Templates
Read a template
/v1/templates/{id}/v1/templates/{id}cURL. The key is in the SENDSMS_API_KEY environment variable.
curl --max-time 30 --request GET \
--url 'https://api.sendsms.to/v1/templates/TEMPLATE_ID' \
--header "X-API-Key: $SENDSMS_API_KEY"Node.js 18+ (built-in fetch).
const response = await fetch("https://api.sendsms.to/v1/templates/TEMPLATE_ID", {
method: "GET",
headers: {
'X-API-Key': process.env.SENDSMS_API_KEY,
},
signal: AbortSignal.timeout(30000),
});
console.log(response.status, await response.text());Python 3.8+, standard library only.
import json
import os
import urllib.error
import urllib.request
request = urllib.request.Request(
"https://api.sendsms.to/v1/templates/TEMPLATE_ID",
method="GET",
headers={
"X-API-Key": os.environ["SENDSMS_API_KEY"],
},
)
try:
with urllib.request.urlopen(request, timeout=30) as response:
print(response.status, response.read().decode("utf-8"))
except urllib.error.HTTPError as error:
print(error.code, error.read().decode("utf-8"))PHP with the cURL extension.
<?php
$ch = curl_init("https://api.sendsms.to/v1/templates/TEMPLATE_ID");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('SENDSMS_API_KEY'),
],
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), PHP_EOL, $body, PHP_EOL;
curl_close($ch);Ruby 2.6+, standard library: net/http, uri.
require 'net/http'
require 'uri'
uri = URI('https://api.sendsms.to/v1/templates/TEMPLATE_ID')
request = Net::HTTPGenericRequest.new('GET', false, true, uri.request_uri)
request['X-API-Key'] = ENV.fetch('SENDSMS_API_KEY')
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 30, read_timeout: 30) { |http| http.request(request) }
puts "#{response.code} #{response.body}"Go, standard library.
package main
import (
"fmt"
"io"
"net/http"
"os"
"time"
)
func main() {
req, err := http.NewRequest("GET", "https://api.sendsms.to/v1/templates/TEMPLATE_ID", nil)
if err != nil {
panic(err)
}
req.Header.Set("X-API-Key", os.Getenv("SENDSMS_API_KEY"))
client := &http.Client{Timeout: 30 * time.Second}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode, string(data))
}.NET 6+ (HttpClient, top-level statements).
using System;
using System.Net.Http;
using System.Text;
using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
using var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sendsms.to/v1/templates/TEMPLATE_ID");
request.Headers.Add("X-API-Key", Environment.GetEnvironmentVariable("SENDSMS_API_KEY"));
using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");Java 11+ (java.net.http). File SendSmsExample.java.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.UUID;
public class SendSmsExample {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30)).build();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sendsms.to/v1/templates/TEMPLATE_ID"))
.timeout(Duration.ofSeconds(30))
.header("X-API-Key", System.getenv("SENDSMS_API_KEY"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}Dart 2.12+, dart:io and dart:convert only.
import 'dart:convert';
import 'dart:io';
Future<void> main() async {
final client = HttpClient()..connectionTimeout = const Duration(seconds: 30);
final request = await client.openUrl('GET', Uri.parse('https://api.sendsms.to/v1/templates/TEMPLATE_ID'));
request.headers.set('X-API-Key', Platform.environment['SENDSMS_API_KEY'] ?? '');
final response = await request.close().timeout(const Duration(seconds: 30));
final body = await response.transform(utf8.decoder).join();
print('${response.statusCode} $body');
client.close();
}#Parameters
| Field | Type | Description |
|---|---|---|
idrequired | path · string |
#Responses
200Successful result
Response format
| Field | Type | Description |
|---|---|---|
idrequired | string · uuid | Template UUID generated by the SendSMS database when created. Stable across edits; use version to identify content revisions. It is not messageId. |
channelrequired | string | Template channel stored by SendSMS. This API is SMS-only. |
namerequired | string | Customer-supplied template name validated and stored by SendSMS. |
bodyrequired | string | Customer-supplied template text with {{placeholders}}, stored for this version. Not a sent message. |
statusrequired | string | Moderation state recorded by SendSMS for the returned template/version. Lists can show the template state; detail/create/update use the current version state. pending/approved/rejected and historical legacy are documented below."pending" "approved" "rejected" "legacy"
|
createdAtrequired | string · date-time | Template record creation timestamp assigned by the SendSMS database. ISO 8601 UTC; Not a message-delivery timestamp. |
updatedAtrequired | string · date-time | Last record change timestamp maintained by SendSMS. ISO 8601 UTC; Not a message-delivery timestamp. |
trafficClassrequired | string | null | Traffic class supplied by the customer and stored by SendSMS; null means none is pinned in the template. This does not override account permissions. |
variablesrequired | array<object> | Variable definitions derived by SendSMS from placeholders actually used in body and supplied definitions. An empty array means no placeholders.maxItems: 30 |
variables[].namerequired | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name.pattern: "^[A-Za-z_][A-Za-z0-9_]{0,39}$" |
variables[].requiredrequired | boolean | Requirement computed/stored by SendSMS from the variable definition; normally true. phone is supplied from the recipient when available.default: true |
variables[].samplerequired | string | Example value supplied by the customer or SendSMS catalog. Used only by preview with useSamples=true; never a substitute for actual send values.maxLength: 500 |
variables[].labeloptional | string | Display label supplied by the customer or SendSMS built-in catalog. May be absent from template definitions. Not used as the substitution key.maxLength: 80 |
variables[].builtinrequired | boolean | Boolean generated by SendSMS: true means a built-in variable such as phone; false means a customer-defined variable. |
versionrequired | integer | Positive version number assigned by SendSMS: starts at 1 and increments when content/settings change. An unchanged update can retain the number. Not a timestamp. |
archivedrequired | boolean | Boolean calculated by SendSMS from the archive marker. true means unavailable for a new send; history is retained. |
dryRunoptional | boolean | Present only in the answer to a trial request (X-Dry-Run: true): nothing was executed; identifiers in this answer are conditional.const: true |
400Invalid input
Check required fields, value types and the request format.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
401Invalid or revoked API key
Check the X-API-Key header and key status. Never expose the key in client-side code. The machine code is in the code field: api_key_missing or api_key_invalid.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
403Insufficient key permissions or account/channel policy; or the request came from an IP address not allowed for this key (ip_not_allowed)
Check API key permissions, account settings and channel availability.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
404Resource unavailable to this account
Check the resource ID and whether it belongs to the API key account.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
409Conflict
Check the current resource state and operation conditions before retrying.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
422Validation or eligibility failure
Correct the data or eligibility conditions indicated in the response.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |
429Rate limit
Reduce the request rate and delay retries. The general per-second limit: code = rate_limit_exceeded.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
503Temporarily unavailable
The service is temporarily unavailable. Before retrying an SMS submission, check whether the previous request was accepted.
Response format
| Field | Type | Description |
|---|---|---|
errorrequired | string | Error identifier or legacy human-readable text returned by SendSMS. Not every handler exposes a stable machine code here. Check HTTP status and documented identifiers; never parse translated prose as a permanent code. |
messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
codeoptional | string | Optional machine-readable code generated by SendSMS or its HTTP framework. Meaning depends on the operation; not a universal numeric provider code. |
statusCodeoptional | integer | Optional HTTP status number generated by the server framework for a framework-level error. The actual HTTP response status is authoritative. |
errorsoptional | array<object> | Optional field-validation issues generated by SendSMS, typically for template create/update. An absent array is not an empty successful result. |
errors[].fieldoptional | string | Request field identified by the SendSMS validator, such as name or body. |
errors[].messageoptional | string | Optional explanation generated by SendSMS. Intended for people; wording/language may change. Absence means the handler supplied no separate explanation. |
missingoptional | array<string> | Variable names SendSMS found missing from a template send/preview request. Present only for relevant template errors. |
invalidoptional | array<object> | Invalid variable values identified by SendSMS, with variable name and validation reason. |
invalid[].nameoptional | string | Variable identifier derived from a {{placeholder}} in the template or built-in catalog; use it as a key in variables. Not a person’s actual name. |
invalid[].reasonoptional | string | SendSMS validation reason: value_too_long, invalid_characters or unsupported_type. It describes a variable value, not network delivery. |
channeloptional | string | Requested channel echoed by SendSMS in a channel-availability refusal. |
reasonsoptional | array<string> | SendSMS channel refusal reasons, such as globally disabled, not assigned, not implemented or not configured. These are platform policy results, not operator receipt codes. |