TABLE OF CONTENTS
- What are Webhooks?
- How to Configure Webhooks?
- Structure of a Webhook Message
- Example of a Webhook Message
- How to Process Webhook Notifications
- Rules and Restrictions
What are Webhooks?
Webhooks allow us to track events that occur in Precoro. Unlike API, you do not need to manually send requests to see if there were any changes in Precoro (e.g., whether there have been changes in Suppliers or if Invoices have been paid), because you will be able to receive notifications about these events in real-time.
All you need to do is to enter your endpoint URL and choose the events to track.
In Precoro, you can add up to 5 unique Webhook Endpoints.
How to Configure Webhooks?
In Precoro, you can set up webhooks on this Configuration page.
Follow these simple steps to configure a webhook:
1. Enter the endpoint URL
Creating a webhook endpoint is no different from creating any other page on your website. It is an HTTP or HTTPS endpoint on your server with a URL. This URL is the link to which requests will be sent. Make sure it is correct and accepts POST requests.
Press the New Webhook button and type in the endpoint:
2. Select the events you want to track
There are nine entities you could track for the moment, and two types of events: create and update.
Structure of a Webhook Message
There are three required fields in a webhook message:
1. Id — ID of the entity that was created or modified.
2. Type — the type of entity that was created or modified.
3. Action — the event that happened.
4. Idn — the IDN of entity, if available.
Below you will find a table of values for type and action.
Entity |
Type |
Warehouse Request |
0 |
Purchase Requisition |
1 |
Purchase Order |
2 |
Invoice |
3 |
Request for Proposal |
4 |
Receipt |
5 |
Expense |
6 |
Supplier |
7 |
Stock Transfer |
8 |
Budget |
9 |
Event |
Action |
Create |
0 |
Update |
1 |
Example of a Webhook Message
Let’s take a look at an example below:
{
"id":123456,
"type":2,
"action":0,
"idn":5,
}
This means a new Purchase Order with id 123456 and idn 5 was created.
How to Process Webhook Notifications
After receiving the message, you can get all the necessary data on it by making a request to the API, following our documentation.
The message contains all the required information (according to the example above, to get full information, you would need to make a request — GET https://api.precoro.com/purchaseorders/{idn}).
Rules and Restrictions
1. To avoid spam requests, if the same action with the same entity occurs several times in Precoro within 30 seconds, it will be sent once.
2. Check if the response code is 200 or 201. If there is an error when sending a message, your webhook will be deactivated after five attempts. You can check this on the webhook settings page.