Skip to main content

Asana

Project description

asana_preview GitHub release PyPi Version

This is a preview version of Asana's new python client library. For feedback and feature requests, please leave a comment on this forum thread or through the feedback form on our documentation site

  • API version: 1.0
  • Package version: 1.0.28

Requirements.

Python 3.4+

Installation & Usage

pip install from PyPI

pip install asana-preview

Then import the package:

import asana_preview 

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_preview

Getting Started

Please follow the installation procedure and then run the following:

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

try:
    # Get a user
    api_response = users_api_instance.get_user(user_gid, opts)
    pprint(api_response)
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_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

POST - create a task

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

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

PUT - update a task

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

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

DELETE - delete a task

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

try:
    # Delete a task
    api_response = tasks_api_instance.delete_task(task_gid)
    pprint(api_response)
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

Class Method HTTP request Description
AttachmentsApi create_attachment_for_object POST /attachments Upload an attachment
AttachmentsApi delete_attachment DELETE /attachments/{attachment_gid} Delete an attachment
AttachmentsApi get_attachment GET /attachments/{attachment_gid} Get an attachment
AttachmentsApi get_attachments_for_object GET /attachments Get attachments from an object
AuditLogAPIApi get_audit_log_events GET /workspaces/{workspace_gid}/audit_log_events Get audit log events
BatchAPIApi create_batch_request POST /batch Submit parallel requests
CustomFieldSettingsApi get_custom_field_settings_for_portfolio GET /portfolios/{portfolio_gid}/custom_field_settings Get a portfolio's custom fields
CustomFieldSettingsApi get_custom_field_settings_for_project GET /projects/{project_gid}/custom_field_settings Get a project's custom fields
CustomFieldsApi create_custom_field POST /custom_fields Create a custom field
CustomFieldsApi create_enum_option_for_custom_field POST /custom_fields/{custom_field_gid}/enum_options Create an enum option
CustomFieldsApi delete_custom_field DELETE /custom_fields/{custom_field_gid} Delete a custom field
CustomFieldsApi get_custom_field GET /custom_fields/{custom_field_gid} Get a custom field
CustomFieldsApi get_custom_fields_for_workspace GET /workspaces/{workspace_gid}/custom_fields Get a workspace's custom fields
CustomFieldsApi insert_enum_option_for_custom_field POST /custom_fields/{custom_field_gid}/enum_options/insert Reorder a custom field's enum
CustomFieldsApi update_custom_field PUT /custom_fields/{custom_field_gid} Update a custom field
CustomFieldsApi update_enum_option PUT /enum_options/{enum_option_gid} Update an enum option
EventsApi get_events GET /events Get events on a resource
GoalRelationshipsApi add_supporting_relationship POST /goals/{goal_gid}/addSupportingRelationship Add a supporting goal relationship
GoalRelationshipsApi get_goal_relationship GET /goal_relationships/{goal_relationship_gid} Get a goal relationship
GoalRelationshipsApi get_goal_relationships GET /goal_relationships Get goal relationships
GoalRelationshipsApi remove_supporting_relationship POST /goals/{goal_gid}/removeSupportingRelationship Removes a supporting goal relationship
GoalRelationshipsApi update_goal_relationship PUT /goal_relationships/{goal_relationship_gid} Update a goal relationship
GoalsApi add_followers POST /goals/{goal_gid}/addFollowers Add a collaborator to a goal
GoalsApi create_goal POST /goals Create a goal
GoalsApi create_goal_metric POST /goals/{goal_gid}/setMetric Create a goal metric
GoalsApi delete_goal DELETE /goals/{goal_gid} Delete a goal
GoalsApi get_goal GET /goals/{goal_gid} Get a goal
GoalsApi get_goals GET /goals Get goals
GoalsApi get_parent_goals_for_goal GET /goals/{goal_gid}/parentGoals Get parent goals from a goal
GoalsApi remove_followers POST /goals/{goal_gid}/removeFollowers Remove a collaborator from a goal
GoalsApi update_goal PUT /goals/{goal_gid} Update a goal
GoalsApi update_goal_metric POST /goals/{goal_gid}/setMetricCurrentValue Update a goal metric
JobsApi get_job GET /jobs/{job_gid} Get a job by id
MembershipsApi create_membership POST /memberships Create a membership
MembershipsApi delete_membership DELETE /memberships/{membership_gid} Delete a membership
MembershipsApi get_membership GET /memberships/{membership_gid} Get a membership
MembershipsApi get_memberships GET /memberships Get multiple memberships
OrganizationExportsApi create_organization_export POST /organization_exports Create an organization export request
OrganizationExportsApi get_organization_export GET /organization_exports/{organization_export_gid} Get details on an org export request
PortfolioMembershipsApi get_portfolio_membership GET /portfolio_memberships/{portfolio_membership_gid} Get a portfolio membership
PortfolioMembershipsApi get_portfolio_memberships GET /portfolio_memberships Get multiple portfolio memberships
PortfolioMembershipsApi get_portfolio_memberships_for_portfolio GET /portfolios/{portfolio_gid}/portfolio_memberships Get memberships from a portfolio
PortfoliosApi add_custom_field_setting_for_portfolio POST /portfolios/{portfolio_gid}/addCustomFieldSetting Add a custom field to a portfolio
PortfoliosApi add_item_for_portfolio POST /portfolios/{portfolio_gid}/addItem Add a portfolio item
PortfoliosApi add_members_for_portfolio POST /portfolios/{portfolio_gid}/addMembers Add users to a portfolio
PortfoliosApi create_portfolio POST /portfolios Create a portfolio
PortfoliosApi delete_portfolio DELETE /portfolios/{portfolio_gid} Delete a portfolio
PortfoliosApi get_items_for_portfolio GET /portfolios/{portfolio_gid}/items Get portfolio items
PortfoliosApi get_portfolio GET /portfolios/{portfolio_gid} Get a portfolio
PortfoliosApi get_portfolios GET /portfolios Get multiple portfolios
PortfoliosApi remove_custom_field_setting_for_portfolio POST /portfolios/{portfolio_gid}/removeCustomFieldSetting Remove a custom field from a portfolio
PortfoliosApi remove_item_for_portfolio POST /portfolios/{portfolio_gid}/removeItem Remove a portfolio item
PortfoliosApi remove_members_for_portfolio POST /portfolios/{portfolio_gid}/removeMembers Remove users from a portfolio
PortfoliosApi update_portfolio PUT /portfolios/{portfolio_gid} Update a portfolio
ProjectBriefsApi create_project_brief POST /projects/{project_gid}/project_briefs Create a project brief
ProjectBriefsApi delete_project_brief DELETE /project_briefs/{project_brief_gid} Delete a project brief
ProjectBriefsApi get_project_brief GET /project_briefs/{project_brief_gid} Get a project brief
ProjectBriefsApi update_project_brief PUT /project_briefs/{project_brief_gid} Update a project brief
ProjectMembershipsApi get_project_membership GET /project_memberships/{project_membership_gid} Get a project membership
ProjectMembershipsApi get_project_memberships_for_project GET /projects/{project_gid}/project_memberships Get memberships from a project
ProjectStatusesApi create_project_status_for_project POST /projects/{project_gid}/project_statuses Create a project status
ProjectStatusesApi delete_project_status DELETE /project_statuses/{project_status_gid} Delete a project status
ProjectStatusesApi get_project_status GET /project_statuses/{project_status_gid} Get a project status
ProjectStatusesApi get_project_statuses_for_project GET /projects/{project_gid}/project_statuses Get statuses from a project
ProjectTemplatesApi delete_project_template DELETE /project_templates/{project_template_gid} Delete a project template
ProjectTemplatesApi get_project_template GET /project_templates/{project_template_gid} Get a project template
ProjectTemplatesApi get_project_templates GET /project_templates Get multiple project templates
ProjectTemplatesApi get_project_templates_for_team GET /teams/{team_gid}/project_templates Get a team's project templates
ProjectTemplatesApi instantiate_project POST /project_templates/{project_template_gid}/instantiateProject Instantiate a project from a project template
ProjectsApi add_custom_field_setting_for_project POST /projects/{project_gid}/addCustomFieldSetting Add a custom field to a project
ProjectsApi add_followers_for_project POST /projects/{project_gid}/addFollowers Add followers to a project
ProjectsApi add_members_for_project POST /projects/{project_gid}/addMembers Add users to a project
ProjectsApi create_project POST /projects Create a project
ProjectsApi create_project_for_team POST /teams/{team_gid}/projects Create a project in a team
ProjectsApi create_project_for_workspace POST /workspaces/{workspace_gid}/projects Create a project in a workspace
ProjectsApi delete_project DELETE /projects/{project_gid} Delete a project
ProjectsApi duplicate_project POST /projects/{project_gid}/duplicate Duplicate a project
ProjectsApi get_project GET /projects/{project_gid} Get a project
ProjectsApi get_projects GET /projects Get multiple projects
ProjectsApi get_projects_for_task GET /tasks/{task_gid}/projects Get projects a task is in
ProjectsApi get_projects_for_team GET /teams/{team_gid}/projects Get a team's projects
ProjectsApi get_projects_for_workspace GET /workspaces/{workspace_gid}/projects Get all projects in a workspace
ProjectsApi get_task_counts_for_project GET /projects/{project_gid}/task_counts Get task count of a project
ProjectsApi project_save_as_template POST /projects/{project_gid}/saveAsTemplate Create a project template from a project
ProjectsApi remove_custom_field_setting_for_project POST /projects/{project_gid}/removeCustomFieldSetting Remove a custom field from a project
ProjectsApi remove_followers_for_project POST /projects/{project_gid}/removeFollowers Remove followers from a project
ProjectsApi remove_members_for_project POST /projects/{project_gid}/removeMembers Remove users from a project
ProjectsApi update_project PUT /projects/{project_gid} Update a project
RulesApi trigger_rule POST /rule_triggers/{rule_trigger_gid}/run Trigger a rule
SectionsApi add_task_for_section POST /sections/{section_gid}/addTask Add task to section
SectionsApi create_section_for_project POST /projects/{project_gid}/sections Create a section in a project
SectionsApi delete_section DELETE /sections/{section_gid} Delete a section
SectionsApi get_section GET /sections/{section_gid} Get a section
SectionsApi get_sections_for_project GET /projects/{project_gid}/sections Get sections in a project
SectionsApi insert_section_for_project POST /projects/{project_gid}/sections/insert Move or Insert sections
SectionsApi update_section PUT /sections/{section_gid} Update a section
StatusUpdatesApi create_status_for_object POST /status_updates Create a status update
StatusUpdatesApi delete_status DELETE /status_updates/{status_update_gid} Delete a status update
StatusUpdatesApi get_status GET /status_updates/{status_update_gid} Get a status update
StatusUpdatesApi get_statuses_for_object GET /status_updates Get status updates from an object
StoriesApi create_story_for_task POST /tasks/{task_gid}/stories Create a story on a task
StoriesApi delete_story DELETE /stories/{story_gid} Delete a story
StoriesApi get_stories_for_task GET /tasks/{task_gid}/stories Get stories from a task
StoriesApi get_story GET /stories/{story_gid} Get a story
StoriesApi update_story PUT /stories/{story_gid} Update a story
TagsApi create_tag POST /tags Create a tag
TagsApi create_tag_for_workspace POST /workspaces/{workspace_gid}/tags Create a tag in a workspace
TagsApi delete_tag DELETE /tags/{tag_gid} Delete a tag
TagsApi get_tag GET /tags/{tag_gid} Get a tag
TagsApi get_tags GET /tags Get multiple tags
TagsApi get_tags_for_task GET /tasks/{task_gid}/tags Get a task's tags
TagsApi get_tags_for_workspace GET /workspaces/{workspace_gid}/tags Get tags in a workspace
TagsApi update_tag PUT /tags/{tag_gid} Update a tag
TaskTemplatesApi get_task_template GET /task_templates/{task_template_gid} Get a task template
TaskTemplatesApi get_task_templates GET /task_templates Get multiple task templates
TaskTemplatesApi instantiate_task POST /task_templates/{task_template_gid}/instantiateTask Instantiate a task from a task template
TasksApi add_dependencies_for_task POST /tasks/{task_gid}/addDependencies Set dependencies for a task
TasksApi add_dependents_for_task POST /tasks/{task_gid}/addDependents Set dependents for a task
TasksApi add_followers_for_task POST /tasks/{task_gid}/addFollowers Add followers to a task
TasksApi add_project_for_task POST /tasks/{task_gid}/addProject Add a project to a task
TasksApi add_tag_for_task POST /tasks/{task_gid}/addTag Add a tag to a task
TasksApi create_subtask_for_task POST /tasks/{task_gid}/subtasks Create a subtask
TasksApi create_task POST /tasks Create a task
TasksApi delete_task DELETE /tasks/{task_gid} Delete a task
TasksApi duplicate_task POST /tasks/{task_gid}/duplicate Duplicate a task
TasksApi get_dependencies_for_task GET /tasks/{task_gid}/dependencies Get dependencies from a task
TasksApi get_dependents_for_task GET /tasks/{task_gid}/dependents Get dependents from a task
TasksApi get_subtasks_for_task GET /tasks/{task_gid}/subtasks Get subtasks from a task
TasksApi get_task GET /tasks/{task_gid} Get a task
TasksApi get_tasks GET /tasks Get multiple tasks
TasksApi get_tasks_for_project GET /projects/{project_gid}/tasks Get tasks from a project
TasksApi get_tasks_for_section GET /sections/{section_gid}/tasks Get tasks from a section
TasksApi get_tasks_for_tag GET /tags/{tag_gid}/tasks Get tasks from a tag
TasksApi get_tasks_for_user_task_list GET /user_task_lists/{user_task_list_gid}/tasks Get tasks from a user task list
TasksApi remove_dependencies_for_task POST /tasks/{task_gid}/removeDependencies Unlink dependencies from a task
TasksApi remove_dependents_for_task POST /tasks/{task_gid}/removeDependents Unlink dependents from a task
TasksApi remove_follower_for_task POST /tasks/{task_gid}/removeFollowers Remove followers from a task
TasksApi remove_project_for_task POST /tasks/{task_gid}/removeProject Remove a project from a task
TasksApi remove_tag_for_task POST /tasks/{task_gid}/removeTag Remove a tag from a task
TasksApi search_tasks_for_workspace GET /workspaces/{workspace_gid}/tasks/search Search tasks in a workspace
TasksApi set_parent_for_task POST /tasks/{task_gid}/setParent Set the parent of a task
TasksApi update_task PUT /tasks/{task_gid} Update a task
TeamMembershipsApi get_team_membership GET /team_memberships/{team_membership_gid} Get a team membership
TeamMembershipsApi get_team_memberships GET /team_memberships Get team memberships
TeamMembershipsApi get_team_memberships_for_team GET /teams/{team_gid}/team_memberships Get memberships from a team
TeamMembershipsApi get_team_memberships_for_user GET /users/{user_gid}/team_memberships Get memberships from a user
TeamsApi add_user_for_team POST /teams/{team_gid}/addUser Add a user to a team
TeamsApi create_team POST /teams Create a team
TeamsApi get_team GET /teams/{team_gid} Get a team
TeamsApi get_teams_for_user GET /users/{user_gid}/teams Get teams for a user
TeamsApi get_teams_for_workspace GET /workspaces/{workspace_gid}/teams Get teams in a workspace
TeamsApi remove_user_for_team POST /teams/{team_gid}/removeUser Remove a user from a team
TeamsApi update_team PUT /teams/{team_gid} Update a team
TimePeriodsApi get_time_period GET /time_periods/{time_period_gid} Get a time period
TimePeriodsApi get_time_periods GET /time_periods Get time periods
TimeTrackingEntriesApi create_time_tracking_entry POST /tasks/{task_gid}/time_tracking_entries Create a time tracking entry
TimeTrackingEntriesApi delete_time_tracking_entry DELETE /time_tracking_entries/{time_tracking_entry_gid} Delete a time tracking entry
TimeTrackingEntriesApi get_time_tracking_entries_for_task GET /tasks/{task_gid}/time_tracking_entries Get time tracking entries for a task
TimeTrackingEntriesApi get_time_tracking_entry GET /time_tracking_entries/{time_tracking_entry_gid} Get a time tracking entry
TimeTrackingEntriesApi update_time_tracking_entry PUT /time_tracking_entries/{time_tracking_entry_gid} Update a time tracking entry
TypeaheadApi typeahead_for_workspace GET /workspaces/{workspace_gid}/typeahead Get objects via typeahead
UserTaskListsApi get_user_task_list GET /user_task_lists/{user_task_list_gid} Get a user task list
UserTaskListsApi get_user_task_list_for_user GET /users/{user_gid}/user_task_list Get a user's task list
UsersApi get_favorites_for_user GET /users/{user_gid}/favorites Get a user's favorites
UsersApi get_user GET /users/{user_gid} Get a user
UsersApi get_users GET /users Get multiple users
UsersApi get_users_for_team GET /teams/{team_gid}/users Get users in a team
UsersApi get_users_for_workspace GET /workspaces/{workspace_gid}/users Get users in a workspace or organization
WebhooksApi create_webhook POST /webhooks Establish a webhook
WebhooksApi delete_webhook DELETE /webhooks/{webhook_gid} Delete a webhook
WebhooksApi get_webhook GET /webhooks/{webhook_gid} Get a webhook
WebhooksApi get_webhooks GET /webhooks Get multiple webhooks
WebhooksApi update_webhook PUT /webhooks/{webhook_gid} Update a webhook
WorkspaceMembershipsApi get_workspace_membership GET /workspace_memberships/{workspace_membership_gid} Get a workspace membership
WorkspaceMembershipsApi get_workspace_memberships_for_user GET /users/{user_gid}/workspace_memberships Get workspace memberships for a user
WorkspaceMembershipsApi get_workspace_memberships_for_workspace GET /workspaces/{workspace_gid}/workspace_memberships Get the workspace memberships for a workspace
WorkspacesApi add_user_for_workspace POST /workspaces/{workspace_gid}/addUser Add a user to a workspace or organization
WorkspacesApi get_workspace GET /workspaces/{workspace_gid} Get a workspace
WorkspacesApi get_workspaces GET /workspaces Get multiple workspaces
WorkspacesApi remove_user_for_workspace POST /workspaces/{workspace_gid}/removeUser Remove a user from a workspace or organization
WorkspacesApi update_workspace PUT /workspaces/{workspace_gid} Update a workspace

