Need help with your APIs? I offer API discovery, governance & evangelism services. Explore services →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

X (Twitter) Direct Messages API

Endpoints related to retrieving, managing Direct Messages

X (Twitter) Direct Messages API is one of 23 APIs that X (Twitter) publishes on the APIs.io network, described by a machine-readable OpenAPI specification.

Tagged areas include Direct Messages. The published artifact set on APIs.io includes an OpenAPI specification, API documentation, a getting-started guide, an API reference, authentication docs, and rate-limit docs.

This API exposes 9 operations across 8 paths, and defines 73 schemas. It is described by OpenAPI 3.0.0, at version 2.161.

Requests are made against a single base URL, https://api.x.com.

9 operations 8 paths 73 schemas 1 DELETE5 GET3 POST

Metadata

The identity and technical contract details declared by the specification.

Specification
OpenAPI 3.0.0
API Version
2.161
Base URL
https://api.x.com/2
Authentication
HTTP Bearer, OAuth 2.0, HTTP Oauth
Terms of Service
Resource Areas
1

Authentication & Security 3

X (Twitter) Direct Messages API declares 3 security schemes for authenticating requests. It accepts HTTP bearer tokens (BearerToken). It supports OAuth 2.0 (OAuth2UserToken) using the authorizationCode flow, exposing 21 scopes. It uses HTTP oauth authentication (UserToken).

Paths & Operations 9

Across 8 paths, the API surfaces 9 operations — 1 DELETE, 5 GET, 3 POST. Each is listed below with its method, path, parameters, and response codes.

Direct Messages 9

Endpoints related to retrieving, managing Direct Messages

POST
/2/dm_conversations
X Create DM Conversation
createDirectMessagesConversation body → 201default
GET
/2/dm_conversations/media/{dm_id}/{media_id}/{resource_id}
X Download DM Media
dmConversationsMediaDownload 3 params → 200default
GET
/2/dm_conversations/with/{participant_id}/dm_events
X Get DM Events for a DM Conversation
getDirectMessagesEventsByParticipantId 9 params → 200default
POST
/2/dm_conversations/with/{participant_id}/messages
X Create DM Message by Participant ID
createDirectMessagesByParticipantId 1 param body → 201default
POST
/2/dm_conversations/{dm_conversation_id}/messages
X Create DM Message by Conversation ID
createDirectMessagesByConversationId 1 param body → 201default
GET
/2/dm_conversations/{id}/dm_events
X Get DM Events for a DM Conversation
getDirectMessagesEventsByConversationId 9 params → 200default
GET
/2/dm_events
X Get DM Events
getDirectMessagesEvents 8 params → 200default
DELETE
/2/dm_events/{event_id}
X Delete DM Event
deleteDirectMessagesEvents 1 param → 200default
GET
/2/dm_events/{event_id}
X Get DM Event by ID
getDirectMessagesEventsById 6 params → 200default

Schemas 73

The contract defines 73 schemas that model the data the API accepts and returns. The most detailed are Tweet (29 properties), User (21 properties), DmEvent (13 properties), UrlFields (9 properties). Each schema is shown below with its type and property counts.

