0

I am using Text Local SMS API and echoing out the response in PHP, although the "response" says success but the delivery status in the report panel of the text local api shows that the status is invalid. Here is my code: I have hidden the api, sender and phone number here.

$OTP = rand(1000,9999);
$apiKey = urlencode('My API');

// Message details
$var= $OTP;

//10 digit phone number with country code 91
$numbers = array(911234567890);
$sender = urlencode('XXXXXX');
$message = rawurlencode("Dear User, your OTP login is ".$var." . This OTP is valid only for 24 hours.");

$numbers = implode(',', $numbers);

// Prepare data for POST request
$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/send/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

The output I get after execution is:

{"balance":988,"batch_id":1834685178,"cost":1,"num_messages":1,"message":{"num_parts":1,"sender":"xxxxxx","content":"Dear User, your OTP login is 8836 . This OTP is valid only for 24 hours."},"receipt_url":"","custom":"","messages":[{"id":"12565543282","recipient":911234567890}],"status":"success"} 

I tried using the message id to check the delivery status. Here is the code.

// Account details
$apiKey = urlencode('My API');

// Message Details
$message_id = '12565543282';

// Prepare data for POST request
$data = array('apikey' => $apiKey, 'message_id' => $message_id);

// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/status_message/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Process your response here
echo $response;

Below is the response of the delivery status. The status "I" means invalid delivery status as per documentation of Text Local.

{"message":{"id":12565543282,"recipient":911234567890,"type":"sms","status":"I","date":"2021-06-27 11:00:45"},"status":"success"}

I have also tried using username and hash instead of the api key but still the results are same. I also tried the same scripts in both localhost and in server but the results are still the same. Can anybody help??

  • 1
    You may want to direct your question to the support of the service you're using. What you describe with your question sounds like a totally valid practice to me. The API call is successful, the delivery status of the message is invalid. These are likely valid states and unless you have not violated the API contract it looks fine (regardless that the fact not sending the message is likely not intended, it's just that things can go wrong, it's not always the happy path). Users are reporting back on SO that the textlocal support is responsive: https://stackoverflow.com/a/65493089/367456 – hakre Jun 27 '21 at 06:09
  • 1
    Thanks. The problem is resolved. It was a problem from their end. – Paarth Pratim Barua Jun 29 '21 at 07:24
  • Heya, I think that is a valid answer to the question. Give it a try, adding it as answer will make this Q/A here more complete. – hakre Jun 29 '21 at 12:31

0 Answers0