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.