3

I am getting some salesforce keyword in response of webservice from other external system. this is response I am getting..

    {
    "id": "ev_HoR7OogNyg9NPidI",
    "occurred_at": 1361996229,
    "object": "event",
    "content": {
        "subscription": {
            "id": "HoR7OogNyg9NP6dG",
            "plan_id": "cloud_drop_for_crm_users",
            "plan_quantity": 1,
            "status": "in_trial",
            "trial_start": 1361996229,
            "trial_end": 1363292229,
            "remaining_billing_cycles": 12,
            "created_at": 1361996229,
            "due_invoices_count": 0,
            "object": "subscription",
            "addons": [{
                "id": "cloud_drop_for_crm_portal_users",
                "quantity": 1,
                "object": "addon"
            }]
        },
        "customer": {
            "id": "HoR7OogNyg9NP6dG",
            "first_name": "Test",
            "last_name": "Test",
            "email": "test@test.com",
            "company": "Test Company",
            "created_at": 1361996229,
            "object": "customer",
            "card_status": "no_card"
        }
    },
    "event_type": "subscription_created",
    "webhook_status": "not_configured"
}

as some sttribue like 'Object' are keyword in salesforce we can not take in to the class as parameter.

@RestResource(urlMapping='/chargebee_webhook/*')
global class chargebee 
{     
   @HttpPost
   global static void doPost()
   {

   }  

}

Can someone help me how I can replace it.

Thanks in advance.

2

I got answer to get the body..

@RestResource(urlMapping='/chargebee_webhook/*')
global class chargebee 
{     
   @HttpPost
   global static void doPost()
   {

        RestRequest req = RestContext.request;
        Blob body = req.requestBody;
        String bodyString = body.toString();    
        system.debug('====='+bodyString);           
   }      
}
| improve this answer | |
  • You may still need to create wrapper ahead and use JSON.deserialise to parse – Mohith Shrivastava Jun 24 '13 at 10:41
  • Yes Mohith, I am doing deserialization for this body by wrapper class – Mahi Jun 24 '13 at 10:49
  • Some third party api posting json response to my salesforce site url When i am using your above code I am getting attempt to dereference null object on below line RestRequest req = RestContext.request; Blob body = req.requestBody; req is comming as null thats y im getting null Cau u pls corect me where i am doing wrong – user4476 Nov 14 '13 at 17:15
  • It may possible you are not getting any response?? you can check on hurl.it .. – Mahi Nov 20 '13 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.