This guide walks you through sending Direct Messages and creating group conversations.
PrerequisitesBefore you begin, you’ll need:
- A developer account with an approved App
- User Access Token (OAuth 2.0 PKCE with
dm.write and dm.read scopes)
Send a one-to-one message
Get the recipient's user ID
You need the user ID of the person you want to message. You can get this from the User lookup endpoint. Send the message
curl -X POST "https://api.x.com/2/dm_conversations/with/9876543210/messages" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Hello! This is a message from the API."}'
Review the response
{
"data": {
"dm_conversation_id": "1234567890-9876543210",
"dm_event_id": "1582103724607971332"
}
}
Create a group conversation
Define participants
Gather the user IDs of everyone you want in the group (excluding yourself).
Create the group with first message
curl -X POST "https://api.x.com/2/dm_conversations" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"conversation_type": "Group",
"participant_ids": ["944480690", "906948460078698496"],
"message": {"text": "Welcome to our new group!"}
}'
Receive the conversation ID
{
"data": {
"dm_conversation_id": "1582103724607971328",
"dm_event_id": "1582103724607971332"
}
}
Save the dm_conversation_id to add more messages later.
Add a message to an existing conversation
Send a message to a conversation you’re already part of:
curl -X POST "https://api.x.com/2/dm_conversations/1582103724607971328/messages" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Adding another message to the conversation."}'
Send with media attachment
curl -X POST "https://api.x.com/2/dm_conversations/with/9876543210/messages" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "Check out this image!",
"attachments": [{"media_id": "1234567890123456789"}]
}'
Delete a message
Delete a message you sent:
curl -X DELETE "https://api.x.com/2/dm_events/1582103724607971332" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
Response:
{
"data": {
"deleted": true
}
}
You can only delete messages you sent, not messages from other participants.
Required scopes
When using OAuth 2.0 PKCE, your access token must have these scopes:
| Scope | Description |
|---|
dm.write | Send and delete messages |
dm.read | Read conversations (required with dm.write) |
tweet.read | Required for some expansions |
users.read | Required for user expansions |
Next steps