Skip to main content
This guide walks you through setting up activity stream subscriptions to receive real-time account activity events.
PrerequisitesBefore you begin, you’ll need:

Create a subscription

Subscribe to a user’s activity events:
curl -X POST "https://api.x.com/2/activity/subscriptions" \
  -H "Authorization: Bearer $BEARER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "2244994945",
    "event_types": ["tweet_create_events", "favorite_events", "follow_events"]
  }'
Response:
{
  "data": {
    "id": "1234567890",
    "user_id": "2244994945",
    "event_types": ["tweet_create_events", "favorite_events", "follow_events"],
    "created_at": "2024-01-15T10:00:00.000Z"
  }
}

Connect to the stream

Open a persistent connection to receive events:
curl "https://api.x.com/2/activity/stream" \
  -H "Authorization: Bearer $BEARER_TOKEN"

Process incoming events

Events stream as JSON objects:
{
  "for_user_id": "2244994945",
  "event_type": "tweet_create_events",
  "created_at": "2024-01-15T10:30:00.000Z",
  "tweet_create_events": [
    {
      "id": "1234567890",
      "text": "Hello from the stream!",
      "author_id": "2244994945"
    }
  ]
}

Available event types

EventDescription
tweet_create_eventsUser posts a new Post
favorite_eventsUser likes a Post
follow_eventsUser follows or is followed
direct_message_eventsUser sends or receives a DM
block_eventsUser blocks or unblocks
mute_eventsUser mutes or unmutes

Manage subscriptions

Get all active subscriptions:
curl "https://api.x.com/2/activity/subscriptions" \
  -H "Authorization: Bearer $BEARER_TOKEN"
Modify event types for a subscription:
curl -X PUT "https://api.x.com/2/activity/subscriptions/1234567890" \
  -H "Authorization: Bearer $BEARER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "event_types": ["tweet_create_events", "favorite_events"]
  }'
Remove a subscription:
curl -X DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
  -H "Authorization: Bearer $BEARER_TOKEN"

Next steps