Can't get tag names in task json


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


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.


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


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


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:
tasks = client.tasks.find_by_project(project[‘gid’], {“opt_fields”:“tags”}, iterator_type=None)

this gives the following example printout:

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


[{‘id’: 838538674777807, ‘gid’: ‘838538674777807’, ‘tags’: }]
Maintenance Mafia
[{‘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


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


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”:“”} I think.


Very nice!


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