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
Peter Russell 9Peter Russell 9 

How can I automate reviews.co.uk invitation with HTTP POST - API INSIDE

We would like to automate the collection of reviews from clients a few days after the delivery of our service (legal advice)

Reviews.co.uk have an API that will allow us to send these invitations but I don't know how to setup the HTTP POST and also how to schedule it as a workflow (triggered by +3 days on a date/time field on the opportunity)

Any help you can provide to this salesforce beginner is greatly apreciated!

Here are the reviews.co.uk api info:

To Queue a Company Review Invitation your system needs to send a HTTP Post Request to our API. The details of this request are outlined below. Your developer should integrate this into your system so that this request is sent automatically for every order.
Method: POST
URL: https://api.reviews.co.uk/merchant/invitation
Headers
FieldTypeDescription
storeStringimmigrationa-dvice-service
apikeyString8a749a31930d6cad737e1c115799afd1
Parameters
FieldTypeDescription
nameStringCustomers name
emailStringCustomers email address
order_idStringCustomers order id
date_sendString(optional) Email send date
delayString(optional) Email send delay
branchString(optional) Branch or product name

Example Request

HEADERS:
{
    "Content-Type": "application/json",
    "store": "immigrationa-dvice-service",
    "apikey": "8a749a31930d6cad737e1c115799afd1"
}

BODY:
{
    "name":"Joe Bloggs",
    "email":"test-230@reviews.co.uk",
    "order_id": 1234
}
VaasuVaasu
Hello Peter,

There are several ways to call a webservice from salesforce.
 1. Outbound messaging using time dependent actions in workflow rules - This looks ideal for your scneario 

    https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_om_outboundmessaging_setting_up.htm
    
 2. Batch class to pick records based on matching critirea( opportunity date - today() is greater than or equal to 3 days) and call a webservice, you can schedule this batch class so that it will kick of on specified time.
 
 3. Create a workflow( time dependent) and create field update as action( some flag to fire trigger) which should fire trigger.From trigger you can create a future method and make HTTP call out.
 
Below is the sample httprequest, I have used your example request details.
 Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('Endpoint'); // endpoint of your service
request.setMethod('post');

request.setHeader('Content-Type','application/json');
request.setHeader('store": 'immigrationa-dvice-service');
request.setHeader('apikey": '8a749a31930d6cad737e1c115799afd1');
String body = '{'name':'Joe Bloggs','email':'test-230@reviews.co.uk','order_id': 1234}';
request.setBody(body);
HttpResponse response = http.send(request);
Peter Russell 9Peter Russell 9
Hi Vaasu

Thank's for the prompt response.

The first method you suggested is one that I have tried - the issue is i'm not sure if I am supposed to be doing anything with the code that review.co.uk have provided? 

Thanks,
Pete
VaasuVaasu
Peter.
I think you should go with option 2 or 3.
I said outbound message would be Ideal for your scenario, but to implement that both systems have to make some changes. I guess this is not possible in your case.
Since they already gave you how the request should be, better try other options( trigger/ Batch( this again depends on your business model)).