X (Twitter)
Learn how to link an X (Twitter) account, browse inboxes, and send your first DM with Unipile.
Prerequisites
Before we start, you need to:
- Signup to Unipile.
- Create an Application in the dashboard.
- Create an API Key from the dashboard.
If you want to follow the SDK examples:
npm i @unipile/sdkCreate a client with your API key:
import { UnipileMessaging } from "unipile";
const key = "apikey";
const messagingApi = new UnipileMessaging({ key });1. Link an account
In the Dashboard, click Link account and select X (Twitter).
Open X in the same browser, copy the ct0 and auth_token cookies from the browser developer tools, then paste them into the Unipile flow.
When the account is added, keep the generated account ID. It will be used in the next steps.
2. List inboxes
X uses two inboxes in Unipile: trusted and requests.
curl --request GET \
--url https://api.unipile.com/v2/acc_1234567890/inboxes \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json'3. List chats
To retrieve chats from the main X inbox, use List inbox Chats:
curl --request GET \
--url https://api.unipile.com/v2/acc_1234567890/inboxes/trusted/chats \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json'4. Send a first message
To start a new X conversation, use Start a Chat with a handle or numeric user ID.
await messagingApi.startChat({
path: {
account_id: "acc_1234567890",
},
body: {
users_ids: "@jack",
text: "Hello from Unipile!",
},
});curl --request POST \
--url https://api.unipile.com/v2/acc_1234567890/chats/send \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"users_ids": "@jack",
"text": "Hello from Unipile!"
}
'
NoteX still enforces its own DM permissions. Some users cannot be messaged depending on their privacy settings and relation to the linked account.
5. Discover Unipile fundamentals
Updated 14 days ago