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": "[email protected]",
            "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.

1 Answer 1

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);           
   }      
}
4
  • You may still need to create wrapper ahead and use JSON.deserialise to parse Jun 24, 2013 at 10:41
  • Yes Mohith, I am doing deserialization for this body by wrapper class
    – Mahi
    Jun 24, 2013 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, 2013 at 17:15
  • It may possible you are not getting any response?? you can check on hurl.it ..
    – Mahi
    Nov 20, 2013 at 7:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .