Here is my curl request. I am trying to convert this to nodemon.js request.
curl--location 'https://conversations.messagebird.com/v1/conversations/start' \
--header 'Authorization: AccessKey Key' \
--header 'Content-Type: application/json' \
--data '{"to": "+919853092550",
"type": "hsm",
"channelId": "f10ea05178db478089117cc7cba79d5c",
"content":
{"hsm":
{"namespace": "92239cc8_406b_4bdf_aab5_b1c379b9b139",
"templateName": "otp",
"language":
{"policy": "deterministic","code": "en"},
"params": [
{"default": "123456"}
]
}
}}'
Here, this is how i converted this.
var headers = {
Authorization: "AccessKey Key",
"Content-Type": "application/json",
};
var dataString = `{
"to": ${number},
"type": "hsm",
"channelId": "f10ea05178db478089117cc7cba79d5c",
"content": {
"hsm": {
"namespace": "92239cc8_406b_4bdf_aab5_b1c379b9b139",
"templateName": "otp",
"language": { "policy": "deterministic", "code": "en" },
"params": [{ "default": ${otp} }],
},
},
}`;
var options = {
url: "https://conversations.messagebird.com/v1/conversations/start",
method: "POST",
headers: headers,
body: dataString,
};
request.post(options, function (error, response, body) {
if (error) console.log(error);
console.log(body);
});
I am getting below error. I tried by doing JSON.stringify still not working.
{ "errors": [{ "code": 21, "description": "JSON is not a valid format" }] }
Please take a look how to solve this issue