Having difficulty in sending SMS through smsgateway.me following the recent update

Today, I encountered an issue while trying to send SMS messages programmatically using PHP from localhost. The problem arose after updating to version 4 of smsgateway.me and I am unable to send any messages. I am struggling to figure out how to pass the API key in the given example. Despite numerous attempts, I have not been successful.

Request Endpoint
Endpoint:   https://smsgateway.me/api/v4/message/send
Method: POST
Request Parameters
Name    Location    Required    Description
Content body    true    JSON payload with the information of SMS messages the API should send

Request Example

[
  {
    "phone_number": "07791064781",
    "message": "Hello World",
    "device_id": 1
  },
  {
    "phone_number": "07791064782",
    "message": "Hello World",
    "device_id": 2
  }
]

I even attempted to test with Postman, but it returned a "500 Internal Server Error"

I would greatly appreciate it if you could take a look and assist me. Thank you.

Answer №1

After carefully reviewing the information provided on their website, it seems that the issue lies in not including the API key in the request. If you do possess the API key, make sure to include it in the Authorization header.

Authorization: <insert your API key here>

By utilizing tools such as Postman, you have the ability to set this header and make another attempt.

Answer №2

To access the Token, go to and log in to your account. Navigate to settings to find your unique token.

function sendMessageUsingSmsGatewayApi($message, $phoneNumber, $deviceId)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://smsgateway.me/api/v4/message/send",
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => "[{\"phone_number\": \"$phoneNumber\", \"message\": \"$message\", \"device_id\": $deviceId}]",
            CURLOPT_HTTPHEADER => array(
                "Cache-Control: no-cache",
                "Postman-Token: 0dfb5acc-f0ae-415b-a5d3-ca12a2dfdfd3",
                "authorization: Your-Token-here"
            ),
        ));

        $response = curl_exec($curl);
        $error = curl_error($curl);

        curl_close($curl);

        if ($error) {
            echo "cURL Error Message: " . $error;
        } else {
            echo $response;
        }
    }

Answer №3

In light of the newly introduced documentation on the website lacking an example of sending SMS to multiple phone numbers, I would like to present this jQuery code snippet that enables the sending of SMS using smsgateway.me.

var phones = {
    "phone1": "9999999999",
    "phone2": "8888888888"
};

for (var key in phones) {
    if (phones.hasOwnProperty(key)) {
        var phone_number = phones[key];
        var message = "Test SMS";
        var device_id = 1;
        var data = [{
            "phone_number": phone_number,
            "message": message,
            "device_id": device_id
        }];
        var jsonData = JSON.stringify(data);
        var options = {
            "async": true,
            "crossDomain": true,
            "url": "https://smsgateway.me/api/v4/message/send",
            "method": "POST",
            "headers": {
                "Authorization": "YOUR_API_KEY",
                "Content-Type": "application/json",
            },
            "processData": false,
            data: jsonData
        }
        $.ajax(options).done(function(response) {
            console.log(response);
        });
    }
}

Although this jQuery code functions correctly, there have been instances where it sends multiple SMS to a single number within the provided JavaScript object. This issue may be attributed to the for loop.

Answer №4

Last year, I came across the smsGateway.php and successfully implemented a programmatic way to send SMS. However, on May 10, 2018, the application suddenly stopped working. Despite being able to connect to the smsGateway server, it failed at retrieving messages. The root cause of this issue was traced back to an incorrect device ID, which led me to discover that a new version (v4) had been introduced, requiring additional information for communication with the server. This extra piece of information, known as the Authorization key, could be found by logging into the smsGateway site. The challenge now lies in integrating this new version into the existing smsGateway.php script, a task that I am still actively pursuing.

On May 16, 2018, smsgateway.me released guidelines on integrating software for automated SMS sending. Users with PHP 5.3 may encounter difficulties adapting to these new changes, which are noted to be more complex compared to the previous version (v3).

In addition, a disclaimer on the site states that the documentation is still being updated and new SDKs are in development, adding to the existing complexities. Despite this, I am working on upgrading my PHP version to 5.6 in hopes of resolving any remaining error messages.

Following the PHP upgrade to version 5.5, I managed to get smsgateway.me up and running smoothly. By downloading the required program files from https://github.com/smsgatewayme/client-php, I was able to integrate the necessary components seamlessly.

require_once(__DIR__ . '/autoload.php');
use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;

$clients = new SMSGatewayMe\Client\ClientProvider(
    "your key from website"
);
$sendMessageRequest = new SMSGatewayMe\Client\Model\SendMessageRequest
([
    'phoneNumber' => $HAMiLote['HASMSTel'], 
    'message' => $AXMessage, 'deviceId' => 100701
]);
$sentMessages =   
$clients->getMessageClient()->sendMessages([$sendMessageRequest]);

?><pre><?php print_r($sentMessages); ?></pre><?php

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble sliding with Material UI Slider

