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;

    }
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

  • 1
    I think you meant RestContext.response, not RestContext.request. – PartOfTheOhana May 21 at 13:33
  • Thanks for the edit @Ohana – Pranay Jaiswal May 21 at 13:33
  • @PranayJaiswal thanks for the input, but still the webhook is getting hit multiple times. This is not working. – Jitesh Goel May 21 at 13:51
  • Thats diffrent issue isnt it – Pranay Jaiswal May 21 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. – Jitesh Goel May 21 at 14:58

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.