Skip to content

Set Webhook ​

PUT /session/webhook

Tell Zate where to report incoming messages. Each session has its own webhook: set your server's url and a secret token, and events for new, edited, deleted, and read messages in private chats will be POSTed to that URL with the token in the x-token header.

The event contents, verification, and retry rules are covered in full in Receiving Messages (Webhook).

Endpoint Details ​

  • Base URL: https://api-zate.azickri.com
  • Headers: id, session-id, and Content-Type: application/json

Headers ​

HeaderTypeRequiredDescription
idstringYesid from Create Session.
session-idstringYessessionId from Create Session.

Request Body ​

FieldTypeRequiredDescription
urlstringYesReceiver URL, starting with http:// or https://. Send an empty string to turn the webhook off.
tokenstringYesSecret token sent in the x-token header of every request. Send an empty string to turn the webhook off.

url and token must be both filled, or both empty. Filling in only one is rejected, since a request without a token couldn't be verified by your server.

Example Request ​

bash
curl -X PUT "https://api-zate.azickri.com/session/webhook" \
  -H "id: YOUR_ID" \
  -H "session-id: YOUR_SESSION_ID" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/webhook/zate","token":"super-secret-123"}'
javascript
import axios from 'axios';

const response = await axios.put(
  'https://api-zate.azickri.com/session/webhook',
  {
    url: 'https://example.com/webhook/zate',
    token: 'super-secret-123',
  },
  {
    headers: {
      'id': 'YOUR_ID',
      'session-id': 'YOUR_SESSION_ID',
    },
  },
);

console.log(response.data);
javascript
const response = await fetch('https://api-zate.azickri.com/session/webhook', {
  method: 'PUT',
  headers: {
    'id': 'YOUR_ID',
    'session-id': 'YOUR_SESSION_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com/webhook/zate',
    token: 'super-secret-123',
  }),
});

const data = await response.json();
console.log(data);
json
{
  "url": "",
  "token": ""
}

Response ​

json
{
  "id": "68b3f0a2c1d4e5f6a7b8c9d0"
}
json
// Only one of the two is filled in
{
  "statusCode": 400,
  "message": "url and token must be both filled, or both empty to turn the webhook off"
}

// Invalid URL
{
  "statusCode": 400,
  "message": "url must be an http or https url"
}

// Fields missing entirely
{
  "statusCode": 400,
  "message": "url must be a string\ntoken must be a string"
}
json
{
  "statusCode": 404,
  "message": "session not found"
}
FieldTypeDescription
idstringSession ID.

You can check the active settings in the webhook field of Get Session.

Good to Know ​

  • Turning the webhook on or off starts from that moment. Messages from before it was turned on aren't sent.
  • Changing only the URL or token doesn't start over. Events that haven't been delivered yet continue to the new URL.
  • Local addresses are allowed, like http://127.0.0.1:3000/webhook when the receiver runs on the same server. But over the internet, use https, since the token travels with every request.
  • The webhook is for private chats only. Group and channel messages aren't sent.