Skip to content

Receive webhooks via Webhook Endpoint#

Webhook Endpoint technology allows you to receive incoming webhooks directly to your server. This means that the Green API server will make a call to the method published on your server side. The advantage of this technology is the fastest possible receipt of incoming webhooks and high capacity, limited only by the rate of processing webhooks on your server side. The disadvantages include the implementation complexity.

The Green API server makes attempts to deliver webhooks at 1-minute interval. Therefore, set up your server so that it is always available to process incoming webhooks, or use Receive webhooks via HTTP API technology. The delivery of incoming webhooks is guaranteed within 24 hours.

Video instruction#

Server setting#

To receive incoming webhooks using Webhook Endpoint technology, you will need to complete the below steps:

  • to publish the IP address on the internet
  • to implement the logic for processing incoming webhooks to the specified IP address
  • if required for the server, then set the Webhook URL Token

Public IP address#

To receive incoming webhooks, a public IP address (endpoint) is required, which will be accessible from the Internet. Thus, the Green API server will be able to make a call to your server at the specified address and transmit an incoming webhook.

Our public IP-addresses which we sent webhooks from#

You may specify the below IP address from which webhooks from us are received, in your server's security settings:

46.101.109.139
51.250.12.167
51.250.78.88
51.250.84.44
51.250.95.149
158.160.49.84
165.22.93.202
167.172.162.71

Incoming webhooks processing#

After receiving an incoming call to the IP address of your server, you will need to process the received webhook. You can see the example of incoming webhook processing code on NodeJS in file

Instance setup#

Before receiving incoming webhooks, you need to set up your instance. Instance settings can be performed in software using SetSettings method, or online in console interface.

Setting by SetSettings method#

To set up receiving incoming webhooks using Webhook Endpoint technology, you need to specify your IP address or your domain name as the webhookUrl parameter, and, if necessary,webhookUrlToken to access your server. For example:

https://84.211.100.201:3000/green-api/webhook/

It is also required to specify what types of webhooks you need to receive. To enable incoming webhooks by type, as well as to specify webhookUrl andwebhookUrlToken parameters, use SetSettings method.

Example of SetSettings method request body#

{
    "webhookUrl": "https://84.211.100.201:3000/green-api/webhook/",
    "webhookUrlToken": "dscnsdiuafkascndjhsalbcvatsvcbasn23rfregvfdg54tds",
    "outgoingWebhook": "yes",
    "stateWebhook": "yes",
    "incomingWebhook": "yes",
    "deviceWebhook": "no"
}

Setup in console#

You can also set up to receive incoming webhooks online. To do this, go to console and select the required user instance. If the instance is authorized, the settings for receiving incoming webhooks will be displayed, see fig. Specify the webhookUrl parameter, as well as the switches by webhooks types and, if you need authorization on your webhook server, specify Webhook URL Token. If the instance is not authorized and the webhooks settings are not displayed, refer to Before you start section.

Setup in console

Authorization

If the WebhookURLToken parameter is not empty, our server will send a request to your server with an authorization header Authorization.

  1. If the Basic authorization type is used, the header will contain Basic <token>;

    • When using Basic authorization, you need to pass a string like this to the webhookUrlToken field:
      Basic AuthToken
      
  2. If the Bearer authorization type is used, the header will contain Bearer <token>.

    • When using Bearer authorization, you need to pass a string like this to the webhookUrlToken field:
      Bearer AuthToken
      
  3. If the authorization type is not specified, the default header will be Bearer <token>.

    • When the authorization type is not specified, you need to pass a string like this to the webhookUrlToken field:
      Bearer AuthToken
      

Receive incoming webhooks#

After setting up the instance, you can start receiving webhooks. You can see the example of incoming webhook processing code:

Debug incoming webhooks#

You can use any free service on the Internet to debug incoming webhooks, for example, Webhook.Site service. The service issues a unique address (URL), which is required to set as the webhookUrl parameter.

A detailed description of incoming webhooks format is given in Incoming webhooks format section.

Http request example that send by green-api:

curl --request POST 'your-webhook-url-address' \
--header 'Content-Type: application/json; charset=utf-8' \
--data-raw '{"typeWebhook":"statusInstanceChanged","instanceData":{"idInstance":000001,"wid":"7123456789@c.us","typeInstance":"whatsapp"},"timestamp":1654553712,"statusInstance":"online"}'