Webhooks notify your application when events occur in the Sohar platform. They use HTTPS and deliver JSON payloads so you can respond to updates in real time.

Steps to receive webhooks

You can start receiving events by following these steps:

  1. Create a local endpoint to receive requests.
  2. Register your development webhook endpoint.
  3. Test that your webhook endpoint is working properly.
  4. Deploy your webhook endpoint to production.
  5. Register your production webhook endpoint.

1. Create a local endpoint to receive requests

In your application, create a route that accepts POST requests. Below is an example using Node.js with Express:

const express = require('express');
const app = express();

app.use(express.json());

app.post('/webhooks', (req, res) => {
  const event = req.body;
  console.log(event);
  res.status(200).end();
});

app.listen(3000, () => console.log('Listening on port 3000'));

Whenever you receive an event, respond with HTTP 200 OK to acknowledge receipt.

You can create a tunnel to your localhost server using a tool like ngrok. For example: https://fa8b-9-27-207-123.ngrok-free.app/webhooks

2. Register your development webhook endpoint

Use the Create Webhook API to register your endpoint and generate an endpointId. Use the Create Event API to subscribe your endpoint to an event. The sandbox.verification.updated event is great for testing purposes.

You should use production credentials to call webhook management APIs. All webhook endpoints can subscribe to production and sandbox events.

3. Test that your webhook endpoint is working properly

Send a few test requests to confirm that your endpoint receives events. If your endpoint is subscribed to the sandbox.verification.updated event, you can call the Create Verification API with sandbox credentials and sandbox values for testing purposes.

4. Deploy your webhook endpoint

After testing, deploy your endpoint to your production environment.

5. Register your production webhook endpoint

Use the Create Webhook API to register your production URL so that live events can be delivered.