Webhooks are a useful tool for apps that want to stay in sync with Orderchamp or execute code after a specific event occurs on an account, for example, when a supplier creates a new product in the Orderchamp admin, or a customer places an order.
To create a webhook, you register both an HTTP endpoint on your app as a webhook receiver and an event that triggers a request to that endpoint. Orderchamp sends you a JSON payload when your selected event occurs, with a copy of the relevant object.
Data about orders, products, or customers can change often, and receiving webhooks is much more efficient than continuously polling for changes to every resource. If your app needs to stay in sync with Orderchamp, then always replace your local copy of any data with the webhook payload.
Common webhook use cases include the following:
Sending notifications to IM clients and pagers
- Collecting data for data-warehousing
- Integrating with accounting software
- Filtering order items and informing shipping companies about orders
- Removing customer data from a database for app uninstalls
Configuring webhooks
#
You can configure a webhook using the API or in the Orderchamp admin .
Configure a webhook using the API
#
You can configure a webhook by making doing a Mutation Query to the GraphQL API. Check out the full Webhooks reference .
Testing Webhooks
#
When testing webhooks, you can run a local server or use a publicly available service such as Beeceptor . If you decide to run a server locally, then you need to make it publicly available using a service such as Pagekite or ngrok . The following URLS do not work as endpoints for webhooks:
- Localhost
- Any URL ending in the word
"internal". For example,example.com/internal - Domains like
www.example.com
Responding to a webhook
#
Your webhook acknowledges that it received data by sending a 200 OK response. Any response outside of the 200 range, including 3XX HTTP redirection codes, indicates that you did not receive the webhook. Orderchamp does not follow redirects for webhook notifications and considers them to be an error response.
Frequency
#
Orderchamp has implemented a five second timeout period and a retry period for subscriptions. Orderchamp waits five seconds for a response to each request to a webhook. If there is no response, or an error is returned, then Orderchamp retries the connection 19 times over the next 48 hours. A webhook is deleted if there are 19 consecutive failures.
To avoid timeouts and errors, consider deferring app processing until after the webhook response has been successfully sent.
Verifying webhooks
#
Webhooks created through the API by an Orderchamp App are verified by calculating a digital signature. Each webhook request includes a X-Orderchamp-Signature header, which is generated using the app's shared secret along with the data sent in the request.
To verify that the request came from Orderchamp, compute the HMAC digest according to the following algorithm and compare it to the value in the X-Orderchamp-Signature header. If they match, then you can be sure that the webhook was sent from Orderchamp.
PHP Code example
#
Verifying in basic laravel controller
Example Webhooks
#
In this example we are going to register a webhook for product events.
Query:
Response:
Using the Orderchamp-client
#
If you happen to use the Orderchamp/orderchamp-laravel package, you could run this query by using the PHP client
Authentication
Rate limits