Oven logo

Oven

asana5.0.10

Published

Asana

pip install asana

Package Downloads

Weekly DownloadsMonthly Downloads

Authors

Project URLs

Requires Python

asana GitHub release PyPi Version

  • API version: 1.0
  • Package version: 5.0.10

Requirements.

Python 3.4+

Installation & Usage

pip install from PyPI

pip install asana

Then import the package:

import asana 

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import asana

Getting Started

Please follow the installation procedure and then run the following:

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
users_api_instance = asana.UsersApi(api_client)
user_gid = "me"
opts = {}

try:
    # Get a user
    user = users_api_instance.get_user(user_gid, opts)
    pprint(user)
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)

Example: GET, POST, PUT, DELETE on tasks

GET - get multiple tasks

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.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 tasks
    tasks = tasks_api_instance.get_tasks(opts)
    for task in tasks:
        pprint(task)
except ApiException as e:
    print("Exception when calling TasksApi->get_tasks: %s\n" % e)

POST - create a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
body = {
    "data": {
        "name": "New Task",
        "projects": ["<YOUR_PROJECT_GID>"],
    }
}
opts = {}

try:
    # Create a task
    task = tasks_api_instance.create_task(body, opts)
    pprint(task)
except ApiException as e:
    print("Exception when calling TasksApi->create_task: %s\n" % e)

PUT - update a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
body = {
    "data": {
        "name": "Updated Task",
    }
}
task_gid = "<YOUR_TASK_GID>"
opts = {}

try:
    # Update a task
    task = tasks_api_instance.update_task(body, task_gid, opts)
    pprint(task)
except ApiException as e:
    print("Exception when calling TasksApi->update_task: %s\n" % e)

DELETE - delete a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
task_gid = "<YOUR_TASK_GID>"

try:
    # Delete a task
    task = tasks_api_instance.delete_task(task_gid)
    pprint(task)
except ApiException as e:
    print("Exception when calling TasksApi->delete_task: %s\n" % e)

Documentation for API Endpoints

All URIs are relative to https://app.asana.com/api/1.0

