Socket
Socket
Sign inDemoInstall

asana

Package Overview
Dependencies
118
Maintainers
3
Versions
87
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    asana

This_is_the_interface_for_interacting_with_the__Asana_Platform_httpsdevelopers_asana_com__Our_API_reference_is_generated_from_our__OpenAPI_spec__httpsraw_githubusercontent_comAsanaopenapimasterdefsasana_oas_yaml_


Version published
Weekly downloads
94K
decreased by-3.62%
Maintainers
3
Install size
10.9 MB
Created
Weekly downloads
 

Readme

Source

asana GitHub release Build Status NPM Version

JavaScript client library for Asana.

  • API version: 1.0
  • Package version: 2.0.6

Installation

For Node.js

npm install from npm
npm install asana --save

For browser

Include the latest release directly from GitHub:

<script src="https://github.com/Asana/node-asana/releases/download/v2.0.6/asana-min.js"></script>

Example usage:

<script>
    const defaultClient = Asana.ApiClient.instance;
    const oauth2 = defaultClient.authentications["oauth2"];
    oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

    let usersApiInstance = new Asana.UsersApi();
    let user_gid = "me";
    let opts = {};

    usersApiInstance.getUser(user_gid, opts, (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log(
            "API called successfully. Returned data: " + JSON.stringify(data, null, 2)
            );
        }
    });
</script>

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let usersApiInstance = new Asana.UsersApi()
let user_gid = "me"; // String | A string identifying a user. This can either be the string \"me\", an email, or the gid of a user.
let opts = { 
    'opt_fields': ["email","name","photo","photo.image_1024x1024","photo.image_128x128","photo.image_21x21","photo.image_27x27","photo.image_36x36","photo.image_60x60","workspaces","workspaces.name"] // [String] | Properties to include in the response. Set this query parameter to a comma-separated list of the properties you wish to include.
};

usersApiInstance.getUser(user_gid, opts, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        console.log('API called successfully. Returned data: ' + JSON.stringify(data, null, 2));
    }
});

Example: GET, POST, PUT, DELETE on tasks

GET - get multiple tasks
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let tasksApiInstance = new Asana.TasksApi()
let opts = { 
    'limit': 50, // Number | Results per page. The number of objects to return per page. The value must be between 1 and 100.
    'project': "<YOUR_PROJECT_GID>", // String | The project to filter tasks on.
    'modified_since': new Date("2012-02-22T02:06:58.158Z"), // Date | Only return tasks that have been modified since the given time.  *Note: A task is considered “modified” if any of its properties change, or associations between it and other objects are modified (e.g.  a task being added to a project). A task is not considered modified just because another object it is associated with (e.g. a subtask) is modified. Actions that count as modifying the task include assigning, renaming, completing, and adding stories.*
    '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","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.name","parent.resource_subtype","path","permalink_url","projects","projects.name","resource_subtype","start_at","start_on","tags","tags.name","uri","workspace","workspace.name"] // [String] | This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include.
};

// GET - get multiple tasks
tasksApiInstance.getTasks(opts, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        console.log('API called successfully. Returned data: ' + JSON.stringify(data, null, 2));
    }
});
POST - create a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let tasksApiInstance = new Asana.TasksApi()
let body = new Asana.TasksBody.constructFromObject({
    data: {
        name: "New Task",
        approval_status: "pending",
        assignee_status: "upcoming",
        completed: false,
        external: {
            gid: "1234",
            data: "A blob of information.",
        },
        html_notes: "<body>Mittens <em>really</em> likes the stuff from Humboldt.</body>",
        is_rendered_as_separator: false,
        liked: true,
        assignee: "me",
        projects: ["<YOUR_PROJECT_GID>"],
    },
});
let opts = {};

// POST - Create a task
tasksApiInstance.createTask(body, opts, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        console.log("API called successfully. Returned data: " + JSON.stringify(data, null, 2));
    }
});
PUT - update a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let tasksApiInstance = new Asana.TasksApi()
let task_gid = "<YOUR_TASK_GID>";
let body = new Asana.TasksTaskGidBody.constructFromObject({
    data: {
        name: "Updated Task",
    },
});
let opts = {};

