Send SMS

http://api.msg91.com/api/v2/sendsms

Parameters

Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
mobiles * integer Keep numbers in international format (with country code), multiple numbers should be separated by comma (,)
message * varchar Message content to send
sender * varchar Receiver will see this as sender's ID.
route * varchar If your operator supports multiple routes then give one route name. Eg: route=1 for promotional, route=4 for transactional SMS.
country numeric 0 for international,1 for USA, 91 for India.
flash integer (0/1) flash=1 (for flash SMS)
unicode integer (0/1) unicode=1 (for unicode SMS)
scheduledatetime date and time When you want to schedule the SMS to be sent. Time format will be Y-m-d h:i:s
response varchar By default you will get response in string format but you want to receive in other format (json,xml) then set this parameter. for example: &response=json or &response=xml
campaign varchar Campaign name you wish to create (up to 50 characters).

Parameters with (*) are mandatory.

Sample Input / Output

  • XML
  • JSON
  • HTTP

Input

http://api.msg91.com/api/v2/sendsms?authkey=YourAuthKey&mobiles=98260XXXXX,98261XXXXX&message=message&sender=senderid&route=4&country=0

Output

  • Success
  • Error
{
    "message": "5762846b4f8d285d378b4567",
    "type": "success"
}
{
    "type":"error",
    "message":"Missing Authentication Key",
    "code":"106"
}

Input

  • Headers
  • Body
{
    "Content-Type": "application/xml",
    "authkey": "YOUR_AUTH_KEY"
}
<MESSAGE>
    <SENDER>SenderID</SENDER>
    <ROUTE>Template</ROUTE>
    <CAMPAIGN>XMlAPI</CAMPAIGN>
    <COUNTRY>country code</COUNTRY>
    <SMS TEXT="message1">
        <ADDRESS TO="98260XXXXX"></ADDRESS>
        <ADDRESS TO="98261XXXXX"></ADDRESS>
    </SMS>
</MESSAGE>

Output

  • Success
  • Error
<RESPONSE>
    <TYPE>success</TYPE>
    <MESSAGE>57a455944f8d28676c8b4567</MESSAGE>
</RESPONSE>
<RESPONSE>
    <TYPE>error</TYPE>
    <MESSAGE>Missing mobile no.</MESSAGE>
    <CODE>101</CODE>
</RESPONSE>

Input

  • Headers
  • Body
{
    "Content-Type": "application/json",
    "authkey": "YOUR_AUTH_KEY"
}
{  
   "sender":"MSGIND",
   "route":"4",
   "country":"91",
   "flash":1,
   "sms":[
        {  
             "message":"Message1",
             "to":["98260XXXXX","98261XXXXX"]
        },
        {  
            "message":"Message2",
            "to":["98260XXXXX","98261XXXXX"]
        }
    ]
}

Output

  • Success
  • Error
{
    "message": "5762846b4f8d285d378b4567",
    "type": "success"
}
{
    "type":"error",
    "message":"Missing Authentication Key",
    "code":"106"
}

Sample Code

  • PHP
  • HTTP
  • XML
  • JSON
<?php

$mobileNumber = "9999999999";

$senderId = "tester";

$message = urlencode("Test message");

$route = 4;

//Prepare you post parameters
$postData = array(
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

$url="http://api.msg91.com/api/v2/sendsms";


$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "$url",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $postData,
    CURLOPT_HTTPHEADER => array(
        "authkey: your_auth_key",
        "content-type: multipart/form-data"
    ),
));

$response = curl_exec($curl);

$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
?>
                        
<?php
$xmlStr = '<MESSAGE>
    <AUTHKEY>your_auth_key</AUTHKEY>
    <SENDER>tester</SENDER>
    <ROUTE>4</ROUTE>
    <CAMPAIGN>FLASH</CAMPAIGN>
    <COUNTRY>91</COUNTRY>
    <UNICODE>1</UNICODE>
    <SMS TEXT="यूनिकोड" >
        <ADDRESS TO="9999999999"></ADDRESS>
        <ADDRESS TO="9999999999"></ADDRESS>
    </SMS>
    <SMS TEXT="यूनिकोड 2">
        <ADDRESS TO="9999999999"></ADDRESS>
    </SMS>
</MESSAGE>';

$url="http://api.msg91.com/api/v2/sendsms";

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "$url",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $xmlStr,
    CURLOPT_HTTPHEADER => array(
        "authkey: your_auth_key",
        "content-type: application/xml"
    ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
?>
                        
<?php

$senderId = "tester";
$route = 4;
$campaign = "test Camp";
$sms = array(
    'message' => 'test message',
    'to' => array('9999999999')
);
//Prepare you post parameters
$postData = array(
    'sender' => $senderId,
    'campaign' => $campaign,
    'route' => $route,
    'sms' => array($sms)
);
$postDataJson = json_encode($postData);

$url="http://api.msg91.com/api/v2/sendsms";

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "$url",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $postDataJson,
    CURLOPT_HTTPHEADER => array(
        "authkey: your_auth_key",
        "content-type: application/json"
    ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
?>