Authentication
DM endpoints require user authentication to access private conversations:| Method | Description |
|---|---|
| OAuth 2.0 Authorization Code with PKCE | Recommended |
| OAuth 1.0a User Context | Legacy support |
Required scopes (OAuth 2.0)
| Scope | Required for |
|---|---|
dm.read | Reading DM events |
tweet.read | Required with dm.read |
users.read | Required with dm.read |
Conversation types
One-to-one
Always has exactly two participants. Conversation ID format:
{smaller_user_id}-{larger_user_id}Group
Two or more participants. Membership can change over time.
Event types
| Event | Description | Key fields |
|---|---|---|
MessageCreate | A message was sent | text, sender_id |
ParticipantsJoin | User joined group | participant_ids, sender_id |
ParticipantsLeave | User left group | participant_ids |
Example events
MessageCreate
MessageCreate
ParticipantsJoin
ParticipantsJoin
ParticipantsLeave
ParticipantsLeave
Fields and expansions
Default fields
| Event type | Default fields |
|---|---|
| MessageCreate | id, event_type, text |
| ParticipantsJoin/Leave | id, event_type, participant_ids |
Available fields
| Field | Description | Events |
|---|---|---|
dm_conversation_id | Conversation ID | All |
created_at | Event timestamp | All |
sender_id | Who sent/invited | MessageCreate, Join |
attachments | Media attachments | MessageCreate |
referenced_tweets | Shared Posts | MessageCreate |
Available expansions
| Expansion | Returns |
|---|---|
sender_id | User object for sender |
participant_ids | User objects for participants |
attachments.media_keys | Media objects |
referenced_tweets.id | Post objects |
Example with expansions
cURL
Pagination
DM events are returned in reverse chronological order (newest first):cURL
Events from up to 30 days ago are available.
ID compatibility with v1.1
Conversation and event IDs are shared between v1.1 and v2 endpoints. This means you can:- Use v2 to retrieve events, then use v1.1 to delete specific messages
- Reference conversation IDs from x.com URLs in API requests