console
console copied to clipboard
HTTP integration | assign HTTP header value
We have a need to assign key value from JSON message to a HTTP header or URL Params value.
Can you provide an example of your json body and which key value needs to be pulled out?
The example json attached. smpljson.txt We need following key values in URL Params: dev_eui, decoded.payload.token, reported_at.

@noraneto please try something like this in your integration and verify how it works out for you.
Thanks, this works for URL Params.
Assigning key value from JSON message to a HTTP header or URL Params value does not work anymore. Worked before, please check.
what interpolation values are you trying to add? any more detail would be appreciated
If you're using a custom template. You can only interpolate values present in the template into the URL Params and Header fields.
I have stored a customer specific api-token as a device label when onboarding devices using console api. I also have another device label which defines the flow for the application. Using the custom script function I will read out the label for the api-token from the uplink_info and write it into the decoded payload key. So basically I have decoded.payload.token in my json and I need to assign it to the HTTP header. And yes I am using the custom template and I can read out the decoded.payload.token with it, but I do not want to send this token as a apart of the body. Would it be possible to read out json keys for the header similarly as in the custom template using double curly brackets?
Sounds like you don't want the decoded.payload.token to appear in the integration json, but you want it to be interpolated in your http headers?
This is not possible right now as the interpolation only works for what results from the integration json.
Yes I would like to interpolate keys from original json message into the http header. However as a workaround I tried to interpolate the keys from custom template that I am using, but it didn't work either.
I also tested interpolating keys from json message to http header without using custom template and it didn't work. I am attaching the debug request. debug.txt
Can you show us the interpolation header fields on your integration without using custom integration json? That would be more helpful
Here is how my header fields look.
The interpolation seems to work only with URL params not with the headers.
Header interpolation was added with https://github.com/helium/router/pull/816.
Thank you for the fast response. Please consider making the interpolation work from the original JSON message (integration input) instead the integration result. It will make integration more flexible as the output (when templates are used) is always subset of original JSON message. Normally you do not want to send header or params keys duplicated in the body. Also when integrating with 3rd party APIs they usually do not allow send additional keys in the body.
I'll have to think on that a bit. All existing integrations using this feature are pulling from the templated message. We have to make sure not to break those, without making it cumbersome to use.
Thanks. There is an option to use triple curly brackets for interpolating, I do not recall what is the usage for that, but maybe something similar will do for pulling from the integration input.
Triple curly brackets are part of the official mustache spec https://mustache.github.io/mustache.5.html for opting out of HTML escaping.
Maybe it is possible interpolate from both jsons, integration input and output at the same time and if the same keys exist the output prevails?
Hi In my case I am seeing that neither header nor URL interpolation is working. I am using a custom decoder. I have verified it works. The values are decoded correctly and interpolated correctly in the request body.
This is my flow:
This is my decoder:
function Decoder(bytes, port, uplink_info) {
var decoded={};
try{
var result = String.fromCharCode.apply(null, bytes);
const parsedResult = JSON.parse(result);
decoded.token = parsedResult.deviceToken;
decoded.payload = parsedResult.sensorValue;
return decoded;
} catch (err) {
return 'Decoder: ' + err.name + " : " + err.message;;
}
}
This is my custom template:
{
"token": {{decoded.payload.token}},
"payload": {{decoded.payload.payload}},
}
I have tried many possible variations in the hope that any of them worked. See image below for my header/params configuration
Note that this is just something I did for helping with debugging. In my real scenario I only want a single JWT Authorization
header with the value Bearer <token>
.
Now, when I send a message from my device, and look at the debug window in console. I see that the request body has been successfully interpolated. However the header and url parameters have not.
The message content is {"deviceToken":"theToken","sensorValue":"theValue"}
This is what I see in the Debug tab (body as expected, headers and url params not interpolated):
{
"id": "a8b67e42-c478-4ff9-8e3c-d3072747aaf8",
"name": "RequestBin",
"status": "success"
}
{
"body": "{\n \"token\": theToken,\n \"payload\": theValue,\n}",
"headers": {
"Authorization": "Bearer {{token}}",
"Authorization1": "Bearer {{decoded.payload.token}}",
"Authorization2": "{{decoded.payload.token}}",
"Authorization3": "{{token}}",
"Content-Type": "application/json"
},
"method": "post",
"url": "https://eo41m4s5k7ej6yi.m.pipedream.net",
"url_params": {
"token": "Bearer {{token}}",
"token1": "Bearer {{decoded.payload.token}}",
"token2": "{{decoded.payload.token}}",
"token3": "{{token}}"
}
}