// PUT - Update a task
tasksApiInstance.updateTask(body, task_gid, opts, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        console.log("API called successfully. Returned data: " + JSON.stringify(data, null, 2));
    }
});
DELETE - delete a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let tasksApiInstance = new Asana.TasksApi()
let task_gid = "<YOUR_TASK_GID>";

// DELETE - Delete a task
tasksApiInstance.deleteTask(task_gid, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        console.log("API called successfully. Returned data: " + JSON.stringify(data, null, 2));
    }
});

Documentation for API Endpoints

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

ClassMethodHTTP requestDescription
Asana.AttachmentsApicreateAttachmentForObjectPOST /attachmentsUpload an attachment
Asana.AttachmentsApideleteAttachmentDELETE /attachments/{attachment_gid}Delete an attachment
Asana.AttachmentsApigetAttachmentGET /attachments/{attachment_gid}Get an attachment
Asana.AttachmentsApigetAttachmentsForObjectGET /attachmentsGet attachments from an object
Asana.AuditLogAPIApigetAuditLogEventsGET /workspaces/{workspace_gid}/audit_log_eventsGet audit log events
Asana.BatchAPIApicreateBatchRequestPOST /batchSubmit parallel requests
Asana.CustomFieldSettingsApigetCustomFieldSettingsForPortfolioGET /portfolios/{portfolio_gid}/custom_field_settingsGet a portfolio's custom fields
Asana.CustomFieldSettingsApigetCustomFieldSettingsForProjectGET /projects/{project_gid}/custom_field_settingsGet a project's custom fields
Asana.CustomFieldsApicreateCustomFieldPOST /custom_fieldsCreate a custom field
Asana.CustomFieldsApicreateEnumOptionForCustomFieldPOST /custom_fields/{custom_field_gid}/enum_optionsCreate an enum option
Asana.CustomFieldsApideleteCustomFieldDELETE /custom_fields/{custom_field_gid}Delete a custom field
Asana.CustomFieldsApigetCustomFieldGET /custom_fields/{custom_field_gid}Get a custom field
Asana.CustomFieldsApigetCustomFieldsForWorkspaceGET /workspaces/{workspace_gid}/custom_fieldsGet a workspace's custom fields
Asana.CustomFieldsApiinsertEnumOptionForCustomFieldPOST /custom_fields/{custom_field_gid}/enum_options/insertReorder a custom field's enum
Asana.CustomFieldsApiupdateCustomFieldPUT /custom_fields/{custom_field_gid}Update a custom field
Asana.CustomFieldsApiupdateEnumOptionPUT /enum_options/{enum_option_gid}Update an enum option
Asana.EventsApigetEventsGET /eventsGet events on a resource
Asana.GoalRelationshipsApiaddSupportingRelationshipPOST /goals/{goal_gid}/addSupportingRelationshipAdd a supporting goal relationship
Asana.GoalRelationshipsApigetGoalRelationshipGET /goal_relationships/{goal_relationship_gid}Get a goal relationship
Asana.GoalRelationshipsApigetGoalRelationshipsGET /goal_relationshipsGet goal relationships
Asana.GoalRelationshipsApiremoveSupportingRelationshipPOST /goals/{goal_gid}/removeSupportingRelationshipRemoves a supporting goal relationship
Asana.GoalRelationshipsApiupdateGoalRelationshipPUT /goal_relationships/{goal_relationship_gid}Update a goal relationship
Asana.GoalsApiaddFollowersPOST /goals/{goal_gid}/addFollowersAdd a collaborator to a goal
Asana.GoalsApicreateGoalPOST /goalsCreate a goal
Asana.GoalsApicreateGoalMetricPOST /goals/{goal_gid}/setMetricCreate a goal metric
Asana.GoalsApideleteGoalDELETE /goals/{goal_gid}Delete a goal
Asana.GoalsApigetGoalGET /goals/{goal_gid}Get a goal
Asana.GoalsApigetGoalsGET /goalsGet goals
Asana.GoalsApigetParentGoalsForGoalGET /goals/{goal_gid}/parentGoalsGet parent goals from a goal
Asana.GoalsApiremoveFollowersPOST /goals/{goal_gid}/removeFollowersRemove a collaborator from a goal
Asana.GoalsApiupdateGoalPUT /goals/{goal_gid}Update a goal
Asana.GoalsApiupdateGoalMetricPOST /goals/{goal_gid}/setMetricCurrentValueUpdate a goal metric
Asana.JobsApigetJobGET /jobs/{job_gid}Get a job by id
Asana.MembershipsApicreateMembershipPOST /membershipsCreate a membership
Asana.MembershipsApideleteMembershipDELETE /memberships/{membership_gid}Delete a membership
Asana.MembershipsApigetMembershipGET /memberships/{membership_gid}Get a membership
Asana.MembershipsApigetMembershipsGET /membershipsGet multiple memberships
Asana.OrganizationExportsApicreateOrganizationExportPOST /organization_exportsCreate an organization export request
Asana.OrganizationExportsApigetOrganizationExportGET /organization_exports/{organization_export_gid}Get details on an org export request
Asana.PortfolioMembershipsApigetPortfolioMembershipGET /portfolio_memberships/{portfolio_membership_gid}Get a portfolio membership
Asana.PortfolioMembershipsApigetPortfolioMembershipsGET /portfolio_membershipsGet multiple portfolio memberships
Asana.PortfolioMembershipsApigetPortfolioMembershipsForPortfolioGET /portfolios/{portfolio_gid}/portfolio_membershipsGet memberships from a portfolio
Asana.PortfoliosApiaddCustomFieldSettingForPortfolioPOST /portfolios/{portfolio_gid}/addCustomFieldSettingAdd a custom field to a portfolio
Asana.PortfoliosApiaddItemForPortfolioPOST /portfolios/{portfolio_gid}/addItemAdd a portfolio item
Asana.PortfoliosApiaddMembersForPortfolioPOST /portfolios/{portfolio_gid}/addMembersAdd users to a portfolio
Asana.PortfoliosApicreatePortfolioPOST /portfoliosCreate a portfolio
Asana.PortfoliosApideletePortfolioDELETE /portfolios/{portfolio_gid}Delete a portfolio
Asana.PortfoliosApigetItemsForPortfolioGET /portfolios/{portfolio_gid}/itemsGet portfolio items
Asana.PortfoliosApigetPortfolioGET /portfolios/{portfolio_gid}Get a portfolio
Asana.PortfoliosApigetPortfoliosGET /portfoliosGet multiple portfolios
Asana.PortfoliosApiremoveCustomFieldSettingForPortfolioPOST /portfolios/{portfolio_gid}/removeCustomFieldSettingRemove a custom field from a portfolio
Asana.PortfoliosApiremoveItemForPortfolioPOST /portfolios/{portfolio_gid}/removeItemRemove a portfolio item
Asana.PortfoliosApiremoveMembersForPortfolioPOST /portfolios/{portfolio_gid}/removeMembersRemove users from a portfolio
Asana.PortfoliosApiupdatePortfolioPUT /portfolios/{portfolio_gid}Update a portfolio
Asana.ProjectBriefsApicreateProjectBriefPOST /projects/{project_gid}/project_briefsCreate a project brief
Asana.ProjectBriefsApideleteProjectBriefDELETE /project_briefs/{project_brief_gid}Delete a project brief
Asana.ProjectBriefsApigetProjectBriefGET /project_briefs/{project_brief_gid}Get a project brief
Asana.ProjectBriefsApiupdateProjectBriefPUT /project_briefs/{project_brief_gid}Update a project brief
Asana.ProjectMembershipsApigetProjectMembershipGET /project_memberships/{project_membership_gid}Get a project membership
Asana.ProjectMembershipsApigetProjectMembershipsForProjectGET /projects/{project_gid}/project_membershipsGet memberships from a project
Asana.ProjectStatusesApicreateProjectStatusForProjectPOST /projects/{project_gid}/project_statusesCreate a project status
Asana.ProjectStatusesApideleteProjectStatusDELETE /project_statuses/{project_status_gid}Delete a project status
Asana.ProjectStatusesApigetProjectStatusGET /project_statuses/{project_status_gid}Get a project status
Asana.ProjectStatusesApigetProjectStatusesForProjectGET /projects/{project_gid}/project_statusesGet statuses from a project
Asana.ProjectTemplatesApideleteProjectTemplateDELETE /project_templates/{project_template_gid}Delete a project template
Asana.ProjectTemplatesApigetProjectTemplateGET /project_templates/{project_template_gid}Get a project template
Asana.ProjectTemplatesApigetProjectTemplatesGET /project_templatesGet multiple project templates
Asana.ProjectTemplatesApigetProjectTemplatesForTeamGET /teams/{team_gid}/project_templatesGet a team's project templates
Asana.ProjectTemplatesApiinstantiateProjectPOST /project_templates/{project_template_gid}/instantiateProjectInstantiate a project from a project template
Asana.ProjectsApiaddCustomFieldSettingForProjectPOST /projects/{project_gid}/addCustomFieldSettingAdd a custom field to a project
Asana.ProjectsApiaddFollowersForProjectPOST /projects/{project_gid}/addFollowersAdd followers to a project
Asana.ProjectsApiaddMembersForProjectPOST /projects/{project_gid}/addMembersAdd users to a project
Asana.ProjectsApicreateProjectPOST /projectsCreate a project
Asana.ProjectsApicreateProjectForTeamPOST /teams/{team_gid}/projectsCreate a project in a team
Asana.ProjectsApicreateProjectForWorkspacePOST /workspaces/{workspace_gid}/projectsCreate a project in a workspace
Asana.ProjectsApideleteProjectDELETE /projects/{project_gid}Delete a project
Asana.ProjectsApiduplicateProjectPOST /projects/{project_gid}/duplicateDuplicate a project
Asana.ProjectsApigetProjectGET /projects/{project_gid}Get a project
Asana.ProjectsApigetProjectsGET /projectsGet multiple projects
Asana.ProjectsApigetProjectsForTaskGET /tasks/{task_gid}/projectsGet projects a task is in
Asana.ProjectsApigetProjectsForTeamGET /teams/{team_gid}/projectsGet a team's projects
Asana.ProjectsApigetProjectsForWorkspaceGET /workspaces/{workspace_gid}/projectsGet all projects in a workspace
Asana.ProjectsApigetTaskCountsForProjectGET /projects/{project_gid}/task_countsGet task count of a project
Asana.ProjectsApiprojectSaveAsTemplatePOST /projects/{project_gid}/saveAsTemplateCreate a project template from a project
Asana.ProjectsApiremoveCustomFieldSettingForProjectPOST /projects/{project_gid}/removeCustomFieldSettingRemove a custom field from a project
Asana.ProjectsApiremoveFollowersForProjectPOST /projects/{project_gid}/removeFollowersRemove followers from a project
Asana.ProjectsApiremoveMembersForProjectPOST /projects/{project_gid}/removeMembersRemove users from a project
Asana.ProjectsApiupdateProjectPUT /projects/{project_gid}Update a project
Asana.RulesApitriggerRulePOST /rule_triggers/{rule_trigger_gid}/runTrigger a rule
Asana.SectionsApiaddTaskForSectionPOST /sections/{section_gid}/addTaskAdd task to section
Asana.SectionsApicreateSectionForProjectPOST /projects/{project_gid}/sectionsCreate a section in a project
Asana.SectionsApideleteSectionDELETE /sections/{section_gid}Delete a section
Asana.SectionsApigetSectionGET /sections/{section_gid}Get a section
Asana.SectionsApigetSectionsForProjectGET /projects/{project_gid}/sectionsGet sections in a project
Asana.SectionsApiinsertSectionForProjectPOST /projects/{project_gid}/sections/insertMove or Insert sections
Asana.SectionsApiupdateSectionPUT /sections/{section_gid}Update a section
Asana.StatusUpdatesApicreateStatusForObjectPOST /status_updatesCreate a status update
Asana.StatusUpdatesApideleteStatusDELETE /status_updates/{status_update_gid}Delete a status update
Asana.StatusUpdatesApigetStatusGET /status_updates/{status_update_gid}Get a status update
Asana.StatusUpdatesApigetStatusesForObjectGET /status_updatesGet status updates from an object
Asana.StoriesApicreateStoryForTaskPOST /tasks/{task_gid}/storiesCreate a story on a task
Asana.StoriesApideleteStoryDELETE /stories/{story_gid}Delete a story
Asana.StoriesApigetStoriesForTaskGET /tasks/{task_gid}/storiesGet stories from a task
Asana.StoriesApigetStoryGET /stories/{story_gid}Get a story
Asana.StoriesApiupdateStoryPUT /stories/{story_gid}Update a story
Asana.TagsApicreateTagPOST /tagsCreate a tag
Asana.TagsApicreateTagForWorkspacePOST /workspaces/{workspace_gid}/tagsCreate a tag in a workspace
Asana.TagsApideleteTagDELETE /tags/{tag_gid}Delete a tag
Asana.TagsApigetTagGET /tags/{tag_gid}Get a tag
Asana.TagsApigetTagsGET /tagsGet multiple tags
Asana.TagsApigetTagsForTaskGET /tasks/{task_gid}/tagsGet a task's tags
Asana.TagsApigetTagsForWorkspaceGET /workspaces/{workspace_gid}/tagsGet tags in a workspace
Asana.TagsApiupdateTagPUT /tags/{tag_gid}Update a tag
Asana.TasksApiaddDependenciesForTaskPOST /tasks/{task_gid}/addDependenciesSet dependencies for a task
Asana.TasksApiaddDependentsForTaskPOST /tasks/{task_gid}/addDependentsSet dependents for a task
Asana.TasksApiaddFollowersForTaskPOST /tasks/{task_gid}/addFollowersAdd followers to a task
Asana.TasksApiaddProjectForTaskPOST /tasks/{task_gid}/addProjectAdd a project to a task
Asana.TasksApiaddTagForTaskPOST /tasks/{task_gid}/addTagAdd a tag to a task
Asana.TasksApicreateSubtaskForTaskPOST /tasks/{task_gid}/subtasksCreate a subtask
Asana.TasksApicreateTaskPOST /tasksCreate a task
Asana.TasksApideleteTaskDELETE /tasks/{task_gid}Delete a task
Asana.TasksApiduplicateTaskPOST /tasks/{task_gid}/duplicateDuplicate a task
Asana.TasksApigetDependenciesForTaskGET /tasks/{task_gid}/dependenciesGet dependencies from a task
Asana.TasksApigetDependentsForTaskGET /tasks/{task_gid}/dependentsGet dependents from a task
Asana.TasksApigetSubtasksForTaskGET /tasks/{task_gid}/subtasksGet subtasks from a task
Asana.TasksApigetTaskGET /tasks/{task_gid}Get a task
Asana.TasksApigetTasksGET /tasksGet multiple tasks
Asana.TasksApigetTasksForProjectGET /projects/{project_gid}/tasksGet tasks from a project
Asana.TasksApigetTasksForSectionGET /sections/{section_gid}/tasksGet tasks from a section
Asana.TasksApigetTasksForTagGET /tags/{tag_gid}/tasksGet tasks from a tag
Asana.TasksApigetTasksForUserTaskListGET /user_task_lists/{user_task_list_gid}/tasksGet tasks from a user task list
Asana.TasksApiremoveDependenciesForTaskPOST /tasks/{task_gid}/removeDependenciesUnlink dependencies from a task
Asana.TasksApiremoveDependentsForTaskPOST /tasks/{task_gid}/removeDependentsUnlink dependents from a task
Asana.TasksApiremoveFollowerForTaskPOST /tasks/{task_gid}/removeFollowersRemove followers from a task
Asana.TasksApiremoveProjectForTaskPOST /tasks/{task_gid}/removeProjectRemove a project from a task
Asana.TasksApiremoveTagForTaskPOST /tasks/{task_gid}/removeTagRemove a tag from a task
Asana.TasksApisearchTasksForWorkspaceGET /workspaces/{workspace_gid}/tasks/searchSearch tasks in a workspace
Asana.TasksApisetParentForTaskPOST /tasks/{task_gid}/setParentSet the parent of a task
Asana.TasksApiupdateTaskPUT /tasks/{task_gid}Update a task
Asana.TeamMembershipsApigetTeamMembershipGET /team_memberships/{team_membership_gid}Get a team membership
Asana.TeamMembershipsApigetTeamMembershipsGET /team_membershipsGet team memberships
Asana.TeamMembershipsApigetTeamMembershipsForTeamGET /teams/{team_gid}/team_membershipsGet memberships from a team
Asana.TeamMembershipsApigetTeamMembershipsForUserGET /users/{user_gid}/team_membershipsGet memberships from a user
Asana.TeamsApiaddUserForTeamPOST /teams/{team_gid}/addUserAdd a user to a team
Asana.TeamsApicreateTeamPOST /teamsCreate a team
Asana.TeamsApigetTeamGET /teams/{team_gid}Get a team
Asana.TeamsApigetTeamsForUserGET /users/{user_gid}/teamsGet teams for a user
Asana.TeamsApigetTeamsForWorkspaceGET /workspaces/{workspace_gid}/teamsGet teams in a workspace
Asana.TeamsApiremoveUserForTeamPOST /teams/{team_gid}/removeUserRemove a user from a team
Asana.TeamsApiupdateTeamPUT /teams/{team_gid}Update a team
Asana.TimePeriodsApigetTimePeriodGET /time_periods/{time_period_gid}Get a time period
Asana.TimePeriodsApigetTimePeriodsGET /time_periodsGet time periods
Asana.TimeTrackingEntriesApicreateTimeTrackingEntryPOST /tasks/{task_gid}/time_tracking_entriesCreate a time tracking entry
Asana.TimeTrackingEntriesApideleteTimeTrackingEntryDELETE /time_tracking_entries/{time_tracking_entry_gid}Delete a time tracking entry
Asana.TimeTrackingEntriesApigetTimeTrackingEntriesForTaskGET /tasks/{task_gid}/time_tracking_entriesGet time tracking entries for a task
Asana.TimeTrackingEntriesApigetTimeTrackingEntryGET /time_tracking_entries/{time_tracking_entry_gid}Get a time tracking entry
Asana.TimeTrackingEntriesApiupdateTimeTrackingEntryPUT /time_tracking_entries/{time_tracking_entry_gid}Update a time tracking entry
Asana.TypeaheadApitypeaheadForWorkspaceGET /workspaces/{workspace_gid}/typeaheadGet objects via typeahead
Asana.UserTaskListsApigetUserTaskListGET /user_task_lists/{user_task_list_gid}Get a user task list
Asana.UserTaskListsApigetUserTaskListForUserGET /users/{user_gid}/user_task_listGet a user's task list
Asana.UsersApigetFavoritesForUserGET /users/{user_gid}/favoritesGet a user's favorites
Asana.UsersApigetUserGET /users/{user_gid}Get a user
Asana.UsersApigetUsersGET /usersGet multiple users
Asana.UsersApigetUsersForTeamGET /teams/{team_gid}/usersGet users in a team
Asana.UsersApigetUsersForWorkspaceGET /workspaces/{workspace_gid}/usersGet users in a workspace or organization
Asana.WebhooksApicreateWebhookPOST /webhooksEstablish a webhook
Asana.WebhooksApideleteWebhookDELETE /webhooks/{webhook_gid}Delete a webhook
Asana.WebhooksApigetWebhookGET /webhooks/{webhook_gid}Get a webhook
Asana.WebhooksApigetWebhooksGET /webhooksGet multiple webhooks
Asana.WebhooksApiupdateWebhookPUT /webhooks/{webhook_gid}Update a webhook
Asana.WorkspaceMembershipsApigetWorkspaceMembershipGET /workspace_memberships/{workspace_membership_gid}Get a workspace membership
Asana.WorkspaceMembershipsApigetWorkspaceMembershipsForUserGET /users/{user_gid}/workspace_membershipsGet workspace memberships for a user
Asana.WorkspaceMembershipsApigetWorkspaceMembershipsForWorkspaceGET /workspaces/{workspace_gid}/workspace_membershipsGet the workspace memberships for a workspace
Asana.WorkspacesApiaddUserForWorkspacePOST /workspaces/{workspace_gid}/addUserAdd a user to a workspace or organization
Asana.WorkspacesApigetWorkspaceGET /workspaces/{workspace_gid}Get a workspace
Asana.WorkspacesApigetWorkspacesGET /workspacesGet multiple workspaces
Asana.WorkspacesApiremoveUserForWorkspacePOST /workspaces/{workspace_gid}/removeUserRemove a user from a workspace or organization
Asana.WorkspacesApiupdateWorkspacePUT /workspaces/{workspace_gid}Update a workspace

