0

I have a Salesforce site which is used as a rest resource for a Shopify Webhook for new Order Creation. When a new order is created in Shopify it hits the Url provided by us and expects a "200 OK" in response. How can I return the required response to the webhook. Here is the document which depicts the webhook requirement:- https://help.shopify.com/en/api/getting-started/webhooks#configuring-webhooks (Please review the "Responding to a webhook" section). Below mentioned is the code Snippet :-

@RestResource(urlMapping='/ShopSf/Odr')
global class ShopifyRestClass {
    @HttpPost

    global static String setName(){

      System.debug('>>>>>>in rest resource');

      RestResponse response = RestContext.response;
      response.statusCode = 200;
      System.debug('>>>>>>>>>>>>>response'+response); 
      ShopifyDataSync.ShopifySyncMethod(RestContext.request,'Order'); 

        return null;

    }
1

1 Answer 1

2

You have to set statuscode and response text blob in RestContext.response

 RestResource(urlMapping='/ShopSf/Odr')
    global class ShopifyRestClass {
        @HttpPost

        global static void setName(){

          System.debug('>>>>>>in rest resource');
          System.debug('>>>>>>>>>>>>>response'+response); 
          ShopifyDataSync.ShopifySyncMethod(RestContext.request,'Order'); 
          RestContext.response.statusCode = 200;
          RestContext.response.responseBody = Blob.valueOf('OK');    

        }

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_restresponse.htm#apex_methods_system_restresponse

5
  • 1
    I think you meant RestContext.response, not RestContext.request. Commented May 21, 2019 at 13:33
  • Thanks for the edit @Ohana Commented May 21, 2019 at 13:33
  • @PranayJaiswal thanks for the input, but still the webhook is getting hit multiple times. This is not working. Commented May 21, 2019 at 13:51
  • Thats diffrent issue isnt it Commented May 21, 2019 at 13:53
  • No, because the webhook hits again the rest resource url if it does not receive 200 OK response back (retry mechanism) as mentioned in the question description document. Commented May 21, 2019 at 14:58

You must log in to answer this question.

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