Webhook quickstart
This guide covers setting up a basic flow to receive webhook notifications from the API using a server.
The result is a server running on Express.js that listens for incoming ApprovedPayment events and queries the API for more information about each transaction.
Dependencies
Before you begin, make sure you have the following installed on your machine:
Set up the server
Run these commands in your terminal to configure the webhook example server on your local machine:
Expose the server
To receive webhooks from the API, your server must be publicly accessible from the internet. You can expose your local server to the public internet using a tunneling tool. There are many tunneling tools available for testing environments. This section covers exposing your local server using two common tunneling tools:
- localhost.run (Requires SSH installed)
- ngrok (Requires a free account)
Choosing a tool
You can use either localhost.run or ngrok in this guide to expose your server.
localhost.run doesn’t require an account to set up and is faster to get started with. localhost.run requires the command line utility SSH to be installed on your machine. Most Unix-based operating systems (Linux, macOS) have SSH pre-installed.
ngrok requires users to create a free account and install the ngrok software. ngrok has more features for managing tunnels and inspecting traffic. If you want to inspect webhook traffic thoroughly, we recommend using ngrok.
Select the tool you want to use and follow the instructions to publicly expose your local server:
localhost.run
ngrok
Create a free ngrok account
Go to ngrok.com and sign up for a free account. If you already have ngrok set up, skip to step 5.
Download your auth token
After logging in to your ngrok account, go to the dashboard to find your authentication token.
Create a webhook notification
In order to receive webhook notifications, you must first create a notification via the API.
Let’s create a notification that sends a webhook for the ApprovedPayment event.
Call the POST /Notification endpoint to create a webhook notification.
Set the target field to the public URL you created in the previous step, with /webhook appended at the end.
See Create notification for more information about the POST /Notification/ endpoint.
See ApprovedPayment for more information about the ApprovedPayment event.
Test the webhook notification
You’ve set up your server, exposed it to the internet, and created a webhook notification pointing to it. Let’s create a test file that processes a payment in order to trigger the webhook notification.
Write the test code
Use the interactive walkthrough to process a test payment in order to trigger your webhook notification. The interactive walkthrough displays code examples alongside step-by-step explanations.
Next steps
Congrats! You’ve built a basic webhook integration that includes:
- A webhook notification for the
ApprovedPaymentevent - A server that listens for the
ApprovedPaymentevent and fetches details about the payment
Try creating new webhook notifications for different event types and triggering them with API calls. All webhook integrations follow the same structure as the one you built in this guide. See the Webhook notification response reference for more information about the different event types you can create webhook notifications for. Contact your Payabli solutions engineer for assistance with webhook integrations in your projects.
Related resources
See these related resources to help you get the most out of Payabli.
Prerequisites
- Notifications and reports overview - Get automated reports and notifications for key events