Documentation for Models

Documentation for Authorization

oauth2

  • Type: OAuth
  • Flow: accessCode
  • Authorization URL: https://app.asana.com/-/oauth_authorize
  • Scopes:
    • default: Provides access to all endpoints documented in our API reference. If no scopes are requested, this scope is assumed by default.
    • openid: Provides access to OpenID Connect ID tokens and the OpenID Connect user info endpoint.
    • email: Provides access to the user’s email through the OpenID Connect user info endpoint.
    • profile: Provides access to the user’s name and profile photo through the OpenID Connect user info endpoint.

Getting events

In order to get events you will need a sync token. This sync token can be acquired in the error message from the initial request to getEvents.

const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let eventsApiInstance = new Asana.EventsApi();
let resource = "12345"; // String | A resource ID to subscribe to. The resource can be a task or project.
let opts = {
    sync: ''
};

// Initial request to get the sync token
eventsApiInstance.getEvents(resource, opts, (error, data, response) => {
    // Set the sync token
    opts['sync'] = JSON.parse(response.text)['sync']
    // Follow up request to get events
    eventsApiInstance.getEvents(resource, opts, (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log('API called successfully. Returned data: ' + JSON.stringify(data, null, 2));
        }
    });
});

Accessing repsonse data

By default, the client library returns a class object of the resource. You can use dot notation to access the response data.

