Storing HTTP Post Server response data

Storing HTTP Post Server response data

@Patrick van Eijk

Hi,

I have created a short analysis script that does an HTTP post to our LoRa Cloud solver of a particular message that a LoRa tracker sent to Tago. I am able to successfully retrieve the response from the server. The response is an array of objects that I now need to parse. Based on the parsing results I might have to create another action which triggers a second analysis with a second HTTP post.

How do I store this server response (response.data) in a data bucket so I can action off it etc ?

Thanks

Patrick

const { Analysis } = require(’/sdk’);
const axios = require(‘axios’);

async function startAnalysis(context,scope) {

if (!scope.length)
return context.log(‘Analysis must be triggered by an action’)
else
{
const das_token = context.environment.find(x => x.key === ‘das_token’).value;

// retreive the DAS Message
var lora_cloud_das_msg = scope.find(x => x.variable === 'das_msg').value;
//context.log("This is the DAS uplink Message: ",lora_cloud_das_msg);

//define the LoRaCloud URL
const lora_cloud = 'https://das.loracloud.com/api/v1/device/send';

const response = await axios.post(lora_cloud,lora_cloud_das_msg,{headers:{Authorization:das_token}});
context.log("this is the response data from the server: ", response.data);
context.log("server status response: ", response.status);
context.log("HTTP Status text from the server: ", response.statusText);

if (server_response.result.stream_records.length > 0)
  context.log("the ROSE stream_records are : ",JSON.stringify(server_response.result.stream_records));
else
  context.log("the ROSE stream_records are empty!");

}
}