Unable to pass payload parameters to Node-RED http request

Peter picture Peter · Mar 4, 2017 · Viewed 7.1k times · Source

I am trying to do a simple http get request in Node-RED. According to online documentation I have to pass the parameters in a function as input for the http request node. My function looks like this;

msg.url = "https://api.socialstudio.radian6.com/v3/posts"
msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.payload = {
        'topics': 234243,
        'limit': 100,
    }
return msg;

However when i look at the server response i get the error:

["{"error":{"message":"Missing topics parameter.","statusCode":400,"errorCode":"MC-Unknown","requestId":"RnY9E0pbcU1lkiaf"},"meta":null}"][1]

I have tried other api's but I have not yet been able to pass the payload parameters.

What am I doing wrong?

Answer

hardillb picture hardillb · Mar 4, 2017

If you want to pass query parameters for a GET request you should set the base URL in the http request node and use the mustache syntax to include them:

https://api.socialstudio.radian6.com/v3/posts?topics={topics},limit={limts}

and change the function node to this:

msg.method = "GET"
msg.headers = {'access_token': access_token}
msg.topics = 234243;
msg.limit = 100;

return msg;