Trouble passing device_id from action

Trouble passing device_id from action

Hello,

I'd like to pass the device_id of the device that triggers the analysis. This analysis is setup to trigger on mqtt topic. It then posts data to an http endpoint. I successfully get the payload, but am not able to pass the device_id through. Any help would be greatly appreciated.

var { Analysis, Account, Resources } = require("@tago-io/sdk");
var axios = require("axios").default;

async function startAnalysis(context, scope) {
  try {
    const account = new Account({
      token: "123456789"
    });
    // Ensure that scope is not empty before accessing scope[0]
    if (scope && scope.length > 0 && scope[0]) {
      const resources = new Resources({account, token: context.token});
      const device = resources.devices;
      const device_id = device.info;
      console.log("Device Token/ Device", device);
      console.log("Device ID", device_id);
      const payload = scope[0];
      const dataToSend = [];
      const payloadData = payload.d;
      const timeStamp = payload.ts;

        // Organizing data to be sent in the dataToSend object
        for (const [variable, value] of Object.entries(payloadData)) {
          dataToSend.push({
            variable: variable,
            value: Number(value),
            time: timeStamp
          });
        }

        if (dataToSend.length > 0) {
          await device.sendData(dataToSend);
          await sendTelemetryToApi(device_id, dataToSend);
      }
    } else {
      console.error("Invalid or empty scope:", scope);
    }
  } catch (error) {
    console.error("Error in analysis:", error);
  }
}
var sendTelemetryToApi = async (serialNumber, telemetry) => {