1. Create an X App
Create an X app with an approved developer account from the developer portal. If creating the app on behalf of your company, use a corporate X account.- Enable “Read, Write, and Access direct messages” on the permissions tab of your app page.
- On the “Keys and Access Tokens” tab, note your app’s Consumer Key (API Key), Consumer Token (API Secret), and Bearer Token.
- Generate your app’s Access Token and Access Token Secret. These are needed to subscribe to user accounts.
- Review Obtaining Access Tokens if unfamiliar with X Sign-in and user contexts.
- Note your app’s numeric ID from the “Apps” page in the developer portal. This is required when applying for Account Activity API access.
2. Get Account Activity API access
The Account Activity API is available on the Enterprise and Pay Per Use tiers. Submit an application for access via the developer portal.3. Register a webhook
To receive Account Activity events, you must register a webhook with a publicly accessible HTTPS URL. See the V2 Webhooks API documentation for details on developing a webhook consumer app, registering a webhook, securing it, and handling Challenge-Response Checks (CRC).- Ensure your webhook is configured to handle POST requests with JSON-encoded event payloads.
- Obtain the
webhook_idfrom the webhook registration response, as it is required for managing subscriptions.
4. Validate setup
To validate that your app and webhook are configured correctly:- Subscribe a user account to your webhook (see Adding a Subscription below).
- Favorite a Post posted by one of the X accounts your app is subscribed to.
- You should receive a
favorite_eventspayload via a POST request to your webhook URL.
It may take up to 10 seconds for events to start being delivered after adding a subscription.
Managing subscriptions
Once you have a registered webhook with a validwebhook_id, you can manage user subscriptions to receive their account activities. Use the following endpoints to add, view, or remove subscriptions.
Adding a subscription
Endpoint:POST /2/account_activity/webhooks/:webhook_id/subscriptions/all — API Reference
Subscribes the authenticating user to receive events via the specified webhook.
Authentication: OAuth 1.0a (3-legged OAuth flow required, representing the user being subscribed).
Checking a subscription
Endpoint:GET /2/account_activity/webhooks/:webhook_id/subscriptions/all — API Reference
Checks if the authenticating user is subscribed to the specified webhook.
Authentication: OAuth 1.0a (3-legged OAuth flow required).
Removing a subscription
Endpoint:DELETE /2/account_activity/webhooks/:webhook_id/subscriptions/:user_id/all — API Reference
Deactivates the subscription for a specific user ID, stopping event delivery to the webhook.
Authentication: OAuth2 App Only Bearer Token.
Viewing all subscriptions
Endpoint:GET /2/account_activity/webhooks/:webhook_id/subscriptions/all/list — API Reference
Retrieves a list of all user IDs currently subscribed to the specified webhook.
Authentication: OAuth2 App Only Bearer Token.
Subscription count
Endpoint:GET /2/account_activity/subscriptions/count — API Reference
Returns the total count of active subscriptions and the provisioned limit for the authenticating application.
Authentication: OAuth2 App Only Bearer Token.
DM-only subscriptions are no longer supported. The
subscriptions_count_direct_messages field will always be "0".Replay
AAAv2 provides replay functionality that allows you to retrieve past events for a specified time range and re-deliver them to your webhook. This is useful for recovering missed events due to downtime. Endpoint:POST /2/account_activity/replay/webhooks/:webhook_id/subscriptions/all — API Reference
Authentication: OAuth2 App Only Bearer Token.
Success (200 OK):
Job completed messages
Once your replay job successfully completes, X will deliver the following job completion event. Once you receive this event, the job has finished running and another can be submitted.Important notes
Sample apps
Next steps
Introduction
Activity types, data objects, and payload examples
Webhooks API
Register and manage your webhooks
Migration guide
Migrate from legacy Enterprise to v2
Webhook quickstart
CRC setup, security, and webhook registration