I am developing a chatbot using Gupshup.io and wanted to make an HTTP call to external API.
I am using this code:
if(event.message=='hi'){
var contextParam = {
"cobrand": {
"cobrandLogin": "sbCobxxxx",
"cobrandPassword": "xxxxxxx-9f-4307-9d9a-451f3xxxx075",
"locale": "en_US"
}
};
var url = "https://developer.api.yodlee.com:443/ysl/restserver/v1/cobrand/login";
var param = contextParam;
var header = {"Content-Type": "application/x-www-form-urlencoded"};
context.simplehttp.makePost(url,param,header);
return;
}
And this is giving me this error:
TypeError: first argument must be a string or Buffer
How can I make a HTTP POST call to an API which takes parameters in JSON format using the Gupshup's online IDE on their bot builder tool?
I'm from the Gupshup team.
Yes it is possible to make POST calls using the Gupshup Bot Builder. Here's the code to do so:
if(event.message=='hi'){
var contextParam = {
"cobrand": {
"cobrandLogin": "sbCobxxxx",
"cobrandPassword": "xxxxxxx-9f-4307-9d9a-451f3xxxx075",
"locale": "en_US"
}
};
var url = "https://developer.api.yodlee.com:443/ysl/restserver/v1/cobrand/login";
var param = JSON.stringify(contextParam);
var header = {"Content-Type": "application/json"};
context.simplehttp.makePost(url, param, header);
return;
}
Remember to stringify the parameters (contextParam in this case) before adding it as the argument to the makePost method. Also, the content-type is application/json.