TIP: look at the "Return type" section of the documented endpoint to understand which properties are accessible. (EX: get_task)

.
.
.
tasksApiInstance.getTask(task_gid, opts, (error, task, response) => {
    if (error) {
        console.error(error);
    } else {
        let taskName = task.data.name
        let taskNotes = task.data.notes
    }
});

Accessing response status code and headers

const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

let usersApiInstance = new Asana.UsersApi()
let user_gid = "me"; // String | A string identifying a user. This can either be the string \"me\", an email, or the gid of a user.
let opts = {};

usersApiInstance.getUser(user_gid, opts, (error, data, response) => {
    if (error) {
        console.error(error);
    } else {
        // Response Status
        console.log("Response Status:" + response.status)
        // Response Headers
        console.log("Response Headers": + JSON.stringify(response.headers))
    }
});

Adding deprecation flag to your "asana-enable" header

const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

// Add asana-enable header for the client
defaultClient.defaultHeaders['asana-enable'] = 'string_ids';

Documentation for Using the callApi 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
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

// GET - get a task
defaultClient.callApi(
    "/tasks/{task_gid}",
    "GET",
    (pathParams = { task_gid: "<YOUR_TASK_GID>" }),
    (queryParams = {}),
    (headerParams = {}),
    (formParams = {}),
    (bodyParam = null),
    (authNames = ["oauth2"]),
    (contentTypes = []),
    (accepts = ["application/json; charset=UTF-8"]),
    (returnType = "Blob"), // Can be one of: "Blob", "String"
    (callback = (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log("API called successfully. Returned data: " + JSON.stringify(JSON.parse(data), null, 2));
        }
    })
);
GET - get multiple tasks -> with opt_fields
defaultClient.callApi(
    "/tasks",
    "GET",
    (pathParams = {}),
    (queryParams = { opt_fields: "name,notes,projects" }),
    (headerParams = {}),
    (formParams = {}),
    (bodyParam = null),
    (authNames = ["oauth2"]),
    (contentTypes = []),
    (accepts = ["application/json; charset=UTF-8"]),
    (returnType = "Blob"), // Can be one of: "Blob", "String"
    (callback = (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log("API called successfully. Returned data: " + JSON.stringify(JSON.parse(data), null, 2));
        }
    })
);
POST - create a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

