Set up Account Activity API subscriptions and start receiving real-time events
This guide walks you through setting up the Account Activity API, managing user subscriptions, validating your webhook, and using the replay feature to recover missed events.
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.
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_id from the webhook registration response, as it is required for managing subscriptions.
Once you have a registered webhook with a valid webhook_id, you can manage user subscriptions to receive their account activities. Use the following endpoints to add, view, or remove subscriptions.
Endpoint:POST /2/account_activity/webhooks/:webhook_id/subscriptions/all — API ReferenceSubscribes the authenticating user to receive events via the specified webhook.Authentication: OAuth 1.0a (3-legged OAuth flow required, representing the user being subscribed).
Path Parameter
Description
webhook_id
The ID of the webhook to associate the subscription with.
Endpoint:GET /2/account_activity/webhooks/:webhook_id/subscriptions/all — API ReferenceChecks if the authenticating user is subscribed to the specified webhook.Authentication: OAuth 1.0a (3-legged OAuth flow required).
Endpoint:DELETE /2/account_activity/webhooks/:webhook_id/subscriptions/:user_id/all — API ReferenceDeactivates the subscription for a specific user ID, stopping event delivery to the webhook.Authentication: OAuth2 App Only Bearer Token.
Path Parameter
Description
webhook_id
The ID of the webhook containing the subscription.
Endpoint:GET /2/account_activity/webhooks/:webhook_id/subscriptions/all/list — API ReferenceRetrieves a list of all user IDs currently subscribed to the specified webhook.Authentication: OAuth2 App Only Bearer Token.
Endpoint:GET /2/account_activity/subscriptions/count — API ReferenceReturns the total count of active subscriptions and the provisioned limit for the authenticating application.Authentication: OAuth2 App Only Bearer Token.
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 ReferenceAuthentication: OAuth2 App Only Bearer Token.
Path Parameter
Description
webhook_id
The ID of the webhook to begin replay.
Query Parameter
Description
from_date
The oldest (starting) UTC timestamp from which the events will be provided. Must be in yyyymmddhhmm format. Timestamp is in minute granularity and is inclusive (i.e. 12:00 includes the 00 minute). Valid times must be within the last 24 hours, UTC time, and no more recent than 31 minutes before the current point in time. It’s recommended that from_date and to_date should be within ~2 hours.
to_date
The latest (ending) UTC timestamp to which the event will be provided. Must be in yyyymmddhhmm format. Timestamp is in minute granularity and is exclusive (i.e. 12:30 does not include the 30th minute of the hour). Valid times must be within the last 24 hours, UTC time, and no more than 10 minutes before the current point in time.
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.
In the event your job does not complete successfully, X will return the following message encouraging you to retry your Replay Job. Once you receive this event, the job has finished running and another can be submitted.
Copy
Ask AI
{ "replay_job_status": { "webhook_id": "<WEBHOOK_ID>", "job_state": "Incomplete", "job_state_description": "Job failed to deliver all events, please retry your replay job", "job_id": "<JOB_ID>" }}
Authentication: When subscribing users, use the consumer key, consumer secret, access token, and access token secret for the user’s account.
Direct Messages: All incoming and outgoing Direct Messages (sent via POST /2/dm_conversations/with/:participant_id/messages) are delivered via webhooks to keep your app aware of all DM activity.
Event Duplication:
If two subscribed users are in the same DM conversation, your webhook receives duplicate events (one per user). Use the for_user_id field to distinguish them.
If multiple apps share the same webhook URL and user, events are sent multiple times (once per app).
Your app should deduplicate events using the event ID to handle occasional duplicates.