# Messages Batch

# Before You Start

Make sure to review the documentation for sending a single message before working with message batches.

# Sending a Message Batch

To send multiple SMS messages in a batch, make a POST request to the /message/send-batch endpoint.

# Parameters

Parameter Required? Description
messages yes An array of messages to be sent in this batch.
messages[].recipient yes The mobile phone number of the SMS recipient.
Format requirements:
• National (Romania): 07PPXXXXXX, 407PPXXXXXX.
• For international numbers, add the 00 prefix: 00359XXXXXXXXX.
messages[].message yes The SMS message body.
messages[].sender no The sender of the message. Must be pre-approved and configured by a GoSMS representative.
• Alphanumeric senders may not be supported by all operators.
• If missing or invalid, the default short number assigned to your connection will be used.
messages[].scheduleDatetime no The date and time when the message should be sent.
Accepted formats: YYYY-MM-DDTHH:MM:SS.mmmZ or YYYY-MM-DD HH:MM:SS.
If missing or invalid, the server’s current date and time will be used.
messages[].validity no Message validity period in minutes.
If set to a value greater than 0, the message remains valid for that duration starting from the scheduled date and time.
If not delivered within the period, the message will expire and will not be charged.

# Code Samples

curl -X POST "https://api.gosms.ro/v1/message/send-batch" \
     -H "X-Authorization: [YOUR_API_KEY]" \
     -H "Content-Type: application/json" \
     -d '{
           "messages": [
              {
                "recipient": "0712345678",
                "message": "This is a test message."
              },
              {
                "recipient": "0712345678",
                "message": "This is another test message."
              }
            ]
         }'
try {
    const res = await fetch("https://api.gosms.ro/v1/message/send-batch", {
        method: "POST",
        headers: {
            "X-Authorization": "[YOUR_API_KEY]",
            "Content-Type": "application/json"
        },
        body: JSON.stringify({
            messages: [
                {
                    recipient: "0712345678",
                    message: "This is a test message."
                },
                {
                    recipient: "0712345678",
                    message: "This is another test message."
                }
            ]
        })
    })
    const json = await res.json()
    console.log(json)
} catch(err) {
    console.log(err)
}
<?php

$apiKey = "[YOUR_API_KEY]";
$url = "https://api.gosms.ro/v1/message/send-batch";

$data = [
    'messages' => [
        [
            "recipient" => "0712345678",
            "message" => "This is a test message."
        ],
        [
            "recipient" => "0712345678",
            "message" => "This is another test message."
        ]
    ]
];

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-Authorization: $apiKey",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

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

echo $response;

# Response

On success, the endpoint will return a response similar to the following:

{
  "success": true,
  "message": "Message orders registered.",
  "balanceDeduction": "0.06",
  "currency": "EUR",
  "orderSummary": [
    {
      "arrayPosition": 0,
      "amount": 0.03,
      "recipient": "0712345678",
      "messageId": "63ff4994-28d0-49c8-ac89-6ad5312525e5"
    },
    {
      "arrayPosition": 1,
      "amount": 0.03,
      "recipient": "0712345678",
      "messageId": "f2381e75-7fcb-4ace-a1c1-1afc0a101b95"
    }
  ]
}