Skip to main content
This guide walks you through retrieving Direct Message events for the authenticated user.
PrerequisitesBefore you begin, you’ll need:
  • A developer account with an approved App
  • User Access Token (OAuth 1.0a or OAuth 2.0 PKCE)

Get all DM events

Retrieve all DM events for the authenticated user:
cURL
curl "https://api.x.com/2/dm_events?\
dm_event.fields=created_at,sender_id,text&\
max_results=100" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"

Response

{
  "data": [
    {
      "id": "1234567890",
      "event_type": "MessageCreate",
      "text": "Hello! How are you?",
      "sender_id": "9876543210",
      "created_at": "2024-01-15T10:30:00.000Z"
    }
  ],
  "meta": {
    "result_count": 1,
    "next_token": "abc123"
  }
}

Get one-to-one conversation

Retrieve DM events from a specific one-to-one conversation:
cURL
curl "https://api.x.com/2/dm_conversations/with/9876543210/dm_events?\
dm_event.fields=created_at,sender_id,text" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"
Replace 9876543210 with the other participant’s user ID.

Get conversation by ID

Retrieve DM events from a specific conversation ID:
cURL
curl "https://api.x.com/2/dm_conversations/1234567890-9876543210/dm_events?\
dm_event.fields=created_at,sender_id,text" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"

Filter by event type

Get only specific event types:
cURL
curl "https://api.x.com/2/dm_events?\
event_types=MessageCreate&\
dm_event.fields=created_at,sender_id,text" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"

Event types

TypeDescription
MessageCreateA message was sent
ParticipantsJoinUser joined conversation
ParticipantsLeaveUser left conversation

Include user data

Expand sender information:
cURL
curl "https://api.x.com/2/dm_events?\
dm_event.fields=created_at,sender_id,text&\
expansions=sender_id&\
user.fields=username,profile_image_url" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"

Response with expansion

{
  "data": [
    {
      "id": "1234567890",
      "event_type": "MessageCreate",
      "text": "Hello!",
      "sender_id": "9876543210"
    }
  ],
  "includes": {
    "users": [
      {
        "id": "9876543210",
        "username": "example_user",
        "profile_image_url": "https://..."
      }
    ]
  }
}

Common parameters

ParameterDescription
max_resultsEvents per page (1-100, default 100)
pagination_tokenToken for next page
dm_event.fieldsEvent fields to return
event_typesFilter by event type
expansionsRelated objects to include

Next steps