Actility's LoraWan platform integrated with Node-Red

I am currently working on learning how to implement an HTTP GET request for the Actility platform in Node-RED. However, I keep encountering an error 401 indicating that the authorization bearer is missing.

This is how my setup looks:

https://i.sstatic.net/CcYbc.png

When making a request to the platform, I receive two codes:

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'

The first code is the token bearer, and the second one is the request URL:

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

I am seeking guidance on creating a flow that can generate the correct response. Any assistance would be appreciated.

Thank you.

function setup

Answer №1

The JavaScript code executed within a function node operates in a secure environment (sandboxed), limiting access to certain features like "require". Nevertheless, this limitation can be easily bypassed by directly adding necessary header data to the msg.headers object, either within the same function node or through a change node.

Although we are not provided with specifics regarding the injected data, based on the information from the http request node documentation, several optional input fields can be included in the request to communicate with the Actility system:

msg.url (string)
    Setting this property is optional and determines the request's URL.

msg.method (string)
    This optional property specifies the HTTP method for the request: GET, PUT, POST, PATCH, or DELETE.

msg.headers (object)
    Defines the request's HTTP headers.

msg.cookies (object)
    If specified, it allows sending cookies along with the request.

msg.payload
    Represents the request body.

If you are transmitting data to Actility via a POST request, you can include the necessary Auth headers by utilizing a simple function node that resembles the following example:

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

In another scenario where the bearer credential string is present as the payload, and there is a predefined payload to be sent to Actility, your function could take this form:

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

Please note: for these injected fields to be effective, values for properties such as msg.url or msg.method must not be pre-set within the http request node configuration.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Searching for nested divs with the same class name in jQuery can be achieved by using the

Need assistance in locating all divs with a specific class name. Some divs may have nested divs with the parent div's class name. Take this scenario for example: <div class="myForm"> <div class ="myDiv"> <div class ="myDiv"> ...

"Enhance user experience with AJAX for selecting multiple checkboxes or performing mult

Hey there! So, I've got a question about handling multiple checkboxes with the same name in a form. Here's an example of what I'm working with: <input type="checkbox" name="myname[]" value="1" /> <input type="checkbox" name="myname ...

Automatically populate input field values into a textarea using a separator with jQuery

There are multiple input fields to fill out: <input type="text" placeholder="name"> <input type="text" placeholder="age"> <input type="text" placeholder="gender"> <input type="text" placeholder="interest"> As I enter information i ...

"Unfortunately, the JavaScript external function failed to function properly, but miraculously the inline function

Struggling to create a fullscreen image modal on the web? I was able to get it working fine when embedding the script directly into my HTML file, but as soon as I moved it to an external JS file, things fell apart. I've double-checked all the variable ...

Optimizing performance: Making the most of mongoose updateMany middleware

PROBLEM SOLVED: SOLUTION PROVIDED BELOW I have a piece of code where I am updating elements one by one: //registerCustomers.js const CustomerRegistrationCode = require("../models/CustomerRegistrationCode"); const setRegCodesToUsed = async (regC ...

Troubleshooting: Issue with Displaying $Http JSON Response in AngularJS View

Struggling to retrieve JSON data from an API and display it in a view using AngularJS. Although I am able to fetch the data correctly, I am facing difficulties in showing it in the view. Whenever I try to access the object's data, I constantly receive ...

Unable to retrieve advanced custom field values from Wordpress

I need to integrate data from my WordPress server into my Swift project. The data is in JSON format and the specific values I require are generated using "advanced custom fields" on the WordPress server. After loading it from another view controller, I ut ...

Is there a way to redirect focus to an object with a lower z-index when working on overlaying a sequence of transparent divs on a map?

Is it possible to give focus to a parent div that contains a child div without hiding the child div? I am integrating the Google Maps API and need to overlay a grid of transparent divs for inserting information. However, with these divs on top of my map, ...

Icons in React are used to visually represent various actions

I am facing an issue with the React icons I imported on my personal website. They are not displaying at all. Despite reinstalling React Icons multiple times, with and without --save, the problem persists. I have thoroughly checked both the node_modules dir ...

What could be causing my C# function to not be triggered by AJAX?

I am attempting to invoke this specific C# method: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string getJSONdata() { string jsonString = ""; using (SqlConnection con = new SqlConnection(conn ...

PHP throws a invalid argument error when attempting to decode a JSON file

Currently, I am attempting to parse a JSON file using PHP with the following code snippet. <?php $content = file_get_contents('result.json'); $contendecoded = json_decode($content); print_r($contendecoded); foreach ($contendecoded ...

Create a custom loading spinner for a jQuery AJAX request

How can I add a loading indicator to my Bootstrap modal that is launched from a link? Currently, there is a 3-second delay while the AJAX query fetches data from the database. Does Twitter Bootstrap have built-in functionality for this? UPDATE: Modified J ...

Determine if a key begins with a specific string within an object and retrieve the corresponding value

If I have an object like this: let fruitSong = {'apple song':12, 'banana song': 24} Object.keys(fruitSong).forEach(e=>{ if(e.startsWith('apple')){ console.log(fruitSong[e]) } }) Is there a different meth ...

Can the lazy load script dependent on jQuery be utilized before the jquery.js script tag in the footer?

After receiving HTML from an AJAX callback, I noticed that there is a script tag for loading code that uses jQuery. However, I consistently encounter the error of jQuery being undefined. All scripts are connected before the closing </body> tag. Is ...

Displaying Images on top of Images with React/Javascript/NextJS

I have two images. Let's say image 1 is a thumbnail for news content. I would like to overlay a promotional PNG banner on top of this image and create a new output image. This output image will be used as the OG (Open Graph) image. How can I achieve t ...

Conceal the absence of a value within an array

I need assistance with handling an array of parameters: $fields = [ 'idutente' => $_POST['acf']['field_60084ad3970a8'] ?? 0, 'nome' => $_POST['acf']['field_6050d30f14572'], ...

Issue with Angular 6 subscribe event not being caught by subject?

A new element was crafted to house a loader: @Component({ selector: 'app-loader', templateUrl: './loader.component.html', styleUrls: ['./loader.component.scss'], providers: [LoaderService] }) export class LoaderCompon ...

When code is obfuscated, JsonConvert.DeserializeObject() may return unexpected object types

In my C# solution, I have two projects: the main application and a license project. Both projects are functioning smoothly. I used JSON to serialize the license details, and now I want to obfuscate the licensing project to enhance security against frauds o ...

Guide on sending MySQL query results as JSON data using Ajax

I'm having trouble figuring out how to pass the results of a MySQL query into an HTML page using AJAX and JSON. I have the following code in ajax2.php: $statement = $pdo->prepare("SELECT * FROM posts WHERE subid IN (:key2) AND Poscode=:postcode2") ...

The code snippets in the Vue3 documentation are quite peculiar

As I peruse the Vue 3 documentation, I notice a recurring pattern in how example code is presented for components: Vue.createApp({}) However, my experience with Vue 3 has been different. Instead of the above syntax, I simply use: <script> export d ...