PollId
string
Unique identifier of this poll.
Media
object
4 properties 1 required
DmResourceId
string
The resource identifier of the media file, including file extension.
DeleteDmResponse
object
2 properties
Geo
object
4 properties 3 required
CreateTextMessageRequest
object
2 properties 1 required
PlaceId
string
The identifier for this place.
ContextAnnotationDomainFields
object
Represents the data for the context annotation domain.
3 properties 1 required
PreviousToken
string
The previous token.
MentionFields
object
Represent the portion of text recognized as a User mention, and its start and end position within the text.
2 properties 1 required
HashtagEntity
ReplySettingsWithVerifiedUsers
string
Shows who can reply a Tweet. Fields returned are everyone, mentionedusers, subscribers, verified and following.
Topic
object
The topic of a Space, as selected by its creator.
3 properties 2 required
Place
object
8 properties 2 required
DmAttachments
array
Attachments to a DM Event.
UserWithheld
object
Indicates withholding details for [withheld content](https://help.twitter.com/en/rules-and-policies/tweet-withheld-by-country).
2 properties 1 required
CountryCode
string
A two-letter ISO 3166-1 alpha-2 country code.
PollOption
object
Describes a choice in a Poll object.
3 properties 3 required
DmEventId
string
Unique identifier of a DM Event.
CashtagEntity
PaginationToken32
string
A base32 pagination token.
Get2DmConversationsIdDmEventsResponse
object
4 properties
CreateDmEventResponse
object
2 properties
NoteTweetText
string
The note content of the Tweet.
Point
object
A [GeoJson Point](https://tools.ietf.org/html/rfc7946section-3.1.2) geometry object.
2 properties 2 required
CreateDmConversationRequest
object
3 properties 3 required
PollOptionLabel
string
The text of a poll choice.
PlaceType
string
CommunityId
string
The unique identifier of this Community.
DisplayTextRange
array
Represent a boundary range (start and end zero-based indices) for the portion of text that is displayed for a post. start must be smaller than end. The start i…
User
object
The X User object.
21 properties 3 required
MentionEntity
FullTextEntities
object
5 properties
UrlFields
object
Represent the portion of text recognized as a URL.
9 properties 1 required
Tweet
object
29 properties
Problem
object
An HTTP Problem Details object, as defined in IETF RFC 7807 (https://tools.ietf.org/html/rfc7807).
4 properties 2 required
TweetWithheld
object
Indicates withholding details for [withheld content](https://help.twitter.com/en/rules-and-policies/tweet-withheld-by-country).
3 properties 2 required
Url
string
A validly formatted URL.
Expansions
object
6 properties
TweetText
string
The content of the Tweet.
EntityIndicesInclusiveInclusive
object
Represent a boundary range (start and end index) for a recognized entity (for example a hashtag or a mention). start must be smaller than end. The start index…
2 properties 2 required
ContextAnnotationEntityFields
object
Represents the data for the context annotation entity.
3 properties 1 required
BinaryPayload
string
Raw binary data bytes.
UrlEntity
Represent the portion of text recognized as a URL, and its start and end position within the text.
UrlEntityDm
Represent the portion of text recognized as a URL, and its start and end position within the text.
MediaId
string
The unique identifier of this Media.
HttpStatusCode
integer
HTTP Status Code.
Get2DmEventsResponse
object
4 properties
EntityIndicesInclusiveExclusive
object
Represent a boundary range (start and end index) for a recognized entity (for example a hashtag or a mention). start must be smaller than end. The start index…
2 properties 2 required
DmConversationId
string
Unique identifier of a DM conversation. This can either be a numeric string, or a pair of numeric strings separated by a '-' character in the case of one-on-on…
TweetId
string
Unique identifier of this Tweet. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.
MediaKey
string
The Media Key identifier for this attachment.
Get2DmEventsEventIdResponse
object
3 properties
Error
object
2 properties 2 required
CashtagFields
object
Represent the portion of text recognized as a Cashtag, and its start and end position within the text.
1 property 1 required
Get2DmConversationsWithParticipantIdDmEventsResponse
object
4 properties
ResultCount
integer
The number of results returned in this response.
DmMediaAttachment
object
1 property 1 required
DmParticipants
array
Participants for the DM Conversation.
MediaWidth
integer
The width of the media in pixels.
Position
array
A [GeoJson Position](https://tools.ietf.org/html/rfc7946section-3.1.1) in the format [longitude,latitude].
UrlImage
object
Represent the information for the URL image.
3 properties
UserName
string
The X handle (screen name) of this user.
ContextAnnotation
object
Annotation inferred from the Tweet text.
2 properties 2 required
NextToken
string
The next token.
CreateMessageRequest
DmEvent
object
13 properties 2 required
Poll
object
Represent a Poll attached to a Tweet.
5 properties 2 required
HashtagFields
object
Represent the portion of text recognized as a Hashtag, and its start and end position within the text.
1 property 1 required
MediaHeight
integer
The height of the media in pixels.
CreateAttachmentsMessageRequest
object
2 properties 1 required
TopicId
string
Unique identifier of this Topic.
UserId
string
Unique identifier of this User. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.

Specification

The full machine-readable OpenAPI contract behind this narrative.

Source

twitter-direct-messages-api-openapi.yml Raw ↑

Other APIs X (Twitter) publishes across the network.

X Ads API
X Activity API
X (Twitter) Account Activity API
X (Twitter) Activity API
X (Twitter) Bookmarks API
X (Twitter) Chat API
X (Twitter) Communities API
X (Twitter) Community Notes API
X (Twitter) Compliance API
X (Twitter) Connections API
X (Twitter) General API
X (Twitter) Likes API