HTTP API Request with Node-RED

Hello,
According to the documentation of the application manager api we should be getting output for this API ( GET /applications/{app_id}/devices/{dev_id}) if the input is of the form

{
  "app_id": "some-app-id",
  "dev_id": "some-dev-id"
}

I passed this as msg.payload to the HTTP request node (GET) from the url http://.thethings.network:8084, but I don’t receive a json object.

What is the response code/msg?
How do you manage auth?

I am trying to understand how to manage authentication, currently the response code says that no json string detected. 404 is the code (it is 200 for successful)

If anybody knows anything that can help me kickstart the process please do help.

404 means that your url is wrong. So you don’t have a json because you are not calling an existing ressource. Without auth, but with an existing ressource, you will receive a 403 or 401.

What is the full url you are using?

The url from which i am requesting data is:

http://eu.thethings.network:8084

This is the Snapshot of Node red:
image

You need to call the endpoint, not the root of the API.
Example: http://eu.thethings.network:8084/applications/45
Will answer:
{“error”:“Metadata not valid: neither token nor key present”,“code”:2,“message”:“Metadata not valid: neither token nor key present”} (try in your browser).
In your case, you have to call: http://eu.thethings.network:8084/applications/{app_id}/devices/{dev_id}

1 Like

That’s incomplete. You may want to try without Node-RED first. The following works for me, on a Mac. Just for readability, a trailing backslash \ indicates the command continues on the next line; I think that’s a forward slash / on Windows. The --get and --url are optional, and --header is the same as -H:

  • To get all devices in application arjanvanb-1:

    curl \
      --get \
      --header 'Authorization: Key ttn-account-v2.m2xb7<redacted>I3RqU' \
      --url http://eu.thethings.network:8084/applications/arjanvanb-1/devices
    

    Beware that the URL should not end with a slash; using [...]/devices/ will throw Invalid Device Identifier: DevID not valid: can not be empty.

  • To get details of a single device, like arjanvanb-heltec-4 in application arjanvanb-1:

    curl \
      --get \
      --header 'Authorization: Key ttn-account-v2.m2xb7<redacted>I3RqU' \
      --url http://eu.thethings.network:8084/applications/arjanvanb-1/devices/arjanvanb-heltec-4
    

So, you’ll need something in Node-RED to programmatically expand the URL to include the application id and device id in the URL. See, e.g., https://cookbook.nodered.org/http/handle-url-parameters See, e.g., https://cookbook.nodered.org/http/set-request-url-template or https://cookbook.nodered.org/http/set-request-url (and https://cookbook.nodered.org/#http-requests in general).

2 Likes

For those with allergies at the CLI, Postman is great to begin and understand how an API works.

2 Likes