Skip to content
Advertisement

Extracting a particular Project ID from Asana Task API via Node.js JSON output

Using the Asana Task API, we’re able to see the list of projects that a task belongs to, as well as those projects’ GID and Notes (description text).

Desired outcome

The entire goal here is to grab the GID of the project that has #websiteprojecttemplate within its Notes value. We need to find the GID of that project, and then output it so we can use that GID later on in our Zapier actions.

Asana Task API

Using this API URL, we can see the output of the API which returns the data of the projects (including the GID and Notes). I believe this is JSON. https://app.asana.com/api/1.0/tasks/{id}?opt_fields=projects.notes

For example: https://app.asana.com/api/1.0/tasks/1799885428032109?opt_fields=projects.notes shows as: 

https://i.imgur.com/zSizMNC.png


Current code

Ideally, the Node.js Javascript code would be able to iterate/search/find the one with #websiteprojecttemplate and then output the matching GID. In this case, it’d be: 1199916857565229

This is the JS code I have so far:

JavaScript

Which outputs something like:

JavaScript

But I need it to output not the entire body’s data, but only the gid value that had #websiteprojecttemplate in its notes value.


TL;DR

How do we update the current code so that it can iterate through the gid and find the one that has #websiteprojecttemplate in the notes, and output the gid number of it?

Advertisement

Answer

I think your question boils down to how to find an element in an array.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement