How to Post Order Information to a Custom Script
IN THIS GUIDE
With Order Desk, you can post order information to a custom script using the Rule Builder. One of the rule actions that can be triggered on an event of your choice is to send order details to a third-party endpoint.
This is helpful if you want to keep track of inventory or perform a custom function when something happens to an order—when a shipment is added or it’s put in the Closed folder, as examples. The action in the rule builder for this is called Post Order JSON:
The order data will be sent in JSON format via POST to your custom URL with the field name order.
The format will be using Order Desk field names, for a reference to these, click here.
The easiest way to test this functionality and see the data returned is to set up a temporary request bin at a service like Mockbin.
Set up your rule and use the testing mechanism to send order data to this URL. You can then inspect it to see exactly what you will be getting from Order Desk.
To send immediately, after you perform the test, go to your View Appointments page and run the pending Send Order To Website action:
If there’s an error, you’ll see the response returned.
While testing, you may want to set your response status code to 400 so you can continue to run the appointment over and over while making sure everything returns correctly.
Order Desk expects your script to return a status code of 200 or 201. If your script returns a status code higher than 201, the post will be considered failed and will be retried up to five times over the course of two hours.
A timeout will occur after 30 seconds and will last 10 seconds before the next try.
After the two hours has elapsed, you will need to manually resubmit your request from the View Appointments page.
Order Desk will pass in an “X-ORDER-DESK-STORE-ID” header with the ID of your store. You can use this to help avoid any spoofing.
For extra security, set an API key and another header will be set called “X-ORDER-DESK-HASH”. This will be an hmac encoded string of the order value being posted.
Here is sample PHP code to ensure that the posted order details came from Order Desk: