POST
/
accounts
/
{account_id}
/
messages
JavaScript
import Surge from '@surgeapi/node';

const client = new Surge({
  apiKey: 'My API Key',
});

const message = await client.messages.create('acct_01j9a43avnfqzbjfch6pygv1td', {
  conversation: { contact: { phone_number: '+18015551234' } },
});

console.log(message.id);
{
  "attachments": [
    {
      "id": "att_01j9e0m1m6fc38gsv2vkfqgzz2",
      "type": "image",
      "url": "https://api.surge.app/attachments/att_01jbwyqj7rejzat7pq03r7fgmf"
    }
  ],
  "body": "Thought you could leave without saying goodbye?",
  "conversation": {
    "contact": {
      "first_name": "Dominic",
      "id": "ctc_01j9dy8mdzfn3r0e8x1tbdrdrf",
      "last_name": "Toretto",
      "phone_number": "+18015551234"
    },
    "id": "cnv_01j9e0dgmdfkj86c877ws0znae",
    "phone_number": {
      "id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
      "number": "+18015552345",
      "type": "local"
    }
  },
  "id": "msg_01j9e0m1m6fc38gsv2vkfqgzz2"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

account_id
string
required

The account from which the message should be sent.

Example:

"acct_01j9a43avnfqzbjfch6pygv1td"

Body

application/json

Payload for creating a message. Either an attachment or the body must be given. You can specify the recipient either using the 'conversation' parameter or the 'to'/'from' parameters, but not both. Create a message while including parameters for the conversation in which the message should be sent.

conversation
object
required

Params for selecting or creating a new conversation. Either the id or the Contact must be given.

Example:
{
"contact": {
"first_name": "Dominic",
"last_name": "Toretto",
"phone_number": "+18015551234"
},
"phone_number": "+18015556789"
}
attachments
AttachmentParams · object[]
body
string

The message body.

send_at
string<date-time>

An optional datetime for scheduling message up to a couple of months in the future.

Response

Created message

A Message is a communication sent to a Contact.

attachments
Attachment · object[]
body
string

The message body.

conversation
object

A conversation with a Contact

Example:
{
"contact": {
"first_name": "Dominic",
"id": "ctc_01j9dy8mdzfn3r0e8x1tbdrdrf",
"last_name": "Toretto",
"phone_number": "+18015551234"
},
"id": "cnv_01j9e0dgmdfkj86c877ws0znae",
"phone_number": {
"id": "pn_01jsjwe4d9fx3tpymgtg958d9w",
"number": "+18015552345",
"type": "local"
}
}
id
string

Unique identifier for the object.