Package: asana-preview
asana_previewThis is apreview versionof Asana's new python client library. For feedback and feature requests, please leave a comment onthis forum threador throughthe feedback form on our documentation siteAPI version: 1.0Package version: 1.0.38Requirements.Python 3.4+Installation & Usagepip install fromPyPIpipinstallasana-previewThen import the package:importasana_previewSetuptoolsInstall viaSetuptools.pythonsetup.pyinstall--user(orsudo python setup.py installto install the package for all users)Then import the package:importasana_previewGetting StartedPlease follow theinstallation procedureand then run the following:importasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classusers_api_instance=asana_preview.UsersApi(api_client)user_gid="me"opts={}try:# Get a useruser=users_api_instance.get_user(user_gid,opts)pprint(user)exceptApiExceptionase:print("Exception when calling UsersApi->get_user:%s\n"%e)Example: GET, POST, PUT, DELETE on tasksGET - get multiple tasksimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classtasks_api_instance=asana_preview.TasksApi(api_client)opts={'limit':50,'offset':"eyJ0eXAiOJiKV1iQLCJhbGciOiJIUzI1NiJ9",'assignee':"14641",'project':"321654",'section':"321654",'workspace':"321654",'completed_since':'2012-02-22T02:06:58.158Z','modified_since':'2012-02-22T02:06:58.158Z','opt_fields':"actual_time_minutes,approval_status,assignee,assignee.name,assignee_section,assignee_section.name,assignee_status,completed,completed_at,completed_by,completed_by.name,created_at,created_by,custom_fields,custom_fields.asana_created_field,custom_fields.created_by,custom_fields.created_by.name,custom_fields.currency_code,custom_fields.custom_label,custom_fields.custom_label_position,custom_fields.date_value,custom_fields.date_value.date,custom_fields.date_value.date_time,custom_fields.description,custom_fields.display_value,custom_fields.enabled,custom_fields.enum_options,custom_fields.enum_options.color,custom_fields.enum_options.enabled,custom_fields.enum_options.name,custom_fields.enum_value,custom_fields.enum_value.color,custom_fields.enum_value.enabled,custom_fields.enum_value.name,custom_fields.format,custom_fields.has_notifications_enabled,custom_fields.is_formula_field,custom_fields.is_global_to_workspace,custom_fields.is_value_read_only,custom_fields.multi_enum_values,custom_fields.multi_enum_values.color,custom_fields.multi_enum_values.enabled,custom_fields.multi_enum_values.name,custom_fields.name,custom_fields.number_value,custom_fields.people_value,custom_fields.people_value.name,custom_fields.precision,custom_fields.resource_subtype,custom_fields.text_value,custom_fields.type,dependencies,dependents,due_at,due_on,external,external.data,followers,followers.name,hearted,hearts,hearts.user,hearts.user.name,html_notes,is_rendered_as_separator,liked,likes,likes.user,likes.user.name,memberships,memberships.project,memberships.project.name,memberships.section,memberships.section.name,modified_at,name,notes,num_hearts,num_likes,num_subtasks,offset,parent,parent.created_by,parent.name,parent.resource_subtype,path,permalink_url,projects,projects.name,resource_subtype,start_at,start_on,tags,tags.name,uri,workspace,workspace.name"}try:# Get multiple taskstasks=tasks_api_instance.get_tasks(opts)fortaskintasks:pprint(task)exceptApiExceptionase:print("Exception when calling TasksApi->get_tasks:%s\n"%e)POST - create a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classtasks_api_instance=asana_preview.TasksApi(api_client)body={"data":{"name":"New Task","projects":["<YOUR_PROJECT_GID>"],}}opts={}try:# Create a tasktask=tasks_api_instance.create_task(body,opts)pprint(task)exceptApiExceptionase:print("Exception when calling TasksApi->create_task:%s\n"%e)PUT - update a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classtasks_api_instance=asana_preview.TasksApi(api_client)body={"data":{"name":"Updated Task",}}task_gid="<YOUR_TASK_GID>"opts={}try:# Update a tasktask=tasks_api_instance.update_task(body,task_gid,opts)pprint(task)exceptApiExceptionase:print("Exception when calling TasksApi->update_task:%s\n"%e)DELETE - delete a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classtasks_api_instance=asana_preview.TasksApi(api_client)task_gid="<YOUR_TASK_GID>"try:# Delete a tasktask=tasks_api_instance.delete_task(task_gid)pprint(task)exceptApiExceptionase:print("Exception when calling TasksApi->delete_task:%s\n"%e)Documentation for API EndpointsAll URIs are relative tohttps://app.asana.com/api/1.0ClassMethodHTTP requestDescriptionAttachmentsApicreate_attachment_for_objectPOST/attachmentsUpload an attachmentAttachmentsApidelete_attachmentDELETE/attachments/{attachment_gid}Delete an attachmentAttachmentsApiget_attachmentGET/attachments/{attachment_gid}Get an attachmentAttachmentsApiget_attachments_for_objectGET/attachmentsGet attachments from an objectAuditLogAPIApiget_audit_log_eventsGET/workspaces/{workspace_gid}/audit_log_eventsGet audit log eventsBatchAPIApicreate_batch_requestPOST/batchSubmit parallel requestsCustomFieldSettingsApiget_custom_field_settings_for_portfolioGET/portfolios/{portfolio_gid}/custom_field_settingsGet a portfolio's custom fieldsCustomFieldSettingsApiget_custom_field_settings_for_projectGET/projects/{project_gid}/custom_field_settingsGet a project's custom fieldsCustomFieldsApicreate_custom_fieldPOST/custom_fieldsCreate a custom fieldCustomFieldsApicreate_enum_option_for_custom_fieldPOST/custom_fields/{custom_field_gid}/enum_optionsCreate an enum optionCustomFieldsApidelete_custom_fieldDELETE/custom_fields/{custom_field_gid}Delete a custom fieldCustomFieldsApiget_custom_fieldGET/custom_fields/{custom_field_gid}Get a custom fieldCustomFieldsApiget_custom_fields_for_workspaceGET/workspaces/{workspace_gid}/custom_fieldsGet a workspace's custom fieldsCustomFieldsApiinsert_enum_option_for_custom_fieldPOST/custom_fields/{custom_field_gid}/enum_options/insertReorder a custom field's enumCustomFieldsApiupdate_custom_fieldPUT/custom_fields/{custom_field_gid}Update a custom fieldCustomFieldsApiupdate_enum_optionPUT/enum_options/{enum_option_gid}Update an enum optionEventsApiget_eventsGET/eventsGet events on a resourceGoalRelationshipsApiadd_supporting_relationshipPOST/goals/{goal_gid}/addSupportingRelationshipAdd a supporting goal relationshipGoalRelationshipsApiget_goal_relationshipGET/goal_relationships/{goal_relationship_gid}Get a goal relationshipGoalRelationshipsApiget_goal_relationshipsGET/goal_relationshipsGet goal relationshipsGoalRelationshipsApiremove_supporting_relationshipPOST/goals/{goal_gid}/removeSupportingRelationshipRemoves a supporting goal relationshipGoalRelationshipsApiupdate_goal_relationshipPUT/goal_relationships/{goal_relationship_gid}Update a goal relationshipGoalsApiadd_followersPOST/goals/{goal_gid}/addFollowersAdd a collaborator to a goalGoalsApicreate_goalPOST/goalsCreate a goalGoalsApicreate_goal_metricPOST/goals/{goal_gid}/setMetricCreate a goal metricGoalsApidelete_goalDELETE/goals/{goal_gid}Delete a goalGoalsApiget_goalGET/goals/{goal_gid}Get a goalGoalsApiget_goalsGET/goalsGet goalsGoalsApiget_parent_goals_for_goalGET/goals/{goal_gid}/parentGoalsGet parent goals from a goalGoalsApiremove_followersPOST/goals/{goal_gid}/removeFollowersRemove a collaborator from a goalGoalsApiupdate_goalPUT/goals/{goal_gid}Update a goalGoalsApiupdate_goal_metricPOST/goals/{goal_gid}/setMetricCurrentValueUpdate a goal metricJobsApiget_jobGET/jobs/{job_gid}Get a job by idMembershipsApicreate_membershipPOST/membershipsCreate a membershipMembershipsApidelete_membershipDELETE/memberships/{membership_gid}Delete a membershipMembershipsApiget_membershipGET/memberships/{membership_gid}Get a membershipMembershipsApiget_membershipsGET/membershipsGet multiple membershipsOrganizationExportsApicreate_organization_exportPOST/organization_exportsCreate an organization export requestOrganizationExportsApiget_organization_exportGET/organization_exports/{organization_export_gid}Get details on an org export requestPortfolioMembershipsApiget_portfolio_membershipGET/portfolio_memberships/{portfolio_membership_gid}Get a portfolio membershipPortfolioMembershipsApiget_portfolio_membershipsGET/portfolio_membershipsGet multiple portfolio membershipsPortfolioMembershipsApiget_portfolio_memberships_for_portfolioGET/portfolios/{portfolio_gid}/portfolio_membershipsGet memberships from a portfolioPortfoliosApiadd_custom_field_setting_for_portfolioPOST/portfolios/{portfolio_gid}/addCustomFieldSettingAdd a custom field to a portfolioPortfoliosApiadd_item_for_portfolioPOST/portfolios/{portfolio_gid}/addItemAdd a portfolio itemPortfoliosApiadd_members_for_portfolioPOST/portfolios/{portfolio_gid}/addMembersAdd users to a portfolioPortfoliosApicreate_portfolioPOST/portfoliosCreate a portfolioPortfoliosApidelete_portfolioDELETE/portfolios/{portfolio_gid}Delete a portfolioPortfoliosApiget_items_for_portfolioGET/portfolios/{portfolio_gid}/itemsGet portfolio itemsPortfoliosApiget_portfolioGET/portfolios/{portfolio_gid}Get a portfolioPortfoliosApiget_portfoliosGET/portfoliosGet multiple portfoliosPortfoliosApiremove_custom_field_setting_for_portfolioPOST/portfolios/{portfolio_gid}/removeCustomFieldSettingRemove a custom field from a portfolioPortfoliosApiremove_item_for_portfolioPOST/portfolios/{portfolio_gid}/removeItemRemove a portfolio itemPortfoliosApiremove_members_for_portfolioPOST/portfolios/{portfolio_gid}/removeMembersRemove users from a portfolioPortfoliosApiupdate_portfolioPUT/portfolios/{portfolio_gid}Update a portfolioProjectBriefsApicreate_project_briefPOST/projects/{project_gid}/project_briefsCreate a project briefProjectBriefsApidelete_project_briefDELETE/project_briefs/{project_brief_gid}Delete a project briefProjectBriefsApiget_project_briefGET/project_briefs/{project_brief_gid}Get a project briefProjectBriefsApiupdate_project_briefPUT/project_briefs/{project_brief_gid}Update a project briefProjectMembershipsApiget_project_membershipGET/project_memberships/{project_membership_gid}Get a project membershipProjectMembershipsApiget_project_memberships_for_projectGET/projects/{project_gid}/project_membershipsGet memberships from a projectProjectStatusesApicreate_project_status_for_projectPOST/projects/{project_gid}/project_statusesCreate a project statusProjectStatusesApidelete_project_statusDELETE/project_statuses/{project_status_gid}Delete a project statusProjectStatusesApiget_project_statusGET/project_statuses/{project_status_gid}Get a project statusProjectStatusesApiget_project_statuses_for_projectGET/projects/{project_gid}/project_statusesGet statuses from a projectProjectTemplatesApidelete_project_templateDELETE/project_templates/{project_template_gid}Delete a project templateProjectTemplatesApiget_project_templateGET/project_templates/{project_template_gid}Get a project templateProjectTemplatesApiget_project_templatesGET/project_templatesGet multiple project templatesProjectTemplatesApiget_project_templates_for_teamGET/teams/{team_gid}/project_templatesGet a team's project templatesProjectTemplatesApiinstantiate_projectPOST/project_templates/{project_template_gid}/instantiateProjectInstantiate a project from a project templateProjectsApiadd_custom_field_setting_for_projectPOST/projects/{project_gid}/addCustomFieldSettingAdd a custom field to a projectProjectsApiadd_followers_for_projectPOST/projects/{project_gid}/addFollowersAdd followers to a projectProjectsApiadd_members_for_projectPOST/projects/{project_gid}/addMembersAdd users to a projectProjectsApicreate_projectPOST/projectsCreate a projectProjectsApicreate_project_for_teamPOST/teams/{team_gid}/projectsCreate a project in a teamProjectsApicreate_project_for_workspacePOST/workspaces/{workspace_gid}/projectsCreate a project in a workspaceProjectsApidelete_projectDELETE/projects/{project_gid}Delete a projectProjectsApiduplicate_projectPOST/projects/{project_gid}/duplicateDuplicate a projectProjectsApiget_projectGET/projects/{project_gid}Get a projectProjectsApiget_projectsGET/projectsGet multiple projectsProjectsApiget_projects_for_taskGET/tasks/{task_gid}/projectsGet projects a task is inProjectsApiget_projects_for_teamGET/teams/{team_gid}/projectsGet a team's projectsProjectsApiget_projects_for_workspaceGET/workspaces/{workspace_gid}/projectsGet all projects in a workspaceProjectsApiget_task_counts_for_projectGET/projects/{project_gid}/task_countsGet task count of a projectProjectsApiproject_save_as_templatePOST/projects/{project_gid}/saveAsTemplateCreate a project template from a projectProjectsApiremove_custom_field_setting_for_projectPOST/projects/{project_gid}/removeCustomFieldSettingRemove a custom field from a projectProjectsApiremove_followers_for_projectPOST/projects/{project_gid}/removeFollowersRemove followers from a projectProjectsApiremove_members_for_projectPOST/projects/{project_gid}/removeMembersRemove users from a projectProjectsApiupdate_projectPUT/projects/{project_gid}Update a projectRulesApitrigger_rulePOST/rule_triggers/{rule_trigger_gid}/runTrigger a ruleSectionsApiadd_task_for_sectionPOST/sections/{section_gid}/addTaskAdd task to sectionSectionsApicreate_section_for_projectPOST/projects/{project_gid}/sectionsCreate a section in a projectSectionsApidelete_sectionDELETE/sections/{section_gid}Delete a sectionSectionsApiget_sectionGET/sections/{section_gid}Get a sectionSectionsApiget_sections_for_projectGET/projects/{project_gid}/sectionsGet sections in a projectSectionsApiinsert_section_for_projectPOST/projects/{project_gid}/sections/insertMove or Insert sectionsSectionsApiupdate_sectionPUT/sections/{section_gid}Update a sectionStatusUpdatesApicreate_status_for_objectPOST/status_updatesCreate a status updateStatusUpdatesApidelete_statusDELETE/status_updates/{status_update_gid}Delete a status updateStatusUpdatesApiget_statusGET/status_updates/{status_update_gid}Get a status updateStatusUpdatesApiget_statuses_for_objectGET/status_updatesGet status updates from an objectStoriesApicreate_story_for_taskPOST/tasks/{task_gid}/storiesCreate a story on a taskStoriesApidelete_storyDELETE/stories/{story_gid}Delete a storyStoriesApiget_stories_for_taskGET/tasks/{task_gid}/storiesGet stories from a taskStoriesApiget_storyGET/stories/{story_gid}Get a storyStoriesApiupdate_storyPUT/stories/{story_gid}Update a storyTagsApicreate_tagPOST/tagsCreate a tagTagsApicreate_tag_for_workspacePOST/workspaces/{workspace_gid}/tagsCreate a tag in a workspaceTagsApidelete_tagDELETE/tags/{tag_gid}Delete a tagTagsApiget_tagGET/tags/{tag_gid}Get a tagTagsApiget_tagsGET/tagsGet multiple tagsTagsApiget_tags_for_taskGET/tasks/{task_gid}/tagsGet a task's tagsTagsApiget_tags_for_workspaceGET/workspaces/{workspace_gid}/tagsGet tags in a workspaceTagsApiupdate_tagPUT/tags/{tag_gid}Update a tagTaskTemplatesApiget_task_templateGET/task_templates/{task_template_gid}Get a task templateTaskTemplatesApiget_task_templatesGET/task_templatesGet multiple task templatesTaskTemplatesApiinstantiate_taskPOST/task_templates/{task_template_gid}/instantiateTaskInstantiate a task from a task templateTasksApiadd_dependencies_for_taskPOST/tasks/{task_gid}/addDependenciesSet dependencies for a taskTasksApiadd_dependents_for_taskPOST/tasks/{task_gid}/addDependentsSet dependents for a taskTasksApiadd_followers_for_taskPOST/tasks/{task_gid}/addFollowersAdd followers to a taskTasksApiadd_project_for_taskPOST/tasks/{task_gid}/addProjectAdd a project to a taskTasksApiadd_tag_for_taskPOST/tasks/{task_gid}/addTagAdd a tag to a taskTasksApicreate_subtask_for_taskPOST/tasks/{task_gid}/subtasksCreate a subtaskTasksApicreate_taskPOST/tasksCreate a taskTasksApidelete_taskDELETE/tasks/{task_gid}Delete a taskTasksApiduplicate_taskPOST/tasks/{task_gid}/duplicateDuplicate a taskTasksApiget_dependencies_for_taskGET/tasks/{task_gid}/dependenciesGet dependencies from a taskTasksApiget_dependents_for_taskGET/tasks/{task_gid}/dependentsGet dependents from a taskTasksApiget_subtasks_for_taskGET/tasks/{task_gid}/subtasksGet subtasks from a taskTasksApiget_taskGET/tasks/{task_gid}Get a taskTasksApiget_tasksGET/tasksGet multiple tasksTasksApiget_tasks_for_projectGET/projects/{project_gid}/tasksGet tasks from a projectTasksApiget_tasks_for_sectionGET/sections/{section_gid}/tasksGet tasks from a sectionTasksApiget_tasks_for_tagGET/tags/{tag_gid}/tasksGet tasks from a tagTasksApiget_tasks_for_user_task_listGET/user_task_lists/{user_task_list_gid}/tasksGet tasks from a user task listTasksApiremove_dependencies_for_taskPOST/tasks/{task_gid}/removeDependenciesUnlink dependencies from a taskTasksApiremove_dependents_for_taskPOST/tasks/{task_gid}/removeDependentsUnlink dependents from a taskTasksApiremove_follower_for_taskPOST/tasks/{task_gid}/removeFollowersRemove followers from a taskTasksApiremove_project_for_taskPOST/tasks/{task_gid}/removeProjectRemove a project from a taskTasksApiremove_tag_for_taskPOST/tasks/{task_gid}/removeTagRemove a tag from a taskTasksApisearch_tasks_for_workspaceGET/workspaces/{workspace_gid}/tasks/searchSearch tasks in a workspaceTasksApiset_parent_for_taskPOST/tasks/{task_gid}/setParentSet the parent of a taskTasksApiupdate_taskPUT/tasks/{task_gid}Update a taskTeamMembershipsApiget_team_membershipGET/team_memberships/{team_membership_gid}Get a team membershipTeamMembershipsApiget_team_membershipsGET/team_membershipsGet team membershipsTeamMembershipsApiget_team_memberships_for_teamGET/teams/{team_gid}/team_membershipsGet memberships from a teamTeamMembershipsApiget_team_memberships_for_userGET/users/{user_gid}/team_membershipsGet memberships from a userTeamsApiadd_user_for_teamPOST/teams/{team_gid}/addUserAdd a user to a teamTeamsApicreate_teamPOST/teamsCreate a teamTeamsApiget_teamGET/teams/{team_gid}Get a teamTeamsApiget_teams_for_userGET/users/{user_gid}/teamsGet teams for a userTeamsApiget_teams_for_workspaceGET/workspaces/{workspace_gid}/teamsGet teams in a workspaceTeamsApiremove_user_for_teamPOST/teams/{team_gid}/removeUserRemove a user from a teamTeamsApiupdate_teamPUT/teams/{team_gid}Update a teamTimePeriodsApiget_time_periodGET/time_periods/{time_period_gid}Get a time periodTimePeriodsApiget_time_periodsGET/time_periodsGet time periodsTimeTrackingEntriesApicreate_time_tracking_entryPOST/tasks/{task_gid}/time_tracking_entriesCreate a time tracking entryTimeTrackingEntriesApidelete_time_tracking_entryDELETE/time_tracking_entries/{time_tracking_entry_gid}Delete a time tracking entryTimeTrackingEntriesApiget_time_tracking_entries_for_taskGET/tasks/{task_gid}/time_tracking_entriesGet time tracking entries for a taskTimeTrackingEntriesApiget_time_tracking_entryGET/time_tracking_entries/{time_tracking_entry_gid}Get a time tracking entryTimeTrackingEntriesApiupdate_time_tracking_entryPUT/time_tracking_entries/{time_tracking_entry_gid}Update a time tracking entryTypeaheadApitypeahead_for_workspaceGET/workspaces/{workspace_gid}/typeaheadGet objects via typeaheadUserTaskListsApiget_user_task_listGET/user_task_lists/{user_task_list_gid}Get a user task listUserTaskListsApiget_user_task_list_for_userGET/users/{user_gid}/user_task_listGet a user's task listUsersApiget_favorites_for_userGET/users/{user_gid}/favoritesGet a user's favoritesUsersApiget_userGET/users/{user_gid}Get a userUsersApiget_usersGET/usersGet multiple usersUsersApiget_users_for_teamGET/teams/{team_gid}/usersGet users in a teamUsersApiget_users_for_workspaceGET/workspaces/{workspace_gid}/usersGet users in a workspace or organizationWebhooksApicreate_webhookPOST/webhooksEstablish a webhookWebhooksApidelete_webhookDELETE/webhooks/{webhook_gid}Delete a webhookWebhooksApiget_webhookGET/webhooks/{webhook_gid}Get a webhookWebhooksApiget_webhooksGET/webhooksGet multiple webhooksWebhooksApiupdate_webhookPUT/webhooks/{webhook_gid}Update a webhookWorkspaceMembershipsApiget_workspace_membershipGET/workspace_memberships/{workspace_membership_gid}Get a workspace membershipWorkspaceMembershipsApiget_workspace_memberships_for_userGET/users/{user_gid}/workspace_membershipsGet workspace memberships for a userWorkspaceMembershipsApiget_workspace_memberships_for_workspaceGET/workspaces/{workspace_gid}/workspace_membershipsGet the workspace memberships for a workspaceWorkspacesApiadd_user_for_workspacePOST/workspaces/{workspace_gid}/addUserAdd a user to a workspace or organizationWorkspacesApiget_workspaceGET/workspaces/{workspace_gid}Get a workspaceWorkspacesApiget_workspacesGET/workspacesGet multiple workspacesWorkspacesApiremove_user_for_workspacePOST/workspaces/{workspace_gid}/removeUserRemove a user from a workspace or organizationWorkspacesApiupdate_workspacePUT/workspaces/{workspace_gid}Update a workspaceAccessing repsonse dataExample: Accessing task data...try:task=tasks_api_instance.get_task(task_gid,opts)task_name=task['name']task_notes=task['notes']exceptApiExceptionase:...Accessing response status code and headersIn the scenario you want to access the response headers or the status code along with the response data you can
provide the_return_http_data_onlyparameter argument in the request method and set the value toFalseimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classusers_api_instance=asana_preview.UsersApi(api_client)user_gid='me'# str | A string identifying a user. This can either be the string \"me\", an email, or the gid of a user.opts={}try:# Get a user - Add asana-enable in the request(api_response,status,headers)=users_api_instance.get_user(user_gid,opts,_return_http_data_only=False)# returns a tuple: (response, status, headers)pprint(api_response)pprint(status)pprint(headers)exceptApiExceptionase:print("Exception when calling UsersApi->get_user:%s\n"%e)Adding deprecation flag: "asana-enable" or "asana-disable" headerOn the clientimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# Add asana-enable header for the clientapi_client.default_headers['asana-enable']='string_ids'OROn the requestimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)# create an instance of the API classusers_api_instance=asana_preview.UsersApi(api_client)user_gid='me'# str | A string identifying a user. This can either be the string \"me\", an email, or the gid of a user.opts={}try:# Get a user - Add asana-enable in the requestapi_response=users_api_instance.get_user(user_gid,opts,header_params={'asana-enable':'string_ids'})pprint(api_response)exceptApiExceptionase:print("Exception when calling UsersApi->get_user:%s\n"%e)Async requests with multithreadingThis client library uses multithreading to make async requests. To make async requests you can pass inasync_req=Truein the method call.NOTE:This feature disables our auto-pagination featureYou will want to add logic to handle the Asana API rate limitsThe code belows is an example of how to make 15 async create task calls. It does not handle the Asana API rate limits.
You will have to implement your own solution for API rate limits based on your tier.importasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)tasks_api_instance=asana_preview.TasksApi(api_client)threads=[]foriinrange(1,15+1):body={"data":{"name":f"Task:{i}","projects":["<YOUR_PROJECT_GID>"]}}opts={}threads.append(tasks_api_instance.create_task(body,opts,async_req=True))forthreadinthreads:try:pprint(thread.get())exceptApiExceptionase:print("Exception when calling TasksApi->create_task:%s\n"%e)PaginationThe pagination feature is enabled by default. This means two things:1: Endpoints that return a single response (EX:get_task(Get a task),get_project(Get a project), etc...)
will return a response with the"data"key abstracted from the response.Instead of returning:{"data":{"gid":"123","actual_time_minutes":null,"assignee":null,..."workspace":{"gid":"1234567","name":"user@example.com","resource_type":"workspace"}}}It returns:{"gid":"123","actual_time_minutes":null,"assignee":null,..."workspace":{"gid":"1234567","name":"user@example.com","resource_type":"workspace"}}2: Endpoints that return an array of resources (EX:get_tasks(Get multiple tasks),get_projects(Get multiple projects), etc...)
will return a generator object (PageIterator.items) that you can use to iterate through each result.Example usage 1:importasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)tasks_api_instance=asana_preview.TasksApi(api_client)opts={"project":"<YOUR_PROJECT_GID>"}try:tasks=tasks_api_instance.get_tasks(opts)fortaskintasks:pprint(task)exceptExceptionase:print("Exception when calling TasksApi->get_tasks:%s\n"%e)Example response:{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},...Example usage 2:importasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)tasks_api_instance=asana_preview.TasksApi(api_client)opts={"project":"<YOUR_PROJECT_GID>"}try:tasks=tasks_api_instance.get_tasks(opts)pprint(list(tasks))exceptExceptionase:print("Exception when calling TasksApi->get_tasks:%s\n"%e)Example response:[{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},...]Ending pagination earlyIn the scenario where you want to end the pagination early, you can specify anitem_limitin the method call. This will stop the iterator from going past that limit.Example Scenario:You have 1000 tasks in a project and are only interested in the first 2 tasks. Instead of letting the pagination code continue to run to get all those 1000 tasks you can specify that you only want the first X results withitem_limit.Withoutitem_limit- The for loop will continue to run until it runs out of tasks:...tasks=tasks_api_instance.get_tasks(opts)fortaskintasks:pprint(task)...Sample response:{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},...<1000th_TASK>Withitem_limit- the for loop will stop at theitem_limityou specified:...tasks=tasks_api_instance.get_tasks(opts,item_limit=2)fortaskintasks:pprint(task)...Sample response:{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},{'gid':'456','name':'Task 2','resource_subtype':'default_task','resource_type':'task'}Alternatively, if you are iterating over the generator object in a for loop, you can also just break out of the loop.EX:...opts={'project':"<YOUR_PROJECT_GID>"}try:count=0tasks=tasks_api_instance.get_tasks(opts)fortaskintasks:ifcount==2:breakpprint(task)count+=1...Sample response:{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},{'gid':'456','name':'Task 2','resource_subtype':'default_task','resource_type':'task'}Disabling default pagination behaviourIf you do not want to use the default pagination behaviour there are two ways to disbale it.1: Per request - Disable pagination behavior for a single request - pass infull_payload=Truein the method requestimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)tasks_api_instance=asana_preview.TasksApi(api_client)opts={"project":"<YOUR_PROJECT>","limit":2}try:tasks=tasks_api_instance.get_tasks(opts,full_payload=True)pprint(tasks)exceptExceptionase:print("Exception when calling TasksApi->get_tasks:%s\n"%e)Sample response:{'data':[{'gid':'123','name':'Task 1','resource_subtype':'default_task','resource_type':'task'},{'gid':'456','name':'Task 2','resource_subtype':'default_task','resource_type':'task'}],'next_page':{'offset':'eyJ0...','path':'/tasks?project=789&limit=2&offset=eyJ0...','uri':'https://app.asana.com/api/1.0/tasks?project=789&limit=2&offset=eyJ0...'}}2: Globally - Disable pagination behavior for all requests - Setreturn_page_iteratorto False...configuration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'configuration.return_page_iterator=Falseapi_client=asana_preview.ApiClient(configuration)...Documentation for Using thecall_apimethodUse this to make HTTP calls when the endpoint does not exist in the current library version or has bugsExample: GET, POST, PUT, DELETE on tasksGET - get a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)try:# GET - get a taskapi_response=api_client.call_api("/tasks/{task_gid}","GET",path_params={"task_gid":"<YOUR_TASK_GID>"},query_params={},header_params={"Accept":"application/json; charset=utf-8"},body=None,post_params=[],files={},response_type=object,# You can specify one of the following types: float, bool, bytes, str, objectauth_settings=["token"],async_req=None,_return_http_data_only=True,_preload_content=True,_request_timeout=None,collection_formats={},)pprint(api_response)exceptApiExceptionase:print("Exception:%s\n"%e)GET - get multiple tasks -> with opt_fieldsimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)try:# GET - get multiple tasksapi_response=api_client.call_api("/tasks","GET",path_params={},query_params={"project":"<YOUR_PROJECT_GID>","opt_fields":"name,notes,projects",},header_params={"Accept":"application/json; charset=utf-8"},body=None,post_params=[],files={},response_type=object,# You can specify one of the following types: float, bool, bytes, str, objectauth_settings=["token"],async_req=None,_return_http_data_only=True,_preload_content=True,_request_timeout=None,collection_formats={},)pprint(api_response)exceptApiExceptionase:print("Exception:%s\n"%e)POST - create a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)try:# POST - create a taskapi_response=api_client.call_api("/tasks","POST",path_params={},query_params={},header_params={"Accept":"application/json; charset=utf-8","Content-Type":"application/json; charset=utf-8",},body={"data":{"name":"New Task","projects":["<YOUR_PROJECT_GID>"],}},post_params=[],files={},response_type=object,# You can specify one of the following types: float, bool, bytes, str, objectauth_settings=["token"],async_req=None,_return_http_data_only=True,_preload_content=True,_request_timeout=None,collection_formats={},)pprint(api_response)exceptApiExceptionase:print("Exception:%s\n"%e)PUT - update a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)try:# PUT - update a taskapi_response=api_client.call_api("/tasks/{task_gid}","PUT",path_params={"task_gid":"<YOUR_TASK_GID>"},query_params={},header_params={"Accept":"application/json; charset=utf-8","Content-Type":"application/json; charset=utf-8",},body={"data":{"name":"Updated Task",}},post_params=[],files={},response_type=object,# You can specify one of the following types: float, bool, bytes, str, objectauth_settings=["token"],async_req=None,_return_http_data_only=True,_preload_content=True,_request_timeout=None,collection_formats={},)pprint(api_response)exceptApiExceptionase:print("Exception:%s\n"%e)DELETE - delete a taskimportasana_previewfromasana_preview.restimportApiExceptionfrompprintimportpprintconfiguration=asana_preview.Configuration()configuration.access_token='<YOUR_ACCESS_TOKEN>'api_client=asana_preview.ApiClient(configuration)try:# DELETE - delete a taskapi_response=api_client.call_api("/tasks/{task_gid}","DELETE",path_params={"task_gid":"<YOUR_TASK_GID>"},query_params={},header_params={"Accept":"application/json; charset=utf-8"},body=None,post_params=[],files={},response_type=object,# You can specify one of the following types: float, bool, bytes, str, objectauth_settings=["token"],async_req=None,_return_http_data_only=True,_preload_content=True,_request_timeout=None,collection_formats={},)pprint(api_response)exceptApiExceptionase:print("Exception:%s\n"%e)