2

A text messaging system we're integrating with includes a feature that sends an HTTP request to a URL with message receipt data but I'm not sure how to prepare our Salesforce to deal with it in the way we want.

I have only ever used the SOAP API, but I understand the basic principles behind RESTful APIs (which I assume is what I need to use). Basically we have some Apex classes that call a SOAP web service externally to send a message, and at the same time a record with some data (message body, headers, etc.) is inserted to salesforce. One of the parameters for the web service call is a callback URL to send message receipt data to.

What I would like is the receipt data stored in the URL parameters to update a record on salesforce. How do I do this?

  • Is the callback request data correctly formatted for REST? If so, you could create a public site with an @HttpGet REST web service. You might have an issue if the Content-Type header in the request isn't Accept: application/json. See Quick Tip – Public RESTful Web Services on Force.com Sites – Daniel Ballinger Jun 11 '14 at 20:00
  • The web service in question is Dynmark's SMS cloud platform. If one is specified, the platform sends and HTTP/HTTPS request to a specified URL and appends all the receipt data as part of the URL's GET parameters. Is there a way for Salesforce to accept this request and update the records? – Adam Jun 12 '14 at 9:01
1

Yes there is! here are the steps to do that :

1) Create a class with the following code :

@RestResource(urlMapping='/sms')
global class InboundSmsController {
    @HttpPost
    global static void restmethod() {

     system.debug('==================BEGIN REST CALL.');

     RestRequest req = RestContext.request;
     RestResponse res = RestContext.response;
     res.addHeader('Content-Type', 'application/json'); 
     String jsonResponse = '';
     String yougetparameter = req.params.get('addyourgetparameter');
     res.statusCode = 200;
     jsonResponse = '{"response": {"status": "Success", "message":"Received."}}';
     res.responseBody = blob.valueOf(jsonResponse);

     /* Add your logic !!!
     */

     return;

     }
}

2) Now once the class is saved Create a Salesforce Site.

3) You are almost done its just the matter of permissions now, continuing from step2
once the site is saved click on "Public Access Settings" and assign the above class
to the site and you are done.

4) Now you need to give URL to the SMS system that URL will be calling this service and
that will be something like this : https://yoursalesforcesite.com/services/apexrest/sms

Let me know if it works.
Cheers !!!

  • It doesn't seem to want to work :/ when I use cURL to check it out it just gives me a load of HTML and nothing changes. – Adam Jun 16 '14 at 13:31
  • Hold that... I just had the site configured wrong :P I think it's working! – Adam Jun 16 '14 at 13:51
  • Great!! Don't forget to mark it as an answer if it works for you ;) – Mohd Nadeem Shaikh Jun 16 '14 at 15:25

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.