ClassMethodHTTP requestDescription
AllocationsApicreate_allocationPOST /allocationsCreate an allocation
AllocationsApidelete_allocationDELETE /allocations/{allocation_gid}Delete an allocation
AllocationsApiget_allocationGET /allocations/{allocation_gid}Get an allocation
AllocationsApiget_allocationsGET /allocationsGet multiple allocations
AllocationsApiupdate_allocationPUT /allocations/{allocation_gid}Update an allocation
AttachmentsApicreate_attachment_for_objectPOST /attachmentsUpload an attachment
AttachmentsApidelete_attachmentDELETE /attachments/{attachment_gid}Delete an attachment
AttachmentsApiget_attachmentGET /attachments/{attachment_gid}Get an attachment
AttachmentsApiget_attachments_for_objectGET /attachmentsGet attachments from an object
AuditLogAPIApiget_audit_log_eventsGET /workspaces/{workspace_gid}/audit_log_eventsGet audit log events
BatchAPIApicreate_batch_requestPOST /batchSubmit parallel requests
CustomFieldSettingsApiget_custom_field_settings_for_portfolioGET /portfolios/{portfolio_gid}/custom_field_settingsGet a portfolio's custom fields
CustomFieldSettingsApiget_custom_field_settings_for_projectGET /projects/{project_gid}/custom_field_settingsGet a project's custom fields
CustomFieldsApicreate_custom_fieldPOST /custom_fieldsCreate a custom field
CustomFieldsApicreate_enum_option_for_custom_fieldPOST /custom_fields/{custom_field_gid}/enum_optionsCreate an enum option
CustomFieldsApidelete_custom_fieldDELETE /custom_fields/{custom_field_gid}Delete a custom field
CustomFieldsApiget_custom_fieldGET /custom_fields/{custom_field_gid}Get a custom field
CustomFieldsApiget_custom_fields_for_workspaceGET /workspaces/{workspace_gid}/custom_fieldsGet a workspace's custom fields
CustomFieldsApiinsert_enum_option_for_custom_fieldPOST /custom_fields/{custom_field_gid}/enum_options/insertReorder a custom field's enum
CustomFieldsApiupdate_custom_fieldPUT /custom_fields/{custom_field_gid}Update a custom field
CustomFieldsApiupdate_enum_optionPUT /enum_options/{enum_option_gid}Update an enum option
EventsApiget_eventsGET /eventsGet events on a resource
GoalRelationshipsApiadd_supporting_relationshipPOST /goals/{goal_gid}/addSupportingRelationshipAdd a supporting goal relationship
GoalRelationshipsApiget_goal_relationshipGET /goal_relationships/{goal_relationship_gid}Get a goal relationship
GoalRelationshipsApiget_goal_relationshipsGET /goal_relationshipsGet goal relationships
GoalRelationshipsApiremove_supporting_relationshipPOST /goals/{goal_gid}/removeSupportingRelationshipRemoves a supporting goal relationship
GoalRelationshipsApiupdate_goal_relationshipPUT /goal_relationships/{goal_relationship_gid}Update a goal relationship
GoalsApiadd_followersPOST /goals/{goal_gid}/addFollowersAdd a collaborator to a goal
GoalsApicreate_goalPOST /goalsCreate a goal
GoalsApicreate_goal_metricPOST /goals/{goal_gid}/setMetricCreate a goal metric
GoalsApidelete_goalDELETE /goals/{goal_gid}Delete a goal
GoalsApiget_goalGET /goals/{goal_gid}Get a goal
GoalsApiget_goalsGET /goalsGet goals
GoalsApiget_parent_goals_for_goalGET /goals/{goal_gid}/parentGoalsGet parent goals from a goal
GoalsApiremove_followersPOST /goals/{goal_gid}/removeFollowersRemove a collaborator from a goal
GoalsApiupdate_goalPUT /goals/{goal_gid}Update a goal
GoalsApiupdate_goal_metricPOST /goals/{goal_gid}/setMetricCurrentValueUpdate a goal metric
JobsApiget_jobGET /jobs/{job_gid}Get a job by id
MembershipsApicreate_membershipPOST /membershipsCreate a membership
MembershipsApidelete_membershipDELETE /memberships/{membership_gid}Delete a membership
MembershipsApiget_membershipGET /memberships/{membership_gid}Get a membership
MembershipsApiget_membershipsGET /membershipsGet multiple memberships
MembershipsApiupdate_membershipPUT /memberships/{membership_gid}Update a membership
OrganizationExportsApicreate_organization_exportPOST /organization_exportsCreate an organization export request
OrganizationExportsApiget_organization_exportGET /organization_exports/{organization_export_gid}Get details on an org export request
PortfolioMembershipsApiget_portfolio_membershipGET /portfolio_memberships/{portfolio_membership_gid}Get a portfolio membership
PortfolioMembershipsApiget_portfolio_membershipsGET /portfolio_membershipsGet multiple portfolio memberships
PortfolioMembershipsApiget_portfolio_memberships_for_portfolioGET /portfolios/{portfolio_gid}/portfolio_membershipsGet memberships from a portfolio
PortfoliosApiadd_custom_field_setting_for_portfolioPOST /portfolios/{portfolio_gid}/addCustomFieldSettingAdd a custom field to a portfolio
PortfoliosApiadd_item_for_portfolioPOST /portfolios/{portfolio_gid}/addItemAdd a portfolio item
PortfoliosApiadd_members_for_portfolioPOST /portfolios/{portfolio_gid}/addMembersAdd users to a portfolio
PortfoliosApicreate_portfolioPOST /portfoliosCreate a portfolio
PortfoliosApidelete_portfolioDELETE /portfolios/{portfolio_gid}Delete a portfolio
PortfoliosApiget_items_for_portfolioGET /portfolios/{portfolio_gid}/itemsGet portfolio items
PortfoliosApiget_portfolioGET /portfolios/{portfolio_gid}Get a portfolio
PortfoliosApiget_portfoliosGET /portfoliosGet multiple portfolios
PortfoliosApiremove_custom_field_setting_for_portfolioPOST /portfolios/{portfolio_gid}/removeCustomFieldSettingRemove a custom field from a portfolio
PortfoliosApiremove_item_for_portfolioPOST /portfolios/{portfolio_gid}/removeItemRemove a portfolio item
PortfoliosApiremove_members_for_portfolioPOST /portfolios/{portfolio_gid}/removeMembersRemove users from a portfolio
PortfoliosApiupdate_portfolioPUT /portfolios/{portfolio_gid}Update a portfolio
ProjectBriefsApicreate_project_briefPOST /projects/{project_gid}/project_briefsCreate a project brief
ProjectBriefsApidelete_project_briefDELETE /project_briefs/{project_brief_gid}Delete a project brief
ProjectBriefsApiget_project_briefGET /project_briefs/{project_brief_gid}Get a project brief
ProjectBriefsApiupdate_project_briefPUT /project_briefs/{project_brief_gid}Update a project brief
ProjectMembershipsApiget_project_membershipGET /project_memberships/{project_membership_gid}Get a project membership
ProjectMembershipsApiget_project_memberships_for_projectGET /projects/{project_gid}/project_membershipsGet memberships from a project
ProjectStatusesApicreate_project_status_for_projectPOST /projects/{project_gid}/project_statusesCreate a project status
ProjectStatusesApidelete_project_statusDELETE /project_statuses/{project_status_gid}Delete a project status
ProjectStatusesApiget_project_statusGET /project_statuses/{project_status_gid}Get a project status
ProjectStatusesApiget_project_statuses_for_projectGET /projects/{project_gid}/project_statusesGet statuses from a project
ProjectTemplatesApidelete_project_templateDELETE /project_templates/{project_template_gid}Delete a project template
ProjectTemplatesApiget_project_templateGET /project_templates/{project_template_gid}Get a project template
ProjectTemplatesApiget_project_templatesGET /project_templatesGet multiple project templates
ProjectTemplatesApiget_project_templates_for_teamGET /teams/{team_gid}/project_templatesGet a team's project templates
ProjectTemplatesApiinstantiate_projectPOST /project_templates/{project_template_gid}/instantiateProjectInstantiate a project from a project template
ProjectsApiadd_custom_field_setting_for_projectPOST /projects/{project_gid}/addCustomFieldSettingAdd a custom field to a project
ProjectsApiadd_followers_for_projectPOST /projects/{project_gid}/addFollowersAdd followers to a project
ProjectsApiadd_members_for_projectPOST /projects/{project_gid}/addMembersAdd users to a project
ProjectsApicreate_projectPOST /projectsCreate a project
ProjectsApicreate_project_for_teamPOST /teams/{team_gid}/projectsCreate a project in a team
ProjectsApicreate_project_for_workspacePOST /workspaces/{workspace_gid}/projectsCreate a project in a workspace
ProjectsApidelete_projectDELETE /projects/{project_gid}Delete a project
ProjectsApiduplicate_projectPOST /projects/{project_gid}/duplicateDuplicate a project
ProjectsApiget_projectGET /projects/{project_gid}Get a project
ProjectsApiget_projectsGET /projectsGet multiple projects
ProjectsApiget_projects_for_taskGET /tasks/{task_gid}/projectsGet projects a task is in
ProjectsApiget_projects_for_teamGET /teams/{team_gid}/projectsGet a team's projects
ProjectsApiget_projects_for_workspaceGET /workspaces/{workspace_gid}/projectsGet all projects in a workspace
ProjectsApiget_task_counts_for_projectGET /projects/{project_gid}/task_countsGet task count of a project
ProjectsApiproject_save_as_templatePOST /projects/{project_gid}/saveAsTemplateCreate a project template from a project
ProjectsApiremove_custom_field_setting_for_projectPOST /projects/{project_gid}/removeCustomFieldSettingRemove a custom field from a project
ProjectsApiremove_followers_for_projectPOST /projects/{project_gid}/removeFollowersRemove followers from a project
ProjectsApiremove_members_for_projectPOST /projects/{project_gid}/removeMembersRemove users from a project
ProjectsApiupdate_projectPUT /projects/{project_gid}Update a project
RulesApitrigger_rulePOST /rule_triggers/{rule_trigger_gid}/runTrigger a rule
SectionsApiadd_task_for_sectionPOST /sections/{section_gid}/addTaskAdd task to section
SectionsApicreate_section_for_projectPOST /projects/{project_gid}/sectionsCreate a section in a project
SectionsApidelete_sectionDELETE /sections/{section_gid}Delete a section
SectionsApiget_sectionGET /sections/{section_gid}Get a section
SectionsApiget_sections_for_projectGET /projects/{project_gid}/sectionsGet sections in a project
SectionsApiinsert_section_for_projectPOST /projects/{project_gid}/sections/insertMove or Insert sections
SectionsApiupdate_sectionPUT /sections/{section_gid}Update a section
StatusUpdatesApicreate_status_for_objectPOST /status_updatesCreate a status update
StatusUpdatesApidelete_statusDELETE /status_updates/{status_update_gid}Delete a status update
StatusUpdatesApiget_statusGET /status_updates/{status_update_gid}Get a status update
StatusUpdatesApiget_statuses_for_objectGET /status_updatesGet status updates from an object
StoriesApicreate_story_for_taskPOST /tasks/{task_gid}/storiesCreate a story on a task
StoriesApidelete_storyDELETE /stories/{story_gid}Delete a story
StoriesApiget_stories_for_taskGET /tasks/{task_gid}/storiesGet stories from a task
StoriesApiget_storyGET /stories/{story_gid}Get a story
StoriesApiupdate_storyPUT /stories/{story_gid}Update a story
TagsApicreate_tagPOST /tagsCreate a tag
TagsApicreate_tag_for_workspacePOST /workspaces/{workspace_gid}/tagsCreate a tag in a workspace
TagsApidelete_tagDELETE /tags/{tag_gid}Delete a tag
TagsApiget_tagGET /tags/{tag_gid}Get a tag
TagsApiget_tagsGET /tagsGet multiple tags
TagsApiget_tags_for_taskGET /tasks/{task_gid}/tagsGet a task's tags
TagsApiget_tags_for_workspaceGET /workspaces/{workspace_gid}/tagsGet tags in a workspace
TagsApiupdate_tagPUT /tags/{tag_gid}Update a tag
TaskTemplatesApidelete_task_templateDELETE /task_templates/{task_template_gid}Delete a task template
TaskTemplatesApiget_task_templateGET /task_templates/{task_template_gid}Get a task template
TaskTemplatesApiget_task_templatesGET /task_templatesGet multiple task templates
TaskTemplatesApiinstantiate_taskPOST /task_templates/{task_template_gid}/instantiateTaskInstantiate a task from a task template
TasksApiadd_dependencies_for_taskPOST /tasks/{task_gid}/addDependenciesSet dependencies for a task
TasksApiadd_dependents_for_taskPOST /tasks/{task_gid}/addDependentsSet dependents for a task
TasksApiadd_followers_for_taskPOST /tasks/{task_gid}/addFollowersAdd followers to a task
TasksApiadd_project_for_taskPOST /tasks/{task_gid}/addProjectAdd a project to a task
TasksApiadd_tag_for_taskPOST /tasks/{task_gid}/addTagAdd a tag to a task
TasksApicreate_subtask_for_taskPOST /tasks/{task_gid}/subtasksCreate a subtask
TasksApicreate_taskPOST /tasksCreate a task
TasksApidelete_taskDELETE /tasks/{task_gid}Delete a task
TasksApiduplicate_taskPOST /tasks/{task_gid}/duplicateDuplicate a task
TasksApiget_dependencies_for_taskGET /tasks/{task_gid}/dependenciesGet dependencies from a task
TasksApiget_dependents_for_taskGET /tasks/{task_gid}/dependentsGet dependents from a task
TasksApiget_subtasks_for_taskGET /tasks/{task_gid}/subtasksGet subtasks from a task
TasksApiget_taskGET /tasks/{task_gid}Get a task
TasksApiget_task_for_custom_idGET /workspaces/{workspace_gid}/tasks/custom_id/{custom_id}Get a task for a given custom ID
TasksApiget_tasksGET /tasksGet multiple tasks
TasksApiget_tasks_for_projectGET /projects/{project_gid}/tasksGet tasks from a project
TasksApiget_tasks_for_sectionGET /sections/{section_gid}/tasksGet tasks from a section
TasksApiget_tasks_for_tagGET /tags/{tag_gid}/tasksGet tasks from a tag
TasksApiget_tasks_for_user_task_listGET /user_task_lists/{user_task_list_gid}/tasksGet tasks from a user task list
TasksApiremove_dependencies_for_taskPOST /tasks/{task_gid}/removeDependenciesUnlink dependencies from a task
TasksApiremove_dependents_for_taskPOST /tasks/{task_gid}/removeDependentsUnlink dependents from a task
TasksApiremove_follower_for_taskPOST /tasks/{task_gid}/removeFollowersRemove followers from a task
TasksApiremove_project_for_taskPOST /tasks/{task_gid}/removeProjectRemove a project from a task
TasksApiremove_tag_for_taskPOST /tasks/{task_gid}/removeTagRemove a tag from a task
TasksApisearch_tasks_for_workspaceGET /workspaces/{workspace_gid}/tasks/searchSearch tasks in a workspace
TasksApiset_parent_for_taskPOST /tasks/{task_gid}/setParentSet the parent of a task
TasksApiupdate_taskPUT /tasks/{task_gid}Update a task
TeamMembershipsApiget_team_membershipGET /team_memberships/{team_membership_gid}Get a team membership
TeamMembershipsApiget_team_membershipsGET /team_membershipsGet team memberships
TeamMembershipsApiget_team_memberships_for_teamGET /teams/{team_gid}/team_membershipsGet memberships from a team
TeamMembershipsApiget_team_memberships_for_userGET /users/{user_gid}/team_membershipsGet memberships from a user
TeamsApiadd_user_for_teamPOST /teams/{team_gid}/addUserAdd a user to a team
TeamsApicreate_teamPOST /teamsCreate a team
TeamsApiget_teamGET /teams/{team_gid}Get a team
TeamsApiget_teams_for_userGET /users/{user_gid}/teamsGet teams for a user
TeamsApiget_teams_for_workspaceGET /workspaces/{workspace_gid}/teamsGet teams in a workspace
TeamsApiremove_user_for_teamPOST /teams/{team_gid}/removeUserRemove a user from a team
TeamsApiupdate_teamPUT /teams/{team_gid}Update a team
TimePeriodsApiget_time_periodGET /time_periods/{time_period_gid}Get a time period
TimePeriodsApiget_time_periodsGET /time_periodsGet time periods
TimeTrackingEntriesApicreate_time_tracking_entryPOST /tasks/{task_gid}/time_tracking_entriesCreate a time tracking entry
TimeTrackingEntriesApidelete_time_tracking_entryDELETE /time_tracking_entries/{time_tracking_entry_gid}Delete a time tracking entry
TimeTrackingEntriesApiget_time_tracking_entries_for_taskGET /tasks/{task_gid}/time_tracking_entriesGet time tracking entries for a task
TimeTrackingEntriesApiget_time_tracking_entryGET /time_tracking_entries/{time_tracking_entry_gid}Get a time tracking entry
TimeTrackingEntriesApiupdate_time_tracking_entryPUT /time_tracking_entries/{time_tracking_entry_gid}Update a time tracking entry
TypeaheadApitypeahead_for_workspaceGET /workspaces/{workspace_gid}/typeaheadGet objects via typeahead
UserTaskListsApiget_user_task_listGET /user_task_lists/{user_task_list_gid}Get a user task list
UserTaskListsApiget_user_task_list_for_userGET /users/{user_gid}/user_task_listGet a user's task list
UsersApiget_favorites_for_userGET /users/{user_gid}/favoritesGet a user's favorites
UsersApiget_userGET /users/{user_gid}Get a user
UsersApiget_usersGET /usersGet multiple users
UsersApiget_users_for_teamGET /teams/{team_gid}/usersGet users in a team
UsersApiget_users_for_workspaceGET /workspaces/{workspace_gid}/usersGet users in a workspace or organization
WebhooksApicreate_webhookPOST /webhooksEstablish a webhook
WebhooksApidelete_webhookDELETE /webhooks/{webhook_gid}Delete a webhook
WebhooksApiget_webhookGET /webhooks/{webhook_gid}Get a webhook
WebhooksApiget_webhooksGET /webhooksGet multiple webhooks
WebhooksApiupdate_webhookPUT /webhooks/{webhook_gid}Update a webhook
WorkspaceMembershipsApiget_workspace_membershipGET /workspace_memberships/{workspace_membership_gid}Get a workspace membership
WorkspaceMembershipsApiget_workspace_memberships_for_userGET /users/{user_gid}/workspace_membershipsGet workspace memberships for a user
WorkspaceMembershipsApiget_workspace_memberships_for_workspaceGET /workspaces/{workspace_gid}/workspace_membershipsGet the workspace memberships for a workspace
WorkspacesApiadd_user_for_workspacePOST /workspaces/{workspace_gid}/addUserAdd a user to a workspace or organization
WorkspacesApiget_workspaceGET /workspaces/{workspace_gid}Get a workspace
WorkspacesApiget_workspacesGET /workspacesGet multiple workspaces
WorkspacesApiremove_user_for_workspacePOST /workspaces/{workspace_gid}/removeUserRemove a user from a workspace or organization
WorkspacesApiupdate_workspacePUT /workspaces/{workspace_gid}Update a workspace

