This article walks step-by-step through sending an SMS message using the Volt GraphQL API.

<aside> ℹ️

We strongly suggest using a GraphQL client library in the language of your choice when interacting with the Volt GraphQL API. Using a GraphQL client library will make it easier to take advantage of static typing, API schema introspection, and other features that let you quickly and reliably build into the Volt GraphQL API. For more information, check out *What is a GraphQL client and why would I use one?.*

</aside>

📘 Instructions

First, ensure that you have access to the data necessary for utilizing the Volt GraphQL API:

  1. Have your Volt GraphQL API access token readily available. If you are unsure of where to locate your API token, contact [[email protected]](mailto:[email protected]?subject=Need%20API%20Access%20Token&body=I%20am%20attempting%20to%20connect%20to%20the%20Volt%20GraphQL%20API%2C%20and%20I%20need%20the%20access%20token%20for%20my%20organization%20in%20order%20to%20utilize%20the%20API.%20Please%20send%20me%20a%20link%20to%20access%20my%20GraphQL%20API%20token.%20My%20organization%20is%3A%20%3CYour%20Organization%20Name%3E).
  2. To send an SMS message using the GraphQL API, you will need to specify the sending and receiving phone numbers, the message content, and a publicly accessible URL for media (if sending MMS).

<aside> ⚠️

A phone number can only be sent from if it belongs to your organization. If you are unsure of which phone numbers belong to your organization, log in to Volt or contact [[email protected]](mailto:[email protected]?subject=Need%20Sending%20Phone%20Numbers&body=I%20am%20attempting%20to%20connect%20to%20the%20Volt%20GraphQL%20API%2C%20and%20I%20need%20a%20list%20of%20sending%20phone%20numbers%20that%20belong%20to%20my%20organization%20in%20order%20to%20utilize%20the%20API.%20Please%20send%20me%20a%20list%20of%20the%20phone%20numbers%20that%20can%20be%20used%20to%20send%20SMS%20through%20Volt.%20My%20organization%20is%3A%20%3CYour%20Organization%20Name%3E).

To ensure that phone numbers can be processed correctly by Volt, ensure that any phone numbers are formatted according to the E.164 standard. For example: (555) 555-0123 should be formatted as +15555550123.

</aside>

Next, use the necessary data to send a message using the GraphQL API. For example, if you want to send an SMS message with the sending number +15555550123 and the receiving number +15555550145, construct a GraphQL API request:

  1. Set the Authorization header to the value Bearer <token>, replacing <token> with the API access token belonging to your organization.
  2. Construct a GraphQL query using the createMessage mutation:
mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {
    createMessage (to: $to, from: $from, body: $body, media: $media) {
        id
        legacyId
        toNumber
        fromNumber
        status
        statusDescription
        media
        body
        sentAt
        confirmedAt
    }
}
  1. Construct a JSON object containing the GraphQL variables for the query created in the previous step:
{
  "to": "+15555550145",
  "from": "+15555550123",
  "body": "Your One Time Code is 654312\\n\\nReply STOP to opt-out.",
  "media": []
}