Node-Red,LoraWan Actility平台

问题描述 投票:0回答:1

我试图学习如何在Node red中为Actility平台添加一个http get请求。现在我只收到错误401,不包括授权承载。

安装程序如下所示:

enter image description here

我从平台上得到两个代码

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer xxx' 'https://dx-api.thingpark.com/core/latest/api/devices?deviceEUI=xx&healthState=ACTIVE&statistics=true&extendedInfo=true'

首先是令牌承载。

第二个是请求网址。

https://dx-api.thingpark.com/core/latest/api/devices?deviceEUI=xxx&healthState=ACTIVE&statistics=true&extendedInfo=true

如何创建能够正确生成答案的流程?

谢谢。

function setup

javascript json http request node-red
1个回答
1
投票

function节点中的Javascript是沙箱(在虚拟机中运行),因此您无法使用某些功能,如“require”。但是,这不是问题 - 您可以将任何标头信息直接添加到msg.headers对象中,无论是在function节点中,还是在change节点中。

您没有向我们显示您正在注入的数据,但根据http request节点信息,您可以将所有这些(可选)字段作为输入传递,这些字段可以成为对Actility系统的请求的一部分:

msg.url (string)
    If not configured in the node, this optional property sets the url
    of the request.

msg.method (string)
    If not configured in the node, this optional property sets the HTTP
    method of the request. Must be one of GET, PUT, POST, PATCH or DELETE.

msg.headers (object)
    Sets the HTTP headers of the request.

msg.cookies (object)
    If set, can be used to send cookies with the request.

msg.payload
    Sent as the body of the request.

假设您要将要POST的有效负载数据注入到Actility中,您只需使用一个简单的函数节点添加您需要的Auth头,该节点执行如下操作:

msg.method = "POST";
msg.headers = {
    "Authorization": "Bearer xxx",
    "Content-Type": "application/json"
};
return msg;

或者,假设您将持有者凭据字符串作为有效负载传递给函数,并且您有一个固定的有效负载要发送到Actility - 那么您的函数可能看起来像这样:

msg.method = "POST";
msg.headers = {
    "Authorization": "Bearer " + msg.payload,
    "Content-Type": "application/json"
};
msg.payload = { "foo": "bar" };
return msg;

注意:为了使用这些注入的字段,http request节点之前不能将它们的值定义为节点配置的一部分。

© www.soinside.com 2019 - 2024. All rights reserved.