// POST - create a task
defaultClient.callApi(
    "/tasks",
    "POST",
    (pathParams = {}),
    (queryParams = {}),
    (headerParams = {}),
    (formParams = {}),
    (bodyParam = {
        data: {
            name: "New Task",
            projects: ["<YOUR_PROJECT_GID>"],
        },
    }),
    (authNames = ["oauth2"]),
    (contentTypes = ["application/json; charset=UTF-8"]),
    (accepts = ["application/json; charset=UTF-8"]),
    (returnType = "Blob"), // Can be one of: "Blob", "String"
    (callback = (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log("API called successfully. Returned data: " + JSON.stringify(JSON.parse(data), null, 2));
        }
    })
);
PUT - update a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

// PUT - update a task
defaultClient.callApi(
    "/tasks/{task_gid}",
    "PUT",
    (pathParams = { task_gid: "<YOUR_TASK_GID>" }),
    (queryParams = {}),
    (headerParams = {}),
    (formParams = {}),
    (bodyParam = {
        data: {
            name: "Updated Task",
        },
    }),
    (authNames = ["oauth2"]),
    (contentTypes = ["application/json; charset=UTF-8"]),
    (accepts = ["application/json; charset=UTF-8"]),
    (returnType = "Blob"), // Can be one of: "Blob", "String"
    (callback = (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log("API called successfully. Returned data: " + JSON.stringify(JSON.parse(data), null, 2));
        }
    })
);
DELETE - delete a task
const Asana = require('asana');
const defaultClient = Asana.ApiClient.instance;

// Configure OAuth2 access token for authorization: oauth2
const oauth2 = defaultClient.authentications['oauth2'];
oauth2.accessToken = "<YOUR_PERSONAL_ACCESS_TOKEN>";

// DELETE - delete a task
defaultClient.callApi(
    "/tasks/{task_gid}",
    "DELETE",
    (pathParams = { task_gid: "<YOUR_TASK_GID>" }),
    (queryParams = {}),
    (headerParams = {}),
    (formParams = {}),
    (bodyParam = null),
    (authNames = ["oauth2"]),
    (contentTypes = []),
    (accepts = ["application/json; charset=UTF-8"]),
    (returnType = "Blob"), // Can be one of: "Blob", "String"
    (callback = (error, data, response) => {
        if (error) {
            console.error(error);
        } else {
            console.log("API called successfully. Returned data: " + JSON.stringify(JSON.parse(data), null, 2));
        }
    })
);

FAQs

Last updated on 29 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc