...
\uD83D\uDCD8 Instructions
First, ensure that you have access to the data necessary for utilizing the Volt GraphQL API:
Have your Volt GraphQL API access token readily available. If you are unsure of where to locate your API token, contact api@textvolt.com.
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).
Note |
---|
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 api@textvolt.com. 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 . |
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:
Set the Authorization
header to the value Bearer <token>
, replacing <token>
with the API access token belonging to your organization.
Construct a GraphQL query using the createMessage
mutation:
Code Block |
---|
|
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
}
} |
Construct a JSON object containing the GraphQL variables for the query created in the previous step:
Code Block |
---|
|
{
"to": "+15555550145",
"from": "+15555550123",
"body": "Your One Time Code is 654312\n\nReply STOP to opt-out.",
"media": []
} |
Note: to send an MMS message, set the media
variable to a list of publicly-accessible media URLs corresponding to the media you wish to send. Supported file types are: JPEG, PNG, GIF, VCF (vCard).
Send a POST
request to https://api.respondflow.com/graphql
with the GraphQL query and variables in the request body. We recommend using a GraphQL client library in the language of your choice to construct and send GraphQL API requests.
For example, to send the above GraphQL request using curl:
Code Block |
---|
|
curl --location --request POST 'https://api.respondflow.com/graphql' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\n createMessage (to: $to, from: $from, body: $body, media: $media) {\n id\n legacyId\n toNumber\n fromNumber\n status\n statusDescription\n media\n body\n sentAt\n confirmedAt\n }\n}","variables":{"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\n\nReply STOP to opt-out.","media":[]}}' |
\uD83D\uDCCB Related articles
...
Filter by label |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | com.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@2815e4 |
---|
showSpace | false |
---|
sort | modified |
---|
showSpacetype | falsepage |
---|
reverse | true | type | page
---|
labels | kb-how-to-article |
---|
cql | label = "kb-how-to-article" and type = "page" and space = "VAPI" | labels | kb-how-to-article |
---|
|
🛠 Examples by Language
These code snippets exhibit examples of sending SMS using the GraphQL API without using a GraphQL client library.
Note |
---|
We strongly suggest using a GraphQL client library in the language of your choice when interacting with the Volt GraphQL API. |
C#
Code Block |
---|
|
var client = new RestClient("https://api.respondflow.com/graphql");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) { In addition, we suggest using a pattern of retrying requests with exponential backoff. While Volt strives to ensure all services achieve 99.99% availability, transient failures are inevitable with any service. Retries allow clients to survive these random partial failures and short-lived transient failures by sending the same request again. Most common HTTP libraries include the ability to retry requests as a built-in feature. |
C#
Code Block |
---|
|
var client = new RestClient("https://api.respondflow.com/graphql");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n sentAt\\n confirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}",
ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content); |
Go
Code Block |
---|
|
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.respondflow.com/graphql"
method := "POST"
payload := strings.NewReader("{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n idbody\\n legacyIdsentAt\\n toNumberconfirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is fromNumber654312\\n\\nReply STOP status\\nto opt-out.\",\"media\":[]}}")
client := &http.Client {
statusDescription\\n }
req, err media\\n := http.NewRequest(method, url, payload)
body\\n if err != nil {
sentAt\\n fmt.Println(err)
return
confirmedAt\\n }
}\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}",
ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content); |
Go
Code Block |
---|
|
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.respondflow.com/graphql"
method := "POST"
payload := strings.NewReader("{\"query\":\req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
} |
HTTP
Code Block |
---|
|
POST /graphql HTTP/1.1
Host: api.respondflow.com
Authorization: Bearer <token>
Content-Type: application/json
Content-Length: 492
{"query":"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n bodystatus\\n sentAtstatusDescription\\n confirmedAt\media\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\body\n\\nReply STOP to opt-out.\",\"media\":[]}}") sentAt\n client := &http.Client { } confirmedAt\n req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
} |
HTTP
Code Block |
---|
|
POST /graphql HTTP/1.1
Host: api.respondflow.com
Authorization: Bearer <token>
Content-Type: application/json
Content-Length: 492
{"query":"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\n createMessage (to: $to, from: $from, body: $body, media: $media) { }\n}","variables":{"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\n\nReply STOP to opt-out.","media":[]}} |
Java
Code Block |
---|
|
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n idsentAt\\n legacyId\n toNumber\n fromNumber\n status\n statusDescription\n media\n body\n sentAt\n confirmedAt\n }\n}","variables":{"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\n\nReply STOP to opt-out.","media":[]}} |
Java
Code Block |
---|
|
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"mutationconfirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}");
Request request = new Request.Builder()
.url("https://api.respondflow.com/graphql")
.method("POST", body)
.addHeader("Authorization", "Bearer <token>")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute(); |
JavaScript (Node)
Code Block |
---|
|
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.respondflow.com/graphql',
'headers': {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n
createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n
toNumber\\n fromNumber\\n status\\n statusDescription\\n id
media\\n legacyId
body\\n toNumber
sentAt\\n fromNumber
confirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}");
Request request = new Request.Builder()
.url("https://api.respondflow.com/graphql")
.method("POST", body)
.addHeader("Authorization", "Bearer <token>")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute(); |
JavaScript (Node)
Code Block |
---|
|
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.respondflow.com/graphql',
'headers': {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `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
}
}`,
variables: {"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\n\nReply STOP to opt-out.","media":[]}
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
}); |
PHP
Code Block |
---|
|
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.respondflow.com/graphql',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"query": status
statusDescription
media
body
sentAt
confirmedAt
}
}`,
variables: {"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\n\nReply STOP to opt-out.","media":[]}
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
}); |
PHP
Code Block |
---|
|
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.respondflow.com/graphql',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"query":"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n sentAt\\n confirmedAt\\n }\\n}","variables":{"to":"+15555550145","from":"+15555550123","body":"Your One Time Code is 654312\\n\\nReply STOP to opt-out.","media":[]}}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer <token>',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; |
Python
Code Block |
---|
|
import requests
url = "https://api.respondflow.com/graphql"
payload="{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n sentAt\\n confirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}"
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
CURLOPT_HTTPHEADERresponse => array(
'Authorization: Bearer <token>',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; |
Python
Code Block |
---|
|
import requests
url = "https://api.respondflow.com/graphql"
payload=requests.request("POST", url, headers=headers, data=payload)
print(response.text) |
Ruby
Code Block |
---|
|
require "uri"
require "net/http"
url = URI("https://api.respondflow.com/graphql")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = "{\"query\":\"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n sentAt\\n confirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out. }\\n}\",\"mediavariables\":[]}}"
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text) |
Ruby
Code Block |
---|
|
require "uri"
require "net/http"
url = URI("https://api.respondflow.com/graphql")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = "{\"query\":\{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}"
response = https.request(request)
puts response.read_body |
Unix shell (curl)
Code Block |
---|
|
curl --location --request POST 'https://api.respondflow.com/graphql' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation createMessage ($to: String!, $from: String!, $body: String!, $media: [String!]) {\\n createMessage (to: $to, from: $from, body: $body, media: $media) {\\n id\\n legacyId\\n toNumber\\n fromNumber\\n status\\n statusDescription\\n media\\n body\\n sentAt\\n confirmedAt\\n }\\n}\",\"variables\":{\"to\":\"+15555550145\",\"from\":\"+15555550123\",\"body\":\"Your One Time Code is 654312\\n\\nReply STOP to opt-out.\",\"media\":[]}}"
response = https.request(request)
puts response.read_body' |