Python API - Getting Project IDs from Portfolios, Locked out of other portfolios

Hi all,

I am working with the Python API, which is proving to be very useful. We are looking to automating pulls from the API to populate our datawarehouse for project analytics.

We have just moved to subscribing to business class, and I noticed that the python API doesn’t support portfolios in the way we expected.

Its a two part problem.

  1. The python API is great, and has a method for projects called projects.find_by_workspace. However there isn’t an equivalent projects.find_by_portfolio method.

As such it was difficult to find the portfolio_ids. To find portfolios we had to use the follow GET company instead:

#Note: the XXXX are just commenting our IDs

portfolios = client.get(’/workspaces/XXXXXXXXXXXXXX/portfolios/?owner=XXXXXXXXXXXXXX’. We can get a list of the following:

, id
, gid
, resource_type
, name
, owner
, created_at
, custom_field_settings
, color
, workspace

I am thinking if there is a way to find our the portfolio id relates the project id, perhaps with some sort of bridge connection similar to how Project Membership maps projects to users, if there was a some way to map Portfolios to projects.

ASK: Is there a way to map projects to portfolios be it through one of the asana python API methods, or through some GET command I am not immediately seeing.

  1. We have also found that Portfolios throw an error if you don’t in fact own the portfolios with your token / account.

I receive the following error:

ForbiddenError Traceback (most recent call last)
in ()
12 , color
13 , workspace
—> 14 ’
16 })

C:\ProgramData\Anaconda2\lib\site-packages\asana\client.pyc in get(self, path, query, **options)
114 # options in the query takes precendence
115 query = _merge(query_options, api_options, parameter_options, query)
–> 116 return self.request(‘get’, path, params=query, **options)
118 def get_collection(self, path, query, **options):

C:\ProgramData\Anaconda2\lib\site-packages\asana\client.pyc in request(self, method, path, **options)
83 url, auth=self.auth, **request_options)
84 if response.status_code in STATUS_MAP:
—> 85 raise STATUS_MAPresponse.status_code
86 elif 500 <= response.status_code < 600:
87 # Any unhandled 500 is a server error.

ForbiddenError: Forbidden: You can only request portfolios that you own.


Either way, I can’t loop through user_id to get a list of all portfolios. Is the API when getting a list of projects only getting public within my workspace then? Why are portfolio’s considered private when I can get so much project and task data? Can I set portfolios to be owned by everyone?

ASK: How could I make a portfolio public within my workspace? Or does a portfolio HAVE to be owned by an account? Is this on the product timeline to have portfolios better integrated with the Asana platform. You have to invite people by a link anyway which is outside of the normal workflow for projects and tasks

I would be greatly thankful for any advise on these asks.

All the best,

Hi Jake_Olsby,

Welcome to the community!

Assuming you write and/or customize python code, the list of projects can be obtained via the ITEMS IN A PORTFOLIO endpoint where each item corresponds to project (compact form / less details) in a particular portfolio.

GET    /portfolios/{portfolio_gid}/items

Then you can get more details of projects using

GET    /projects/{project_gid}

You can follow similar methods available in the Python SDK for other endpoints.

There is no projects->portfolios mapping (I haven’t seen) in the API that could address portfolio to project relations except the above one. @Joe_Trollo, @Diakoptis could provide more insights, I believe.

#Regarding ASK 2:

According to the Portfolios Endpoint, you are unable to retrieve portfolios owned by others (other Asana account holders). You can see all portfolios of all members of the workspace in the Asana account, but in order to retrieve all portfolios in your workspace via API you will need to use API keys from other account holders who are the owner of their portfolios.

Hope that gives you some insights.


Hi @Jake_Olsby, sorry about the missing method in our client libraries—they tend to lag behind our official API due to the process involved in updating them with new features.

Unfortunately, we do not currently expose any mapping from a project to the portfolios it’s in—only from a portfolio to the projects it contains. Additionally, portfolios cannot be made public and must have an owner. This is a limitation of the web product that the API cannot avoid, but we will update the API as soon as we hear of changes to portfolios in the web product.