Create message

POST /v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages

Individual chat messages

Headers

  • X-Twilio-Webhook-Enabled string

    The X-Twilio-Webhook-Enabled HTTP request header

    Values are true or false.

Path parameters

  • ServiceSid string Required

    The SID of the Service to create the Message resource under.

    Minimum length is 34, maximum length is 34. Format should match the following pattern: ^IS[0-9a-fA-F]{32}$.

  • ChannelSid string Required

    The SID of the Channel the new Message resource belongs to. This value can be the Channel resource's sid or unique_name.

application/x-www-form-urlencoded

Body

  • From string

    The Identity of the new message's author. The default value is system.

  • Attributes string

    A valid JSON string that contains application-specific data.

  • DateCreated string(date-time)

    The date, specified in ISO 8601 format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.

  • DateUpdated string(date-time)

    The date, specified in ISO 8601 format, to assign to the resource as the date it was last updated.

  • LastUpdatedBy string

    The Identity of the User who last updated the Message, if applicable.

  • Body string

    The message to send to the channel. Can be an empty string or null, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.

  • MediaSid string

    The SID of the Media to attach to the new Message.

    Minimum length is 34, maximum length is 34. Format should match the following pattern: ^ME[0-9a-fA-F]{32}$.

Responses

  • 201 application/json

    Created

    Hide headers attributes Show headers attributes
    • Access-Control-Allow-Origin string

      Specify the origin(s) allowed to access the resource

    • Access-Control-Allow-Methods string

      Specify the HTTP methods allowed when accessing the resource

    • Access-Control-Allow-Headers string

      Specify the headers allowed when accessing the resource

    • Access-Control-Allow-Credentials boolean

      Indicates whether the browser should include credentials

    • Access-Control-Expose-Headers string

      Headers exposed to the client

    Hide response attributes Show response attributes object
    • sid string | null

      The unique string that we created to identify the Message resource.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^IM[0-9a-fA-F]{32}$.

    • account_sid string | null

      The SID of the Account that created the Message resource.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^AC[0-9a-fA-F]{32}$.

    • attributes string | null

      The JSON string that stores application-specific data. If attributes have not been set, {} is returned.

    • service_sid string | null

      The SID of the Service the Message resource is associated with.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^IS[0-9a-fA-F]{32}$.

    • to string | null

      The SID of the Channel that the message was sent to.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^CH[0-9a-fA-F]{32}$.

    • channel_sid string | null

      The SID of the Channel the Message resource belongs to.

      Minimum length is 34, maximum length is 34. Format should match the following pattern: ^CH[0-9a-fA-F]{32}$.

    • date_created string(date-time) | null

      The date and time in GMT when the resource was created specified in ISO 8601 format.

    • date_updated string(date-time) | null

      The date and time in GMT when the resource was last updated specified in ISO 8601 format.

    • last_updated_by string | null

      The Identity of the User who last updated the Message, if applicable.

    • was_edited boolean | null

      Whether the message has been edited since it was created.

    • from string | null

      The Identity of the message's author. The default value is system.

    • body string | null

      The content of the message.

    • index integer

      The index of the message within the Channel. Indices may skip numbers, but will always be in order of when the message was received.

      Default value is 0.

    • type string | null

      The Message type. Can be: text or media.

    • media

      An object that describes the Message's media, if the message contains media. The object contains these fields: content_type with the MIME type of the media, filename with the name of the media, sid with the SID of the Media resource, and size with the media object's file size in bytes. If the Message has no media, this value is null.

    • url string(uri) | null

      The absolute URL of the Message resource.

POST /v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages
curl \
 --request POST 'https://chat.twilio.com/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages' \
 --user "username:password" \
 --header "Content-Type: application/x-www-form-urlencoded" \
 --header "X-Twilio-Webhook-Enabled: true" \
 --data 'Body=Hello'
{"Body"=>"Hello"}
{"Body"=>"Hello", "Attributes"=>"{\"test\": \"test\"}", "DateCreated"=>"2015-12-16T22:18:37Z", "DateUpdated"=>"2015-12-16T22:18:38Z", "LastUpdatedBy"=>"username"}
{"MediaSid"=>"MEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
Response examples (201)
{
  "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "body": "Hello",
  "from": "system",
  "type": "text",
  "index": 0,
  "media": null,
  "attributes": null,
  "was_edited": false,
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "2016-03-24T20:37:57Z",
  "date_updated": "2016-03-24T20:37:57Z",
  "last_updated_by": "system"
}
{
  "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "body": "Hello",
  "from": "system",
  "type": "text",
  "index": 0,
  "media": null,
  "attributes": "{\"test\": \"test\"}",
  "was_edited": true,
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "2015-12-16T22:18:37Z",
  "date_updated": "2015-12-16T22:18:38Z",
  "last_updated_by": "username"
}
{
  "to": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/IMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "body": "Hello",
  "from": "system",
  "type": "text",
  "index": 0,
  "media": {
    "sid": "MEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "size": 99999999999999,
    "filename": "hello.pdf",
    "content_type": "application/pdf"
  },
  "attributes": null,
  "was_edited": false,
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "channel_sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "2016-03-24T20:37:57Z",
  "date_updated": "2016-03-24T20:37:57Z",
  "last_updated_by": "system"
}