Send SMS via FLOW

http://api.msg91.com/api/v5/flow/

Parameters

Parameter name Data type Description
authkey * alphanumeric Login authentication key (this key is unique for every user)
flow_id * alphanumeric Flow Id of your created flow (this key is unique for every flow)
recipients * array It will carry the mobile numbers along with the respective variables if any
mobiles * integer It contain mobile numbers. You can also use your own mobile number parameter by adding the same in the flow under receiver/recipient field. Mobile number should be in International format. Example: 919898989898, here 91 is the country code and 9898989898 is the mobile number
sender * varchar You can enter your sender id here. If you have used FromAPI as the sender value in your flow, pass the sender id in the API call, else the sender id added to the flow will be processed.
route varchar If your operator supports multiple routes then give one route name. Eg: route=1 for promotional, route=4 for transactional SMS.
unicode integer (0/1) Enter 1 if sending SMS in languages other than English, for english pass 0
schtime date and time When you want to schedule the SMS to be sent. Time format could be of your choice you can use Y-m-d h:i:s (2020-01-01 10:10:00) Or Y/m/d h:i:s (2020/01/01 10:10:00) Or you can send unix timestamp (1577873400)
Variable parameter like VAR1, VAR2 are for the message content that you add in the flow, here the same variable name should be used as the parameter name that was created in the flow and the value to the same will be the value of your variable. Example: "name" : "Drake"

Parameters with (*) are mandatory.

Sample Input / Output

  • JSON

Input

  • Headers
  • Body
{
    "Content-Type": "application/json",
    "authkey": "YOUR_AUTH_KEY"
}
{
    "flow_id":"EnterflowID",
    "sender" : "EnterSenderID",
    "recipients" : [
        {
          "mobiles":"919XXXXXXXXX",
          "VAR1":"VALUE 1",
          "VAR2" : "VALUE 2"
        },
        {
          "mobiles":"9189XXXXXXXX",
          "VAR1":"VALUE 1",
          "VAR2" : "VALUE 2"
        }
    ]
}

Output

  • Success
  • Error
{
    "message": "5762846b4f8d285d378b4567",
    "type": "success"
}
{
    "message":"flow id missing",
    "type":"error"
}

Sample Code

  • PHP
  • JSON
<?php

$senderId = "tester";
$flow_id = 4;
$recipients = array(
    array(
        "mobiles" => "919XXXXXXXXX",
        "VAR1" => "VALUE 1",
        "VAR2" => "VALUE 2"
    ),
    array(
        "mobiles" => "9189XXXXXXXX",
        "VAR1" => "VALUE 1",
        "VAR2" => "VALUE 2"
    )
);

//Prepare you post parameters
$postData = array(
    "sender" => $senderId,
    "flow_id" => $flow_id,
    "recipients" => $recipients
);
$postDataJson = json_encode($postData);

$url="http://api.msg91.com/api/v5/flow/";

$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;
}
?>