Accessing response data

Example: Accessing task data

.
.
.
try:
    task = tasks_api_instance.get_task(task_gid, opts)
    task_name = task['name']
    task_notes = task['notes']
except ApiException as e:
    .
    .
    .

Accessing response status code and headers

In 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_only parameter argument in the request method and set the value to False

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
users_api_instance = asana.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)
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)

Adding deprecation flag: "asana-enable" or "asana-disable" header

On the client

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# Add asana-enable header for the client
api_client.default_headers['asana-enable'] = 'string_ids'

OR

On the request

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

# create an instance of the API class
users_api_instance = asana.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 = users_api_instance.get_user(user_gid, opts, header_params={'asana-enable': 'string_ids'})
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)

Async requests with multithreading

This client library uses multithreading to make async requests. To make async requests you can pass in async_req=True in the method call.

NOTE:

  • This feature disables our auto-pagination feature
  • You will want to add logic to handle the Asana API rate limits

The 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.

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

tasks_api_instance = asana.TasksApi(api_client)
threads = []
for i in range(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))

for thread in threads:
    try:
        pprint(thread.get())
    except ApiException as e:
        print("Exception when calling TasksApi->create_task: %s\n" % e)

Pagination

The 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": "[email protected]",
            "resource_type": "workspace"
        }
    }
}

