๐ŸงณManaging Webhooks

Learn how to manage various aspects of Airstack webhooks for your application, from webhook creation, receiving payload, etc.

Create New Webhook

Currently, there is no dedicated API to update an existing webhook. If you would like to make changes to your webhook, you should first delete your webhook and create a new one with a new configuration.

You can simply call the /webhooks API as shown below to create a new webhooks with the receiving endpoint and filter configuration provided to the body request.

To learn more about filter configuration, check this section here.

curl -X 'POST' \
  'https://webhooks.airstack.xyz/api/v1/webhooks' \
  -H 'accept: application/json' \
  -H 'Authorization: <YOUR_AIRSTACK_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
  "endpoint": "YOUR_ENDPOINT",
  "filter_config": {
    "event_type": "profile.updated"
    }
  }
}'

Receiving Payload From Webhooks

To receive data payload from webhooks, you will need to have a POST endpoint where you can receive the payload in the body:

import express, { Request, Response } from "express";
import bodyParser from "body-parser";

const app = express();

app.use(bodyParser.json());

app.post("/webhook", (request: Request, response: Response) => {
  console.log(request.body);

  // Add your business logic here

  response.status(200).json("Success");
});

app.listen(4000, () => console.log("Running on port 4000"));

Then, simply add your business logic before returning status 200 and your endpoint is ready to receive data payload from AIrstack webhooks.

This endpoint have to be accessible through the internet, so if you are developing locally, you should expose your endpoint by creating a secure tunnel with service such as ngrok.

To create a secure tunnel with ngrok, simply run the following command:

ngrok http 4000 # Or replace with the PORT for your endpoint

This will provide you with a tunnel URL that you can provide as an endpoint when creating the webhook.

Once your endpoint is ready for production, simply deploy it to your preferred hosting platform.

Validating Filter Configuration

Filter configuration has 3 available fields:

  • event_type (Required): specify the type of events on Farcaster network to listen to, check out the list here.

  • filter: specify to filter based on the available filter field and the value specified. For profile.created and profile.updated events, check out ProfileFilter. For follow.created and follow.deleted events, check out FollowFilter.

  • payload: Only required if filter field exist. This field accepts a sample payload which needs to have the same field value for fields specified in filter, while others can have arbitrary value. For profile.created and profile.updated events, check out ProfilePayload. For follow.created and follow.deleted events, check out FollowPayload.

In order to ensure that your webhooks are created successfully, it is best practice that you validate your filter configuration as shown below:

In payload, ensure that the value of fields matched to the value provided in filter field. Other fields that is not provided in filter field can just use arbitrary value in payload.

Otherwise, if this is not fulfilled, validation will fail.

curl -X 'POST' \
  'http://webhooks.airstack.xyz/api/v1/filters/test' \
  -H 'accept: application/json' \
  -H 'Authorization: <YOUR_AIRSTACK_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "event_type": "follow.deleted",
    "filter": {
      "followerProfileId": "3761"
    },
    "payload": {
      "followerProfileId": "3761",
      "followingProfileId": "326089"
    }
  }'

Delete Webhook

To delete an existing webhook, simply run the following code and provide the webhook ID associated with the webhook that would like to be deleted:

curl -X 'DELETE' \
  'http://webhooks.airstack.xyz/api/v1/webhooks/<webhook_id>' \
  -H 'accept: application/json' \
  -H 'Authorization: <YOUR_AIRSTACK_API_KEY>'

Developer Support

If you have any questions or need help regarding managing Airstack webhooks, please join our Airstack's Telegram group.

More Resources

Last updated