function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ayush_MangalAyush_Mangal 

Webhook API Makes a HTTP POST request to your URL with POST parameters

The server (through Webhook API) makes a HTTP POST request to my URL ( I can only set the URL on server ) with POST parameters whenever an event occours on the server side. I want to insert a record on custom object, reading POST Parameters.

 

Can someone explain What I need to do..

 

-Do i need to make a Public Web Service in Salesforce

-Does Anyone have a better idea.

SuperfellSuperfell

You can write an apex rest service (.e.g. see http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_rest_code_sample_basic.htm) then expose it for anonymous access by using sites. Alternatively you can write the web listener in java or ruby or similar and have it make API calls to salesforce, you could then deploy this on heroku.

miku1051miku1051

Hi,

 

Did you get any solution.. I am facing the same issue..can you share some code snippet.

 

Help would be much appreciated ..

Ayush_MangalAyush_Mangal

Hi miku1051

 

Yes, I got the solution.

 

You can create a Rest based WEB Service that can handel HTTP POST request inside your org and expose that to the Webhook API Http Post request with parameters along with the request.

 

You can check it youself using http://www.hurl.it/. This is a great site one can use to send POST/GET Request to check their web-services.

miku1051miku1051

Thanks for your reply..

 I will test on this site.

but can you please provide me some code snippet for the same....?

 

 

 

 

 

Ayush_MangalAyush_Mangal

HI,

 

You can post your snippet here and brifly state what you are doing, which Webhook API are you using and all.

miku1051miku1051

Hi Ayush

 

I am getting this response in web service-

 

{
"id": "ev_KyVnQyO8Bd3a128",
"occurred_at": 1364917765,
"object": "event",
"content": {
"subscription": {
"id": "KyVnQyO8Bd3EZ1T",
"plan_id": "no_trial",
"plan_quantity": 1,
"status": "active",
"trial_start": 1341157763,
"trial_end": 1343836163,
"current_term_start": 1362239364,
"current_term_end": 1364917764,
"created_at": 1341157763,
"activated_at": 1362239364,
"due_invoices_count": 1,
"due_since": 1364917764,
"total_dues": 1095,
"object": "subscription",
"addons": [{
"id": "data_usage",
"quantity": 1,
"object": "addon"
}]
},
"transaction": {
"id": "txn_KyVnQyO8Bd3ZM26",
"subscription_id": "KyVnQyO8Bd3EZ1T",
"payment_method": "card",
"gateway": "chargebee",
"type": "payment",
"date": 1364917765,
"amount": 1095,
"id_at_gateway": "cb_KyVnQyO8Bd3ZP27",
"status": "failure",
"error_code": "3001",
"error_text": "Insufficient funds",
"object": "transaction",
"masked_card_number": "519933******4810"
},
"event_type": "payment_failed",
"webhook_status": "not_configured"
}

 

As you can see in this code iam getting some parameters that are keyword in salesforce.

Can you please help me for sending parameters in below class

 

 

@RestResource(urlMapping='/chargebee_webhook/*')
global class chargebee
{
@HttpPost
global static void doPost()
{
system.debug('-----'+s1);

}


}

 

any help will be appreciated..

 

Ayush_MangalAyush_Mangal

Please Try this:

 

@HttpPost
global static string myMethod(){
RestRequest req = RestContext.request;
Map<String,string> paramMap = req.params; System.debug('PRAM '+paramMap);

String a1 = paramMap.get('Event');
String a2 = paramMap.get('From');
String a3 = paramMap.get('To');
String a4 = paramMap.get('Date');
-
- // You can map different parametrs in different Variables.
-

// do something

}

 

If works, please mark this as solution.

miku1051miku1051

When i am using the same i am not getting any value in the map....am i missing something...

 

@RestResource(urlMapping='/chargebee_webhook/*')
global class chargebee
{
@HttpPost
global static void doPost()
{
RestRequest req = RestContext.request;
Map<String,string> paramMap = req.params;
System.debug('PRAM '+req.params);

String a1 = paramMap.get('object');
system.debug('========'+a1);

}

 

 

Ayush_MangalAyush_Mangal

Are you checking your web-service through http://www.hurl..it/. Can you send what is the reply you are getting when you send a Post request

miku1051miku1051

this is my complete request and response

POST /services/apexrest/chargebee_webhook HTTP/1.1
Host: chargebee-developer-edition.ap1.force.com
Accept: */*
Content-Type: application/json
Content-Length: 1105
Expect: 100-continue

{ "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": "crm_portal_users", "quantity": 1, "object": "addon" }] }, "customer": { "id": "HoR7OojkgNyg9NP6dG", "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" }
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Mon, 24 Jun 2013 10:20:07 GMT
Transfer-Encoding: chunked

""

 

miku1051miku1051
RestRequest req = RestContext.request;
Blob body = req.requestBody;
String bodyString = body.toString();

 I have used this its working now...

  thanks for help...

Ayush_MangalAyush_Mangal

As you can see you are receving status code 200 in reply, that means your web-service is running fine and returning the responce correct. Their can be somthing wrong with content-type or in Code.

MooMasterMooMaster
Jumping onto this one a bit late, but had a similar issue to write the APEX code so i've come up with a solution using Salesforce Visual Workflow and a custom plugin. Makes for a dynamic way to POST JSON to any HTTPS endpoint (such as Zapier Webooks).

Link here if this helps anyone else out:
http://moometric.com/integrations/sf/salesforce-visual-workflow-plugin-post-json-callout-external-webservice/
Caleb Kuester 35Caleb Kuester 35
It's worth noting that hurl.it is no longer available. People were probably using it maliciously.
Postman is how you can send get/post data from your computer to some endpoint for testing purposes.