Messages

Send a short code message

Changed on

Queues an outbound SMS or MMS using a short-code sender. Delivery progress and final disposition are reported asynchronously through messaging webhooks.

post/messages/short_code

Request

  • Base URL: https://api.telnyx.com/v2
  • URL: https://api.telnyx.com/v2/messages/short_code
  • Auth: HTTP bearer

Headers

Idempotency-Keystring

Optional opaque, unquoted key for safely retrying the same logical request. Keys must contain 1 to 255 letters, numbers, hyphens, or underscores. Generate a unique UUID v4 for each operation and reuse it only when retrying that operation with the same request. Invalid headers—including duplicate, empty, malformed, or overlong values—return 400 with error code 10015. A request already in progress with the same key returns 409; reusing the key with a different request returns 422. Only successful responses are replayed, for up to 24 hours. Do not include sensitive data in the key.

Request body

fromstring required

Phone number, in +E.164 format, used to send the message.

tostring required

Receiving address (+E.164 formatted phone number or short code).

textstring

Message body (i.e., content) as a non-empty string.

Required for SMS

subjectstring

Subject of multimedia message

media_urlsstring[]

A list of media URLs. The total media size must be less than 1 MB.

Required for MMS

webhook_urlstring url

The URL where webhooks related to this message will be sent.

webhook_failover_urlstring url

The failover URL where webhooks related to this message will be sent if sending to the primary URL fails.

use_profile_webhooksboolean

If the profile this number is associated with has webhooks, use them for delivery notifications. If webhooks are also specified on the message itself, they will be attempted first, then those on the profile.

type'SMS' | 'MMS'

The protocol for sending the message, either SMS or MMS.

auto_detectboolean

Automatically detect if an SMS message is unusually long and exceeds a recommended limit of message parts.

encoding'auto' | 'gsm7' | 'ucs2'

Encoding to use for the message. auto (default) uses smart encoding to automatically select the most efficient encoding. gsm7 forces GSM-7 encoding (returns 400 if message contains characters that cannot be encoded). ucs2 forces UCS-2 encoding and disables smart encoding. When set, this overrides the messaging profile's smart_encoding setting.

Example request

{
  "from": "+18445550001",
  "to": "+18445550001",
  "text": "Hello, World!",
  "subject": "From Telnyx!",
  "media_urls": [
    "http://example.com"
  ],
  "webhook_url": "http://example.com/webhooks",
  "webhook_failover_url": "https://backup.example.com/hooks",
  "use_profile_webhooks": true,
  "type": "MMS"
}

Response

Successful response with details about a message.

Example response

{
  "data": {
    "record_type": "message",
    "direction": "outbound",
    "id": "40385f64-5717-4562-b3fc-2c963f66afa6",
    "type": "MMS",
    "messaging_profile_id": "4000eba1-a0c0-4563-9925-b25e842a7cb6",
    "organization_id": "b448f9cc-a842-4784-98e9-03c1a5872950",
    "from": {
      "phone_number": "+18445550001",
      "carrier": "TELNYX LLC",
      "line_type": "VoIP"
    },
    "to": [
      {
        "phone_number": "+18665550001",
        "status": "queued",
        "carrier": "T-MOBILE USA, INC.",
        "line_type": "Wireless"
      }
    ],
    "cc": [],
    "text": "Hello, World!",
    "num_chars": 13,
    "subject": "From Telnyx!",
    "media": [
      {
        "url": "https://pbs.twimg.com/profile_images/1142168442042118144/AW3F4fFD_400x400.png",
        "content_type": null,
        "sha256": null,
        "size": null
      }
    ],
    "webhook_url": "https://www.example.com/hooks",
    "webhook_failover_url": "https://backup.example.com/hooks",
    "encoding": "GSM-7",
    "parts": 1,
    "tags": [
      "Greetings"
    ],
    "cost": {
      "amount": "0.0051",
      "currency": "USD"
    },
    "cost_breakdown": {
      "carrier_fee": {
        "amount": "0.00305",
        "currency": "USD"
      },
      "rate": {
        "amount": "0.00205",
        "currency": "USD"
      }
    },
    "tcr_campaign_id": "TCPA3X7",
    "tcr_campaign_billable": true,
    "tcr_campaign_registered": "REGISTERED",
    "received_at": "2019-01-23T18:10:02.574Z",
    "sent_at": null,
    "completed_at": null,
    "valid_until": null,
    "errors": [],
    "wait_seconds": 0.5
  }
}

Changes

    • info

      added the new optional header request parameter Idempotency-Key

    • info

      added the non-success response with the status

    • info

      added the non-success response with the status

    • info

      added the non-success response with the status

    • warning

      added the new WHATSAPP enum value to the / response property for the response status

    • info

      added the optional property / to the response with the status

    • info

      added the optional property / to the response with the status