Changing Device Tags With Widget

Changing Device Tags With Widget


I am trying to do exactly the same as in this topic:

So i created the widget in my blueprint dashboard, field1 was configured to my blueprint device and i set the variable name as "constant_a"

The button was set to trigger my analysis, which is:

  1. /**
     * Update the value of a Tag without affecting others

    const { Account, Analysis, Device, Utils, Services } = require("@tago-io/sdk");
    async function updateTag(context, scope) {
      // Requires scope to know what device and what widget called it
      if (!scope[0]) throw "Scope is missing";

      // Read the stored account_token and make an account object
      const env_vars = Utils.envToJson(context.environment);
      const account = new Account({ token: env_vars.account_token });

      // Get the device id of the caller
      const {origin} = scope[0];

      // Get the new tag value from the widget. Change "VARIABLE_NAME" to match that within the input form.
      const new_tag = scope.find(x => x.variable === 'constant_a');

      console.debug(`Device: ${scope[0].device}`);

      // Get the device's info using its ID, then isolate the tags

      const device_info = await;
      var tags = device_info.tags;
      // Search for the Tag Key you want to edit "KEY_NAME"
      let i
      for(i = 0; i < tags.length; i++){
      // Find the Key/Value pair you want to edit
      // C
        if(tags[i].key == "device_constant_a"){
        // Set the VALUE of the pair you want to edit to the one provided by the input form
        tags[i].value = new_tag.value;
      // Push the new set of tags to the device. You're done!
      account.devices.edit(origin, { tags });
    module.exports = new Analysis(updateTag);
But i am getting this error:

[2023-04-14 11:10:47] Analysis Called.
[2023-04-14 11:10:47] Duration: 1.6s Billed Duration: 2s.
[2023-04-14 11:10:47] Analysis finished.
[2023-04-14 11:10:47] node:internal/process/promises:288 triggerUncaughtException(err, true /* fromPromise */); ^ [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Invalid Device ID".] { code: 'ERR_UNHANDLED_REJECTION' } Node.js v18.13.0
[2023-04-14 11:10:46] Device: 63ab3dfd6b0686000adf15e0 > TagoIO-SDK: No region or env defined, using fallback as usa-1.

What am i missing?

Thanks in advance,