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 asana.rest 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","created_by.name","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)
try:
# Get time tracking entries for a task
api_response = api_instance.get_time_tracking_entries_for_task(task_gid, opt_fields=opt_fields)
pprint(api_response)
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': datetime.date(2023, 8, 3),
'gid': '<TIME_TRACKING_ENTRY_GID>',
'resource_type': None}],
'next_page': None}
You can access the data using dot notation EX:
api_response.data[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 asana.rest 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)
try:
# GET - /tasks/{task_gid}/time_tracking_entries
api_response = api_client.call_api(
"/tasks/{task_gid}/time_tracking_entries",
"GET",
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"},
body=None,
post_params=[],
files={},
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
auth_settings=["oauth2"],
async_req=None,
_return_http_data_only=True,
_preload_content=True,
_request_timeout=None,
collection_formats={},
)
pprint(api_response)
except ApiException as e:
print("Exception: %s\n" % e)