Using webhooks
Last updated
Was this helpful?
Last updated
Was this helpful?
Webhooks are a useful tool for apps that want to execute code after a specific event occurs on a shop, for example, after a customer creates a cart on the storefront, or a merchant creates a new product in the ShopBase admin.
Instead of having your app periodically poll a shop for a specific event, you can register a webhook for the event and create an HTTP endpoint as your webhook receiver. Whenever the event occurs, a webhook is sent to the endpoint. This approach uses less API requests, making it easier to stay within API call limits while building more robust apps. Webhook event data can be stored as JSON or XML.
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
You can configure a webhook using the API or in the ShopBase admin (later).
You can configure a webhook by making a HTTP POST request to the in the REST Admin API.
After you've created a webhook, you're presented with a secret to validate its integrity. You can also it.
Localhost
Any URL ending in the word "internal". For example, thisshop.com/internal
Domains like www.example.com
ShopBase domains such as shopbase.com
and onshopbase.com
Your endpoint must be an HTTPS webhook address with a valid SSL certificate that can correctly process event notifications as described below. You can also implement verification to make sure webhook requests originate from ShopBase.
After you register a webhook URL, ShopBase issues a HTTP POST request to the URL specified every time that event occurs. The request's POST parameters contain XML/JSON data relevant to the event that triggered the request.
ShopBase verifies SSL certificates when delivering payloads to HTTPS webhook addresses. Make sure your server is correctly configured to support HTTPS with a valid SSL certificate.
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. ShopBase does not follow redirects for webhook notifications and considers them to be an error response.
Frequency
ShopBase has implemented a five second timeout period and a retry period for subscriptions. ShopBase waits five seconds for a response to each request to a webhook. If there is no response, or an error is returned, then ShopBase 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.
Webhooks created through the ShopBase admin are verified using the secret displayed in the Webhooks section of the Notifications page.
To verify that the request came from ShopBase, compute the HMAC digest according to the following algorithm and compare it to the value in the X-ShopBase-Hmac-SHA256 header. If they match, then you can be sure that the webhook was sent from ShopBase.
In the event that your app goes offline for an extended period of time, you can recover your webhooks by re-registering your webhooks and importing the missing data.
To re-register the webhooks, consult the app's code that initially registered the webhooks. You can add a check that fetches all the existing webhooks and only registers the ones that you need.
To import the missing data, you can fetch data from the outage period and feed it into your webhook processing code.
When testing webhooks, you can run a local server or use a publicly available service such as . If you decide to run a server locally, then you need to make it publicly available using a service such as or . The following URLS do not work as endpoints for webhooks:
Payloads contain a JSON or XML object with the data for the webhook event. The contents and structure of each payload varies depending on the .
Webhooks created through the API by a ShopBase App are verified by calculating a digital signature. Each webhook request includes a X-ShopBase-Hmac-SHA256 header, which is generated using the app's shared secret along with the data sent in the request.
You can follow or below example uses PHP to verify a webhook request: