Unable to pass payload parameters to Node-RED http request

旧巷老猫 提交于 2019-12-13 16:25:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!