1

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?

Antti29
  • 2,953
  • 12
  • 34
  • 36
SUNNY
  • 125
  • 1
  • 3
  • 13

1 Answers1

4

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.

Sohan
  • 1,287
  • 1
  • 15
  • 29