Accessing repsonse data

Example: Accessing task data

.
.
.
try:
    task = tasks_api_instance.get_task(task_gid)
    task_data = task['data']
    task_name = task_dict_data['name']
    task_notes = task_dict_data['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_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

# create an instance of the API class
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.

try:
    # Get a user - Add asana-enable in the request
    api_response = api_instance.get_user(user_gid, _return_http_data_only=False) # returns a tuple: (object, status, headers)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)

Adding deprecation flag to your "asana-enable" header

On the client

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

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

OR

On the request

import asana_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

# create an instance of the API class
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.

try:
    # Get a user - Add asana-enable in the request
    api_response = api_instance.get_user(user_gid, header_params={'asana-enable': 'string_ids'})
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)

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_preview
from asana_preview.rest import ApiException
from pprint import pprint

configuration = asana_preview.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana_preview.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_preview
from asana_preview.rest import ApiException
from pprint import pprint

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

try:
    # GET - get multiple tasks
    api_response = api_client.call_api(
        "/tasks",
        "GET",
        path_params={},
        query_params=[('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_preview
from asana_preview.rest import ApiException
from pprint import pprint

configuration = asana_preview.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana_preview.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_preview
from asana_preview.rest import ApiException
from pprint import pprint

configuration = asana_preview.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana_preview.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_preview
from asana_preview.rest import ApiException
from pprint import pprint

configuration = asana_preview.Configuration()
configuration.access_token = '<YOUR_ACCESS_TOKEN>'
api_client = asana_preview.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)

Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asana_preview-1.0.28.tar.gz (85.5 kB view details)

Uploaded Source

Built Distribution

asana_preview-1.0.28-py3-none-any.whl (154.1 kB view details)

Uploaded Python 3

File details

Details for the file asana_preview-1.0.28.tar.gz.

File metadata

  • Download URL: asana_preview-1.0.28.tar.gz
  • Upload date:
  • Size: 85.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for asana_preview-1.0.28.tar.gz
Algorithm Hash digest
SHA256 1f3efb8e0da6b6f435d640576dfe64730440b609f78eda631e265c8433f3a9e8
MD5 86fdb6bd21c0881929ea3c82ed61c9d0
BLAKE2b-256 fd08105aa8ab763e000bc0610fb075ab7f393bd8adb184544d0013a7ad33dd0d

See more details on using hashes here.

File details

Details for the file asana_preview-1.0.28-py3-none-any.whl.

File metadata

File hashes

Hashes for asana_preview-1.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0a561e22274aef08108b2bfcc124202765262285108de62d8e5d9b10960a4c
MD5 84b630b98489baec9ff8a86a3a0bafa9
BLAKE2b-256 a713a5d92dc5eac3614602266cc44f59f7f546521834f692afc3eaa38aee0e5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page