# Send an SMS

You can send an SMS using the resource /sms

The whole purpose of this endpoint is to ingest an SMS into our systems. In that regard, the following behaviour should be handled by your implementation:

  • The return of this request will always return the sms with a status of pending
  • The id returned can be used to retrieve status updates
  • The request will only fail if the provided request is not valid in a definitive manner (incorrect phone number, missing parameters, unauthorized)

The following payload is expected in the body of the request (complete the fields as needed):

{
  "from": "",
  "to": "",
  "body": "",
  "shortenUrls": true,
  "isTransactional": false
}

And returns the following response.

{
  "shortenUrls": true,
  "isTransactional": false,
  "from": "36789",
  "to": "590690112233",
  "body": "Hello world !",
  "id": "8_zyfMv7Q_o7ovXviPUu3",
  "status": "pending",
  "statusReason": ""
}

Note that you're receiving two new fields in the response.

  • id: This is the id generated by Sofy for your message. You must store this id in your system in order to receive further status updates.
  • status: The status of the SMS. Will always be pending as no processing has taken place yet.

# Code examples

curl -X 'POST' \
  "https://api.sofy.fr/v1/sms" \
  -H "accept: application/json" \
  -H "X-API-KEY-ID: $SOFY_API_KEY_ID" \
  -H "X-API-KEY-SECRET: $SOFY_API_KEY_SECRET " \
  -H "Content-Type: application/json" \
	-d '{
    "from": "APITEST",
    "to": "590690112233",
    "body": "Hello world",
    "shortenUrls": true,
    "isTransactional": false
  }'
# Where SOFY_API_KEY_ID and SOFY_API_KEY_SECRET are environment variables containing your credentials
import axios from 'axios';
require('dotenv').config();

const myNumber = '590690112233';

axios.post(
  'https://api.sofy.fr/v1/sms',
  {
    from: 'APITEST',
    to: myNumber,
    body: 'Hello world',
    shortenUrls: true,
    isTransactional: false,
  },
  {
    headers: {
      'X-API-KEY-ID': process.env.SOFY_API_KEY_ID,
      'X-API-KEY-SECRET': process.env.SOFY_API_KEY_SECRET,
    },
  },
);
<?php

$ID = getenv('SOFY_API_KEY_ID');
$SECRET = getenv('SOFY_API_KEY_SECRET');

$myNumber = '590690112233';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sofy.fr/v1/sms");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "X-API-KEY-ID: " . $ID,
    "X-API-KEY-SECRET: " . $SECRET,
	"Content-Type: application/json"
));

$payload = json_encode(array("from" => 'APITEST', 'to' => $myNumber, 'body' => 'Hello world'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

# High Throughput

You can safely loop over all the messages you want to send and call the /sms resource.

However, because REST over HTTP is not a lightweight medium, you could experience low thoughput if your network latency is high. In order to achieve very high throughput in this scenario, you must parallelize your requests using any method. Your overwall rate should not exceed the rate limit.

# Rate Limiting

In order to protect our systems, we have rate limits in place for all endpoints, so that is also the case for /sms. Even though they're well calibrated for a typical usage, we're aware that it can be problematic for batch sending of SMSes. See Rate limiting to learn more.