Skip to content

Instantly share code, notes, and snippets.

@sd031
Last active March 24, 2023 11:55
Show Gist options
  • Save sd031/5fce44669a5bf024bef1 to your computer and use it in GitHub Desktop.
Save sd031/5fce44669a5bf024bef1 to your computer and use it in GitHub Desktop.
this is a sample code for smsgupshup api
var express = require('express');
var request = require('request');
var app = express();
//there should be too many things above this line , use mean.io framework for building api fopr quality code
//
//sample api path
app.post('/send_message', function (req, res) {
//below all are post variable
//mobile_no,message
var mobile_no = req.body.mobile_no;
var message = encodeURIComponent(req.body.message);
//credential from smsgupshup
var userid = 'your api user ip';
var password = 'your api password';
//try to break api params as much as possible and put variable on it
var url = 'http://enterprise.smsgupshup.com/GatewayAPI/rest?method=SendMessage&send_to='+mobile_no+'&msg='+message+'&msg_type=TEXT&userid='+userid+'&auth_scheme=plain&password='+password+'&v=1.1&format=text';
request
.get(url)
.on('response', function(response) {
console.log(response.statusCode); // 200
if(response.statusCode=='200'){
//1 for success or whatever for you need
res.send('1');
}else{
//0 for failure or whatever for you need
res.send('0');
}
});
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
@dhruvitphoenixs
Copy link

not working this code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment