Using Asana Search API with Python - custom fields

Hi there!

I am trying to use Asana search API with my little program written in Python 3.
I have access to workspace ID, I have also a custom field which is an alphanumeric value, let’s call it Field 1.
Now I want to search my workspace to find a task that will have a value of this custom field set to, for example, lorem1.

Following these instructions I tried with bash curl something like this:

curl -H "Authorization: Bearer <mytoken>" "https://app.asana.com/api/1.0/workspaces/workspaceID/tasks/search?custom_fields.Field1.value=lorem1"
 and it works.

But when I want to use this in Python with a function in python asana library (here)
search_in_workspace(), it returns an error " InvalidRequestError: Invalid Request: You must specify at least one search filter."
I presume that the format of the data I am passing through is wrong (see below), but I cannot find anywhere an example of how it should look like.
My not-working code:

query= { "custom_fields" : { 'Field1' : 'lorem1' } }
find_tasks = client.tasks.search_in_workspace(workspace_id, query)

Anyone knows how the data should look like?

Did you have a look at the Python library source code? @Diakoptis any idea?

Hi @Kernelko,

The key-value pairs in the URL need to map exactly to key-value pairs in the query dictionary you give to the client library. In this case, the key in the URL is custom_fields.Field1.value so your input would need to be query = {"custom_fields.Field1.value": "lorem1"}

Hi Joe, I want to filter projects by custom field (n Klipfolio) and I’m running into problems with the query URL. Can you point to documentation or possibly provide the proper syntax? Thanks!

Hi @Kelli_Booth, full documentation for the search API is hosted on our developers portal.

@Joe_Trollo I had trouble interpreting the syntax for python from the deverlopers portal. Specifically, I tried completed_since=now and couldn’t get it to work. The python documentation doesn’t give any examples. Where could I learn how to apply a completed_now filter in the python API for search functions? Thank you!

Were you successful at running a search with other parameters?

Hi @gf11, all the accepted parameters for the search API are listed out in tables in the documentation. In this case, what you’re looking for is likely completed=false.