Get Time tracking entries for a task(python) does not have opt_pretty option


I am using api below

when I see web page and http request params show opt_pretty.

but source code in python library “asana-preview”

does not have opt_pretty.

Do I have to install specific version for that?

It said OpenAPI spec version : 1.0


Please read this before posting

  • If you received an error from the API that you’re looking for help with, please include the error in your post and be descriptive of the requests you made that received the errors. To be clear, we need the error in the JSON response from the API, not the error your code raised.
  • Do not share any API credentials. Please check that the code you’re pasting into the post does not contain any real OAuth tokens or personal access tokens. If you have exposed credentials, you should revoke them immediately.

Hi @andy39

You can add the opt_pretty as a parameter to the request url i.e

Remember to change task_gid with the task you are wanting to operate on

FYI check out the link below on how to install the official Asana Python library

Thanks Harsh4

The url what you provide to me. it checked opt_pretty exist,

but python-asana-preview source code does not exist parameter for opt_field.

it maybe not include that version. I think.

Hi @andy39,

You are right. We removed opt_pretty from our v4 python client library (python-asana) and python-asana-preview the reason for this is because we don’t think it is necessary since the response from the library returns a resource instance instead of a JSON string.

According to our developer docs for opt_pretty:

Provides the response in “pretty” output. In the case of JSON this means doing proper line breaking and indentation to make it readable. This will take extra time and increase the response size so it is advisable only to use this during debugging.

The emphasis is on the “This will take extra time and increase the response size so it is advisable only to use this during debugging.” hence why we do not support this for the newer python library since it doesn’t seem necessary.

Can you describe your use case? If it is desired, we can add it back to the python library.

Also, feel free to use the v4 python client library as they have been updated to use the same syntax as the preview python client library.

Here’s how you would make a call to our v4 python client library (python-asana):

import asana
from import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: oauth2
configuration = asana.Configuration()
configuration.access_token = '<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>'

# create an instance of the API class
api_instance = asana.TimeTrackingEntriesApi(asana.ApiClient(configuration))
task_gid = '<YOUR_TASK_GID>' # str | The task to operate on.
opt_fields = ["created_by","","duration_minutes","entered_on","offset","path","uri"] # list[str] | This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include. (optional)

    # Get time tracking entries for a task
    api_response = api_instance.get_time_tracking_entries_for_task(task_gid, opt_fields=opt_fields)

except ApiException as e:
    print("Exception when calling TimeTrackingEntriesApi->get_time_tracking_entries_for_task: %s\n" % e)

The output of the above code will look like:

{'data': [{'created_by': {'gid': '<USER_GID>',
                          'name': '<USER_NAME>',
                          'resource_type': None},
           'duration_minutes': 720,
           'entered_on':, 8, 3),
           'gid': '<TIME_TRACKING_ENTRY_GID>',
           'resource_type': None}],
 'next_page': None}

You can access the data using dot notation EX:[0].duration_minutes

If you prefer to make a API call with our client library call_api method you can do so with the following:

import asana
from import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: 
configuration = asana.Configuration()
configuration.access_token = '<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

    # GET - /tasks/{task_gid}/time_tracking_entries
    api_response = api_client.call_api(
        path_params={"task_gid": "<YOUR_TASK_GID>"},
        query_params=[('opt_fields', 'created_by,duration'), ('opt_pretty', 'true')],
        header_params={"Accept": "application/json; charset=utf-8"},
        response_type=str, # If there is an existing response model for the resource you can use that EX: "TaskResponseData" or you can specify one of the following types: float, bool, bytes, str, object
except ApiException as e:
    print("Exception: %s\n" % e)
1 Like

Thanks for answer. I just wonder why only that method does not have opt_pretty.

if it is not have that options, it is not big deal with my process.

thanks again.

Hi @andy39,

The method get_time_tracking_entries_for_task is not the only method that does not have opt_pretty all methods in python-asana v4.X.X do not include opt_pretty.

Can you help me understand why you need opt_pretty for python?


Just make consistency with other process what I am doing in my server.

my other process using opt_pretty. as I mentioned before. if it does not have, it is okay for me.