Before creating subscriptions, you’ll need to know the user ID of the account you want to filter on. In this example, we will use the XDevelopers handle. You can look up user IDs in a few of ways including:Look up a user’s ID by username:
Next step is to create a subscription. In this example, we will subscribe to XDevelopers’s bio updates. In order to do so, we will pass the user_id and event_type in the JSON body. In this case, the event_type is profile.update.bio.We’ll pass X Developer’s user ID: 2244994945, and an optional tag:
Once we have created the subscription, we can receive the events via webhooks or a persistent HTTP stream. In this example, we will open the persistent HTTP stream:
curl -H "Authorization: Bearer YOUR_BEARER_TOKEN" \ -X POST \ https://api.x.com/2/activity/subscriptions \ -d '{ "event_type": "profile.update.bio", "filter": { "user_id": "123456789" }, "tag": "my bio updates", "webhook_id": "1976325569252868099" }'
The tag field is optional. This can be used to help identify events on delivery.
The webhook_id field is also optional. See our webhook docs for help setting up a webhook. If a webhook_id is specified, the event will be delivered to the provided webhook, in addition to the stream if it is open.
The PUT endpoint allows you to update a subscription’s delivery method or tag.Updating the filter or event_type requires deleting the existing subscription and adding a new one.
curl -H "Authorization: Bearer YOUR_BEARER_TOKEN" \ -X PUT \ https://api.x.com/2/activity/subscriptions/1976325569252868096 \ -d '{ "tag": "my new tag", "webhook_id": "192846273860294839" }'