twitter

API reference

Messages

Each campaign contains a set of Message objects which are eventually sent as a Twitter DM.

ENDPOINTS

Create Message


To send a DM to a Twitter user, you create a Message object for the desired campaign.

warning

Make sure your campaign is API accessible !

You'll only be able to use this endpoint with campaigns that allow API access. Go to my campaigns .

Parameters


  • to stringRequired
    Twitter User ID or Username
  • is_username booleanOptional
    Must be true if a username is used for the parameter 'to'. Default is false.

Returns


Returns the newly created Message object.

  • id string
    Unique identifier of the message
  • campaign string
    Unique identifier of the campaign
  • to string
    Recipient Twitter User ID
  • text string
    Message text that was sent to the recipient
  • createdAt number
    Unix timestamp of the moment the message was created

Example


cURL

curl https://api.colddm.me/v1/campaigns/some-campaign-id/messages/
-H "Content-type: application/json"
-H "Authorization: Bearer your-secret-api-key"
-d '{
  "to": "jack",
  "is_username": true
}'

Javascript

const campaignId = 'some-campaign-id'
const response = await fetch(
  `https://api.colddm.me/v1/campaigns/${campaignId}/messages/`,
  {
    method: 'POST',
    headers: {
      'Content-type': 'application/json',
      Authorization: 'Bearer your-secret-api-key',
    },
    body: JSON.stringify({
      to: 'jack',
      is_username: true,
    }),
  }
)
if (response.ok) {
  //Success
  const { data: message } = await response.json()
  console.log(`Message id: ${message.id}`)
} else {
  //Handle error
  const { code, message } = await response.json()
  console.log(`Error Code : ${code}
               Error Message : ${message}`)
}
Previous
Campaigns