Can't get tag names in task json


#1

Hi all, using the Asana API to extract tasks as json and everything is fine except for the tags they don’t supply the name field. Here’s an example:
[{‘id’: 403649264093954, ‘gid’: ‘403649264093954’, ‘resource_type’: ‘tag’}]
It seems to stop short of providing the name. Any ideas on how to get this? I’ve been struggling for a few days but cannot for the life of me work it out. Cheers


#2

You need to use the opt_field field to ask for the fields you want to get, in your case name. Tell me if that is unclear.


#3

Ok, I’ll have another bash. It seemed odd though as it has supplied everything else for every other field, yet seems to leave off the name. Thanks for the tip, I’ll report back


#4

I guess they have some fields they incorporate by default and some others you need to request.


#5

Still can’t get it to work. Should have mentioned I’m using Python. Here’s a snippet of the code:

workspace = me[‘workspaces’][0]
projects = client.projects.find_by_workspace(workspace[‘gid’], iterator_type=None)
for project in projects:
print(project[‘name’])
print(project[‘gid’])
tasks = client.tasks.find_by_project(project[‘gid’], {“opt_fields”:“tags”}, iterator_type=None)
print(tasks)


this gives the following example printout:

ECHO permissions
423870134675052
[{‘id’: 423878153403869, ‘gid’: ‘423878153403869’, ‘tags’: }]
New PA Life Sciences
423870134675055

CPT
437168064465488

Visio
840368980763000
[{‘id’: 838538674777807, ‘gid’: ‘838538674777807’, ‘tags’: }]
Maintenance Mafia
876187656884319
[{‘id’: 951428934900524, ‘gid’: ‘951428934900524’, ‘tags’: }, {‘id’: 929250285153432, ‘gid’: ‘929250285153432’, ‘tags’: }, {‘id’: 921140107614559, ‘gid’: ‘921140107614559’, ‘tags’: }, {‘id’: 920448290106568, ‘gid’: ‘920448290106568’, ‘tags’: }, {‘id’: 904449946897932, ‘gid’: ‘904449946897932’, ‘tags’: }, {‘id’: 876135098310671, ‘gid’: ‘876135098310671’, ‘tags’: }, {‘id’: 876135098310672, ‘gid’: ‘876135098310672’, ‘tags’: }]


see how the tags have the name field missing? Not sure what to try next


#6

Try using opt_expand instead of opt_field; that should give you the expanded related tag objects instead of just the compact-form objects.


#7

Actually I don’t see any tags, only empty arrays… Can you format your code using the option in the forum ? (</> in the editor)
You can also do {“opt_fields”:“tags.name”} I think.


#8

Very nice!


#9

That’s it Phil, nail on the head. Thanks both for pointing me in the right direction