问题
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?
回答1:
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;
回答2:
msg.payload
contains the body of the request, but it looks like the server you're trying to query requires the data to be passed as a query string.
Try this:
msg.url = "https://api.socialstudio.radian6.com/v3/posts?topics=234243&limit=100"
(and remove msg.payload
)
来源:https://stackoverflow.com/questions/42596187/unable-to-pass-payload-parameters-to-node-red-http-request