I've encountered an issue with my Material UI slider - it doesn't slide when clicked and dragged. I followed one of the examples on the Material UI website (https://material-ui.com/components/slider/) and included an onChange function. The values ...

Arranging JSON data in Python based on string values for sorting

I have a JSON file containing employee information: ll = {"employees":[ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"James", "lastName":"Bond"}, {"firstName":"Celestial", "lastName":"Syste ...

The search feature in AngularJS with filter appears to be malfunctioning

I've been attempting to use the angularjs filter method for searching, but it doesn't seem to be working correctly. Despite not seeing any errors in the console, the search results aren't showing up. Can someone lend a hand with this? Below ...

Sending JSON data to a different domain via AJAX

I am aware that AJAX does not function between separate domains. I am attempting to transmit JSON data from one webpage to another domain that contains a PHP page responsible for storing that JSON data in a database. My approach involved using AJAX to con ...

Only in iOS, AJAX-Requests in a Cordova-based app fail silently

After creating an app using Cordova and XCode, I included local Ajax-Requests to JSON files which were functioning correctly in the previous version of the app on iOS. However, without any changes to the code, these requests are now failing on iOS. Interes ...

What is the most effective way to retrieve specific data from this object using JavaScript?

I attempted to retrieve the number of hashtags used at a specific time using the Twitter API and an npm module called hashtag-count. Below is the program and the generated results object: var HashtagCount = require("hashtag-count") require('dotenv&ap ...

css rules are not applied if the element is dynamically added using javascript

I'm encountering an issue with my code that inserts icons into a div with the ID of "editor". When I try to add a <select> element to the div with the ID of "drug_tool", the CSS styling rules for it are being ignored. How can I resolve this prob ...

Is there a way to incorporate an additional property into an existing JSON object within Azure Functions using C#?

In the Azure function, my input consists of ServiceBus queue properties The code is designed to retrieve all properties: using System.Net; using Newtonsoft.Json; public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter ...

Unable to scroll to the top of the page with JavaScript

I tried the code below but it didn't quite do the trick. Can someone assist me with refreshing the page to the top every time it loads? window.addEventListener('load', function(){ window.scrollTo(0,0) }) window.onload = (event) => { ...

JavaScript: what is the method to add a paragraph when the condition is not met?

I am currently working on a project that involves checking if a student is actively engaged in an online journal. This is done by tracking the student's progress using a unique userId. If the student's userId is not found in the JSON data returne ...

Ensuring that one then() statement waits for the other to finish before executing

My React application is connected to Firestore DB, and I'm fetching data in the componentDidMount() lifecycle method. I handle two then() calls - one for retrieving data from the DB and saving it, and the other for updating the component's state. ...

The deserialization functionality in System.Text.Json's JsonSerializer.Deserialize<T>() may experience difficulties in appropriately parsing

Looking to deserialize this json using System.Text.Json, but encountering difficulties that are unclear. The following result has been obtained: PS: It should be noted that the array containing elements does not have a name, simply follow the link for ref ...

Leveraging react-router for automatic redirection after form submission

My goal is to implement a search functionality on the page where users can enter a search term (name, email, username) and have the page filter out one card from all the cards based on the search value. I believe that upon pressing enter, we should redirec ...

Ways to resolve the problem of connecting Provider with my store and efficiently transmitting data to components in my Redux-React application

Encountering an error that reads: Uncaught Error: Could not find "store" in either the context or props of "Connect(WebShop)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(WebShop)". Despite havin ...

error is not defined in the onsuccess function of the ajax.beginform partial view

Currently, I am working on an MVC5 project where a View is calling a Partial View. Within the Partial View, there is an Ajax.BeginForm that triggers a function on OnSuccess. However, during execution, I encounter an error stating that the function cannot ...

jQuery does not seem to be able to recognize the plus sign (+)

I am currently developing a calculator program and facing some challenges with the addition function. While the other functions ("/", "-", "*") are working fine, the plus ("+") operation seems to be malfunctioning. Here's the snippet of HTML and JavaS ...

What is the reason behind the necessity for a React class component to always invoke super(props) within its constructor function?

I recently came across a tutorial from reactjs.org that mentioned the importance of calling the base constructor with props in class components. However, further research led me to a StackOverflow answer suggesting that super() can be used instead of super ...

The use of NSMutableRequest to structure arrays and dictionaries in the HTTPBody allows for easy communication

Having some trouble figuring this out. I've looked at various examples but can't seem to pinpoint what's going wrong here. It would be great to get a fresh perspective on the issue. I am working with an array and a dictionary that I need to ...

Need help adding color to your PlotlyJS barpolar chart background?

After creating a PlotlyJS barpolar chart, I noticed an issue with the background color where the bars end. The background color seems to be stuck on white, as shown in the image. (Please ignore the transparent black rounded square in the background, as it ...

Contrasting createMuiTheme and getMuiTheme

When would you choose to use one over the other? What are the key differences in how they operate? ...