V2 Account Activity API
Account Activity API v2 is now available on Pro!
Overview
The Account Activity API (AAA) provides a way to receive real-time events related to X user accounts via webhooks. By subscribing specific user accounts to a pre-configured webhook, your application can be notified of various activities such as Posts, Direct Messages, Likes, Follows, Blocks, and more, from one or more of your owned or subscribed accounts through a single connection.This API is commonly used to build applications that need to react instantly to user actions or maintain an up-to-date state based on user activity. You will receive all related activities below for each user subscription on your webhook registration:
Activity Types
- Posts (by user)
- Post deletes (by user)
- @mentions (of user)
- Replies (to or from user)
- Reposts (by user or of user)
- Quote Posts (by user or of user)
- Reposts of Quoted Posts (by user or of user)
- Likes (by user or of user)
- Follows (by user or of user)
- Unfollows (by user or of user)
- Blocks (by user or of user)
- Unblocks (by user or of user)
- Mutes (by user or of user)
- Unmutes (by user or of user)
- Direct Messages sent (by user)
- Direct Messages received (by user)
- Typing indicators (to user)
- Read receipts (to user)
- Subscription revokes (by user)
Feature Summary
This document focuses on managing user subscriptions associated with your webhooks using v2 Account Activity API endpoints.
Manage Subscriptions
The Account Activity API provides webhook-based JSON messages any time there are events associated with X accounts subscribed to your service. X delivers those activities to your registered webhook. In the following steps, you will learn how to set up and manage subscriptions for user accounts.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 only on the Enterprise tier. Submit an application for Enterprise 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_id from 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_events payload via a POST request to your webhook URL.
- Note: It may take up to 10 seconds for events to start being delivered after adding a subscription.
Important Notes
- 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.
- Example Code: See the Account Activity API Setup for a web app that displays webhook events.
Managing Subscribed Users (v2 API)
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.Adding a Subscription
Endpoint: POST /2/account_activity/webhooks/:webhook_id/subscriptions/allDescription: Subscribes the authenticating user to receive events via the specified webhook.
Authentication: OAuthUser (3-legged OAuth flow required, representing the user being subscribed).
- Consumer Key: e.g., xvz1evFS…
- Access Token: e.g., 370773112-GmHxMAgYyLbN…
Request:
bash
- Success (200 OK):
- json
- Failure (400 Bad Request):
Checking a Subscription
Endpoint: GET /2/account_activity/webhooks/:webhook_id/subscriptions/allDescription: Checks if the authenticating user is subscribed to the specified webhook.
Authentication: OAuthUser (3-legged OAuth flow required).
Path Parameters:
Request:
bash
- Success (200 OK):
- json
- Failure (400 Bad Request):
Removing Subscriptions
Endpoint: DELETE /2/account_activity/webhooks/:webhook_id/subscriptions/:user_id/allDescription: Deactivates the subscription for a specific user ID, stopping event delivery to the webhook.
Authentication: OAuth2 App Only Bearer Token.
- Bearer Token: e.g., AAAAAAAAAAAA0%2EUifi76ZC9Ub0wn…
Request:
bash
- Success (200 OK):
- json
- Failure (400 Bad Request):
Viewing all Subscriptions
Endpoint: GET /2/account_activity/webhooks/:webhook_id/subscriptions/all/listDescription: Retrieves a list of all user IDs currently subscribed to the specified webhook.
Authentication: OAuth2 App Only Bearer Token.
Path Parameters:
Request:
bash
- Success (200 OK):
- json
- Failure (400 Bad Request):
Subscriptions Count
Endpoint: GET /2/account_activity/subscriptions/countDescription: Returns the total count of active subscriptions and the provisioned limit for the authenticating application.
Authentication: OAuth2 App Only Bearer Token.
Request:
bash
- Success (200 OK):
- json
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 Description: Initiates a replay job Authentication: OAuth2 App Only Bearer Token Path Parameters:
Query Parameters:
Responses:
Success:
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.Account Activity Data Object Structure
Available Activities
Payload Examples
Below are example payloads for each Account Activity event.tweet_create_events (Posts, Retweets, Replies, QuoteTweets)
tweet_create_events (@mentions)
favorite_events
follow_events
unfollow_events
block_events
unblock_events
mute_events
unmute_events
user_event
direct_message_events
direct_message_indicate_typing_events
direct_message_mark_read_events
tweet_delete_events
Support for Longform Posts
The V2 Account Activity API now supports longform posts, which are posts exceeding 280 characters. When a longform post is included in a tweet_create_events payload, the text field contains the first 140 characters (or fewer), and the truncated field is set to true. The full post content is delivered in the extended_tweet object, which includes:- full_text: The complete text of the post, including all characters beyond the 280-character limit.
- entities: Any entities (e.g., hashtags, URLs, user mentions, symbols) appearing in the full text, including those after the 280th character.
- display_text_range: The range of characters to display, accounting for the full text.
Account Activity API Migrating from Legacy Enterprise to v2
See our Migration Guide!Frequently Asked Questions
What are the advantages of using the Account Activity API? The Account Activity API uses webhooks, delivering data in real-time without requiring an open connection (unlike streaming APIs) or frequent polling (unlike REST APIs). Benefits include:- Speed: Delivers data at the speed of X.
- Simplicity: Provides all account events through a single webhook connection, including Posts, @mentions, Replies, Reposts, Quote Tweets, Likes, DMs, Follows, Blocks, and Mutes.
- Scale: Supports all activities for managed accounts without rate limits or event caps (Enterprise tier).
Account Activity API Reference Index
For webhook management endpoints (register, view, validate, delete), see the V2 Webhooks API documentation