Asana/python-asana

'created_by' property

mhmostafa88 opened this issue · 1 comments

Before the recent update, the 'created_by' property used to exist, but now it's missing from the returned task object.
It's true that this property doesn't exist in the asana api documentation, but it does exist, it's an undocumented property
(see this thread in the asana forum )

Hi @mhmostafa88,

Thank you for reporting this. We have updated our developer documentation to show this property as an opt-in option. Here are some ways to make this request with the python client library:

Option 1: Using the task instance

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_PERSONAL_ACCESS_TOKEN>'

# Create an instance of the API class
api_instance = asana.TasksApi(asana.ApiClient(configuration))
task_gid = '<YOUR_TASK_GID>'
opt_fields = ["created_by","name"]

try:
    # Get a task
    api_response = api_instance.get_task(task_gid, opt_fields=opt_fields)
    # Print task created_by
    pprint(api_response.data.created_by)
except ApiException as e:
    print("Exception when calling TasksApi->get_task: %s\n" % e)

Option 2: Using the call_api method

import asana
from asana.rest import ApiException
from pprint import pprint

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

try:
    # GET - get a task
    api_response = api_client.call_api(
    "/tasks/{task_gid}",
    "GET",
    path_params={"task_gid": "<YOUR_TASK_GID>"},
    query_params=[('opt_fields', 'created_by,name')],
    header_params={"Accept": "application/json; charset=utf-8"},
    body=None,
    post_params=[],
    files={},
    response_type=object, # 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={},
    )
    # Print task created_by
    pprint(api_response['data']['created_by'])
except ApiException as e:
    print("Exception when calling TasksApi->get_task: %s\n" % e)