pythonjsonapiasana

Accessing optional fields using Asana Python API


I am trying to get additional fields when making a call through Asana's Python API Tasks.find_by_project(). My code for the call is:

project_tasks = Tasks(self.client).find_by_project(project_gid, opt_fields= ["name", "memberships", "gid"])

And I am getting:

{'id': 408541814417314, 'gid': '408541814417314', 'memberships': [{}], 'name': 'Reports - Develop quality control report to run for MES'}

It seems like I can only access the fields that are populated by the compact task record, but I need additional fields and would like to get them without re-looping through all the tasks and getting the complete task. Oddly, it returns an empty list, but when I look at the full tasks record there are memberships for this task.

I saw this question, which seems to be similar but the given (attempted) solution doesn't work for me (I get no additional fields): How can I access custom fields from Asana API using Python?


Solution

  • In case anyone else runs into this issue, I had tyo work with Asana to get this figured out. memberships isn't callable, you have to call Tasks(self.client).find_by_project(project_gid, opt_fields= ["name", "memberships.section", "gid"]) or Tasks(self.client).find_by_project(project_gid, opt_fields= ["name", "memberships.project", "gid"]) you can also apparently call opt_expand=['memberships'] to get all of the data.

    from asana:

    Thanks for your patience!

    We heard back from our Platform Team regarding the issue. What you are experiencing is currently expected behavior, but it is not intuitive, because the membership object doesn't have any data of its own.

    If you wanted to get the nested data, you can specify which data you want opt_fields=['memberships.project', 'memberships.section'] in their opt_fields request. Another option is to use opt_expand=['memberships'] to get all of the data.

    Hope this helps! Let me know if there's anything else I can assist you with.