Getting started with the filtered stream webhooks API
The v2 filtered stream webhooks API is similar to the v2 filtered stream endpoint in terms of setting up the rules to filter on. The difference lies in the delivery mechanism for the Posts that match your rules.- In case of v2 filtered stream endpoint, you have to establish a persistent connection and listen for Posts matching your rules.
- In case of this filtered stream webhook endpoint, you register your webhook, and X delivers Posts matching your rules to your webhook.
- Setting up your filtered stream rules
- Creating your webhook
- Linking your Filtered Stream instance to your webhook
Setting up your filtered stream rules
Filtered stream rules are made up of one or many operators that are combined using boolean logic and parentheses to help define which Posts will be delivered to your webhooks. The filtered stream webhooks API uses the same set of endpoints as the v2 filtered stream endpoint to create and manage rules. Check out this detailed guide that demonstrates how you can build filters.Creating your webhook
Create a webhook to receive events by registering a publicly accessible HTTPS URL with the X API. Webhooks must handle GET requests for CRC validation and POST requests for event payloads. Follow the Webhooks Introduction documentation for detailed steps on creating and managing webhooks. Note: If you already use webhooks for Account Activity API (AAA), the webhooks set up for that are exactly the same here. In fact, you can use the same webhook endpoint you use for AAA for this API, if you have the bandwidth and can separate the events.Linking your Filtered Stream instance to your webhook
Once your rules are set and the webhook is created, link the webhook to your Filtered Stream instance. This routes matched post events to your webhook URL. Use the endpoint:POST /2/tweets/search/webhooks/:webhook_id
You can include query parameters identical to those used in the streaming endpoint /2/tweets/search/stream
such as expansions, fields, and media options. This customizes the
data included in event payloads.
Example: