Bulk Upload Setup Tutorial using CSV Files

Dear Vitor,

Do you mind checking the GitHub script version, please? Without changing anything, I just downloaded the available version, used the tago-builder command to generate the code to be used in the cloud (as described in documentation) and got the following error:

[2022-04-07 08:16:02] (node:108) UnhandledPromiseRejectionWarning: undefined (Use `node --trace-warnings ...` to show where the warning was created) (node:108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:108) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thank you!

And besides the question above, it is possible to define the bucket type via script, please?

As it is, the Legacy bucket type is created, but because this one will be deprecated, I would like to create the immutable one already.

Thank you again!

Hi there,

Thank you for contacting us and sorry for the inconvenience. We appreciate your feedback and we are aware of the issue with the GitHub script version. Unfortunately, the script is outdated and it does not work well with the newest bucket versions, which are Immutable and Mutable buckets. We are planning to update the script as soon as possible, but we cannot give you an exact timeline right now.

Thank you for your patience and understanding.

Hi there,

We have some good news for you! We have updated the outdated bulk import via CSV script and the CSV example as well.

To get the changes, you just need to reinstall the template and you are good to go. We hope you enjoy this feature and let us know if you have any questions or feedback.

Cheers

Hi Philip,

Thanks for updating the script. The link to the dashboard template appears to be broken.

And FWIW - At least on a Mac, I had to separately install tago-builder (npm i -g @tago-io/builder ) in order to be able to run it.

Cheers,

Erwin

Same thing for me: “Template not found”

Hi Ducktator and Erwin,

I used this link: https://admin.tago.io/template/6001ec2ba103cf001da03282 and it worked as expected:

Hi all,

How would we be able to also pre-define tags per device when bulk importing using a CSV?
For example, when I onboard a new user I’d want to pre-assign the tag key: company and tag value: company_name and maybe some other tags.Thanks!

Hi Duckator,

Check Tago’s analysis-example-bulkupload on GitHub (https://github.com/tago-io/analysis-example-bulkupload) you will need to customize that script to reach what you’re looking for. The repo have the script from the analysis of this post.

Guilherme Costa

Software Engineer

Ah, I see.
Just have to uncomment and use line 73.
Read right over that.

Dear Team,

Updating my question: It is possible to delete folders via script?

For example: I uploaded many CSV files to register the devices, but then I would like (and need because of the storage limit) to delete the folder “buckets” in my Tago profile → files → buckets with all of the CSV files.

Thank you

Hi Desenvolvimento,

Yeah, you can delete specific files by using the SDK.

Hi, Freddy!

Would you mind giving me an example of how I could use it, please? Even after reading the SDK, I’m still having some problems.

//const { Files } = require('@tago-io/sdk');//async function f_main(context, scope){  csvUrl = 'https://api.tago.io/file/ ... ';  arq = new Files();  arq.delete(csvUrl)}

Thank you for your attention!

Hi Desenvolvimento

The following code will list all your root files and folders:

const { Analysis, Account, Utils } = require("@tago-io/sdk");

async function listDevicesByTag(context) {
  const envVars = Utils.envToJson(context.environment);

  if (!envVars.account_token) {
    return context.log("Missing account_token environment variable");
  }

  const account = new Account({ token: envVars.account_token });
  const files = await account.files.list();

  context.log("Files:", files);
}

module.exports = new Analysis(listDevicesByTag);

Output

[2023-05-26 16:23:42] Analysis Called.
[2023-05-26 16:23:42] Duration: 1.4s Billed Duration: 2s.
[2023-05-26 16:23:42] Analysis finished.
[2023-05-26 16:23:42] Files: { files: [ { filename: 'helloworld.txt', size: 7, last_modified: 2023-05-26T19:14:45.000Z, public: true } ], folders: [ 'buckets', 'dashboard screenshot' ], total: 50, usage: 1.13 }
[2023-05-26 16:23:41] > TagoIO-SDK: No region or env defined, using fallback as usa-1.
[2023-05-26 16:23:40] Starting Analysis...

If you need something more specific, just ask and I’ll be glad to help!

Thank you, Freddy!

I could list the files and use the delete(), nevertheless, the files are kept in my account. Could you help me again, please?

My code:

My output:

As you can see, I even tried to paste the entire link, but even so, my file was not deleted:

Thank you again!

Hi Desenvolvimento!

You forgot to add a to your delete method.

So if you have a helloworld.txt in your root folder you’ll need to call the method like such:

await account.files.delete([“/helloworld.txt”]);

Hope this helps ya! :slight_smile:

Ops, you’re totally right! haha

Now it worked! :smiley:

Thank you again for all of your attention.

The Bulk Upload tutorial had been updated to use the Access Policies feature and be up to date with TagoIO SDK!