This project is read-only.

EditSubscriptionProduct and MigrateSubscriptionProduct giving "422 Unprocessable Entity"

Jun 28, 2011 at 6:05 PM

Hi, i'm getting "422 Unprocessable Entity" when using the mentioned methods. Any idea whats wrong?
My code is something like this:
                System.Collections.Generic.IDictionary<int, ISubscription> temp = getSubscription(chargifyId);
                ISubscription oldSub = temp.ElementAt(0).Value;

                IProduct newPlafond = getProductDetails(handler_for_the_new_product);

                subscription = chargify.EditSubscriptionProduct(oldSub, newPlafond);


All variables are correctly filled.

I was going to create a new issue, but decided to create a discussion first so i can rule out any programming mistakes.

Also, i'm using the compiled dll from 19 May.

Thanks for any help.

Jun 29, 2011 at 2:40 PM

Try this:

try {
// your code here
} catch (ChargifyException cex) {
    // Examine cex.ErrorMessages for possible messages from the server about the issue.

I ran the same code on my subdomain, and didn't have any issues - so I wonder if the product handle is wrong? Either way, you should be able to get an idea once you check out the error.


-- Kori

Jun 30, 2011 at 5:34 PM

Thank you for answering.

There was nothing wrong with the code, there was actually a problem with the product configuration in the Chargify website.

Everything works fine now :)

Thanks again for the help.

Aug 30, 2011 at 11:58 PM

Hi Kori,

(This may be better suited on Chargify forum, tell me if so)

I purposely set an invalid credit card number to ensure that MigrateSubscriptionProduct fails as expected, and error is returned as expected:

ChargifyNET.ChargifyException was caught
  Message=The server returned 'Unprocessable Entity' with the status code 422 (422) when posting '<?xml version="1.0" encoding="UTF-8"?><migration><product_handle>mockgenpremium</product_handle><include_initial_charge>1</include_initial_charge></migration>'.
  LastDataPosted=<?xml version="1.0" encoding="UTF-8"?><migration><product_handle>mockgenpremium</product_handle><include_initial_charge>1</include_initial_charge></migration>
  StatusDescription=Unprocessable Entity
       at ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData)
       at ChargifyNET.ChargifyConnect.MigrateSubscriptionProduct(Int32 SubscriptionID, String ProductHandle, Boolean IncludeTrial, Boolean IncludeInitialCharge)
       at ChargifyNET.ChargifyConnect.MigrateSubscriptionProduct(Int32 SubscriptionID, IProduct Product, Boolean IncludeTrial, Boolean IncludeInitialCharge)
       at MockGen.ClientLibrary.Managers.SubscriptionManagerChargify.UpgradeSubscription(String userID, String subscriptionPackageID) in C:\Development\Projects\Looksie\MockGen\MockGen2\MockGen.ClientLibrary\Managers\SubscriptionManagerChargify.cs:line 177
  InnerException: System.Net.WebException
       Message=The remote server returned an error: (422) Unprocessable Entity.
            at System.Net.HttpWebRequest.GetResponse()
            at ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData)


The single ChargifyError in ErrorMessages is:

>? ex.ErrorMessages[0]
    Message: "Unable to process new product subscription"

Perhaps Chargify could return a more useful error message to indicate the error was related to payment processing? 

I can only suggest to the user on error that they update their credit card details on the Self Service page as a *possible* fix.


Oct 11, 2011 at 9:03 PM


Yea - that sort of question is better at - though, it's likely to be me who would be answering the ticket :P

The issue is, that there's a bit of a disconnect when it comes to the migration action and the reporting of errors. 98% of the time, the issue is that the card is being declined for the charge being placed on it during the migration. If you want specific details, submit a ticket and I can get them for you. I've been trying to get the guys to put some attention into the error reporting, which I hope they'll be able to get to soon. One of their biggest issues currently, is that they just need more developers .. so it's always a bandwidth issue trying to balance between new features and bug fixing (like the issue you posted).

Chargify.NET only works as a wrapper to the API, but I'm at the mercy of what it returns to my library. I'm working on learning RoR, but it's quite a switch for a lifetime .NET dev like myself - so that I can help them by fixing these little annoyances while they keep working on the latest and greatest.

-- Kori