Send SMS function in Javascript

I am quite not much familiar with javascript and want to create a function for sending SMS, generally a normal function I can able to create but chunk function with I am not able to run. I also read the other threads available on Google but it was not helpful. Please help I want when I call this function then API will run.
How do I achieve the goal…

API Documenation

const options = {
  "method": "POST",
  "hostname": "api.msg91.com",
  "port": null,
  "path": "/api/v5/flow/",
  "headers": {
    "authkey": "1234567890",
    "content-type": "application/JSON"
  }
};

const req = http.request(options, function (res) {
  const chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    const body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write("{\n  \"flow_id\": \"EnterflowID\",\n  \"sender\": \"EnterSenderID\",\n  \"short_url\": \"1 (On) or 0 (Off)\",\n  \"mobiles\": \"919XXXXXXXXX\",\n  \"VAR1\": \"VALUE 1\",\n  \"VAR2\": \"VALUE 2\"\n}");
req.end();```

Want to create this function

sendSMS(myflowid, mysenderid, myshorturl, mymobileno, myvar1, myvar2);
if(sendSMS ==1) {
     return res.json({msg:"MSG Sent"});
} else {
     return res.json({msg:"MSG Not Sent"});
}

Just to be sure: This code is for NodeJS as a background process or do you use it in the browser?

I just want to create a function… OR we can say convert into a sort code in dynamic way where we can able to pass the data in api.

I just wonder. If you use this function in browser JavaScript you need to insert the api key into the code. If you do so, everybody can see it and of course use it for his own needs. Don’t know if this is what you want

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.