Handling webhook deliveries
Learn how to write code to listen for and respond to webhook deliveries.
Introduction
When you create a webhook, you specify a payload URL and subscribe to event types. When an event that your webhook is subscribed to occurs, Shopwaive will send an HTTP request with data about the event to the URL that you specified. If your server is set up to listen for webhook deliveries at that URL, it can take action when it receives one.
This article describes how to write code to let your server listen for and respond to webhook deliveries. You can test your code by using your computer or codespace as a local server.
Step-by-step:
Create a webhook with the following settings. For more information, see "Creating webhooks."
For the payload URL, create an endpoint defined on your server that you'll receive the webhook request
In order to handle webhook deliveries, you need to write code that will:
Initialize your server to listen for requests to your webhook payload URL
Read the HTTP headers and body from the request
Take the desired action in response to the request
You can use any programming language that you can run on your server. The following example prints a message when a webhook delivery is received. However, you can modify the code to take another action, such as making a request to the Shopwaive REST API or sending an email
Create a JavaScript file with the following contents. Modify the code to handle the event types that your webhook is subscribed to, as well as the ping
event that Shopwaive sends when you create a webhook. This example handles the available_balance
and ping
events.
Test the code
Trigger your webhook. For example, if you created an organization webhook that is subscribed to the
available_balance
event, change an available balance of a customer in your organization.Navigate to your webhook payload URL on your server console. You should see an event that corresponds to the event that you triggered. This indicates that Shopwaive successfully sent a webhook delivery to the payload URL that you specified.
Last updated