Ranjit Singh Shekhawat
Ranjit Singh Shekhawat

Reputation: 529

Sending sms to multiple phonenumbers using mysms API

I'm trying to send sms using mysms API. I am able to send to single number using following example:

Example: https://api.mysms.com/json/message/send?api_key=xxxxx&msisdn=xxx&password=xxx&recipient=436761234567&message=Hi

How can I send to multiple number using above example?

Upvotes: 1

Views: 736

Answers (1)

GxGL
GxGL

Reputation: 11

I came up with this code:

function sendSMS() {
    var apikey = "your api_key";
    var mno = 40123123456; // msisdn = your number without +sign in from
    var pwd = "yourpassword";
    // var no = 40123123456; // single number & replace this with a real one
    var grp = [40123123456,40123123456,40123123456]; // multiple numbers / let's call it a group & just replace those with your actual testing numbers
    var msg = "Hi!%0aThis is a test message!%0aThis is another row.%0a:D"; // Use %0a to insert a new row in your message

    for ( var i in grp ) {
        var smsurl = "https://api.mysms.com/json/message/send?api_key="+apikey+"&msisdn="+mno+"&password="+pwd+"&recipient="+grp[i]+"&message="+msg+"";
        var xhttp = new XMLHttpRequest();
        xhttp.open("GET", smsurl, true);
        xhttp.send();
        console.log(smsurl);
    }
}

Now just make the call:

sendSMS();

This code is javascript and I hope will answer your question well. Also it was tested and proven that is working. There is always room for improvements.

Upvotes: 1

Related Questions