In our Shopify store we have an order creation webhook that points to a cakephp action URL. The action that webhook points to fetches the order data and then saves this to the database.
The problem that we were facing with this webhook was that it was getting invoked multiple times for each order and eventually was getting deleted after specific number of failures. Going through Shopify documentation on this for the possible reasons it was learned that this could be because webhook was not getting HTTP Status 200 due to any of the following reasons:-
- Webhook call is timing out because Shopify expects a response within 5 seconds of call. And if it doesn’t receive this, call is marked as failure. Subsequently after specific number of failures webhook is removed.
- There is some problem at the app end that is handling the webhook request and webhook is not able to receive a success status.
Further looking into this we came to know that the webhook was firing multiple times because after doing necessary functions the action was not able to return success response. It was because we have used cakephp action for webhook. And as per cakephp behaviour after executing the controller action it tries to find the corresponding view and invoke that. But in our case it was unable to find the view file hence throwing error and returning HTTP Status 500.
To resolve the issue we created the missing view file and thus it was able to run successfully and return HTTP Status 200.
As an alternative approach, after we perform the necessary functionality on webhook call we can use exit statement to defer the next possible execution. In this case if the action is successfully performed it will ignore any further processing that can result in some kind of error.
Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at firstname.lastname@example.org