It returns:

{
    "gid": "123",
    "actual_time_minutes": null,
    "assignee": null,
    ...
    "workspace": {
        "gid": "1234567",
        "name": "[email protected]",
        "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:

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

tasks_api_instance = asana.TasksApi(api_client)
opts = {"project": "<YOUR_PROJECT_GID>"}

try:
    tasks = tasks_api_instance.get_tasks(opts)
    for task in tasks:
        pprint(task)

except Exception as e:
    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:

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

tasks_api_instance = asana.TasksApi(api_client)
opts = {"project": "<YOUR_PROJECT_GID>"}

try:
    tasks = tasks_api_instance.get_tasks(opts)
    pprint(list(tasks))

except Exception as e:
    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 early

In the scenario where you want to end the pagination early, you can specify an item_limit in 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 with item_limit.

Without item_limit - The for loop will continue to run until it runs out of tasks:

    ...
    tasks = tasks_api_instance.get_tasks(opts)
    for task in tasks:
        pprint(task)
    ...

Sample response:

{'gid': '123',
 'name': 'Task 1',
 'resource_subtype': 'default_task',
 'resource_type': 'task'},
 .
 .
 .
 <1000th_TASK>

With item_limit - the for loop will stop at the item_limit you specified:

    ...
    tasks = tasks_api_instance.get_tasks(opts, item_limit=2)
    for task in tasks:
        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 = 0
    tasks = tasks_api_instance.get_tasks(opts)
    for task in tasks:
        if count == 2:
            break
        pprint(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 behaviour

If 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 in full_payload=True in the method request

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

tasks_api_instance = asana.TasksApi(api_client)
opts = {"project": "<YOUR_PROJECT>", "limit": 2}

try:
    tasks = tasks_api_instance.get_tasks(opts, full_payload=True)
    pprint(tasks)
except Exception as e:
    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 - Set return_page_iterator to False

...
configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
configuration.return_page_iterator = False
api_client = asana.ApiClient(configuration)
...

Documentation for Using the call_api method

Use this to make HTTP calls when the endpoint does not exist in the current library version or has bugs

Example: GET, POST, PUT, DELETE on tasks

GET - get a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_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={},
        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, object
        auth_settings=["token"],
        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)

GET - get multiple tasks -> with opt_fields

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

try:
    # GET - get multiple tasks
    api_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, object
        auth_settings=["token"],
        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)

POST - create a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

try:
    # POST - create a task
    api_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, object
        auth_settings=["token"],
        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)

PUT - update a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

try:
    # PUT - update a task
    api_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, object
        auth_settings=["token"],
        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)

DELETE - delete a task

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

configuration = asana.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)

try:
    # DELETE - delete a task
    api_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, object
        auth_settings=["token"],
        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)