Asana/python-asana

Documentation for create_attachment_for_object is lacking

urysegal-alltrue opened this issue · 1 comments

The documentation for create_attachment_for_object doesn't describe the options and the example really doesn't make any sense as it tries to upload both a file and a URL ( but the description says you can only do one of them). In addition, the description doesn't explain how to actually upload a file, in case this is the way the developer wants to go. Can we get an actual example and a description for the options? Thank you!

Hi @urysegal-alltrue,

Our sample code is auto generated from our OpenAPI Spec so when our SDK is generated the generator will define all possible request body parameters that is available for the endpoint and it is up to the user to determine which properties are needed for that particular endpoint based on our developer documentation for that particular endpoint. The reason why this is tricky for the generator is due to how our endpoint behaves. There are multiple ways you can upload an attachment with our Upload an attachment endpoint EX: 1. local file, 2. url. There isn't a proper way to define this API Behavior in the spec for the generator to understand. Given that you encountered this issue and this will probably have others ask about it, I'll make a note for my team to either manually override this example or create a guide/add example else where on how to make this request.

In the meantime, here is an example of how you would make a request to upload an attachment from a local file (EX: uploading test.txt file from the same directory that this code is ran):

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>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
attachments_instance = asana.AttachmentsApi(api_client)
file = 'test.txt' # str |  (optional)
parent = '123' # str |  (optional) EX: task gid
name = 'This is a test file' # str |  (optional)

try:
    # Upload an attachment
    api_response = attachments_instance.create_attachment_for_object(file=file, parent=parent, name=name)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AttachmentsApi->create_attachment_for_object: %s\n" % e)

Let me know if you have any other questions