### Get a Goal (Ruby SDK) Source: https://developers.asana.com/reference/getgoal This example demonstrates how to fetch a goal using the Asana Ruby SDK. Make sure to install the gem with `gem install asana`. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.goals.get_goal(goal_gid: 'goal_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Get Project Template (Python v3) Source: https://developers.asana.com/reference/getprojecttemplate A concise example using the Python SDK v3 to get a project template. Ensure you have `asana==3.2.3` installed. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.project_templates.get_project_template(project_template_gid, {'param': 'value', 'param': 'value'}, opt_pretty=True) ``` -------------------------------- ### Get Project Brief (Node.js v1) Source: https://developers.asana.com/reference/getprojectbrief Fetch a project brief using the Asana Node.js SDK v1. This example demonstrates basic usage with token authentication. Install the SDK using `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.projectbriefs.getProjectBrief(projectBriefGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get Webhooks with Python SDK (v5) Source: https://developers.asana.com/reference/getwebhooks This example demonstrates retrieving multiple webhooks with detailed options using the Asana Python SDK v5. Install with 'pip install asana'. ```python import asana from asana.rest import ApiException from pprint import pprint configuration = asana.Configuration() configuration.access_token = '' api_client = asana.ApiClient(configuration) # create an instance of the API class webhooks_api_instance = asana.WebhooksApi(api_client) workspace = "1331" # str | The workspace to query for webhooks in. opts = { 'limit': 50, # int | Results per page. The number of objects to return per page. The value must be between 1 and 100. 'offset': "eyJ0eXAiOJiKV1iQLCJhbGciOiJIUzI1NiJ9", # str | Offset token. An offset to the next page returned by the API. A pagination request will return an offset token, which can be used as an input parameter to the next request. If an offset is not passed in, the API will return the first page of results. *Note: You can only pass in an offset that was returned to you via a previously paginated request.* 'resource': "51648", # str | Only return webhooks for the given resource. 'opt_fields': "active,created_at,delivery_retry_count,failure_deletion_timestamp,filters,filters.action,filters.fields,filters.resource_subtype,last_failure_at,last_failure_content,last_success_at,next_attempt_after,offset,path,resource,resource.name,target,uri", # list[str] | This endpoint returns a 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. } try: # Get multiple webhooks api_response = webhooks_api_instance.get_webhooks(workspace, opts) for data in api_response: pprint(data) except ApiException as e: print("Exception when calling WebhooksApi->get_webhooks: %s\n" % e) ``` -------------------------------- ### Get Project Brief (Node.js v3) Source: https://developers.asana.com/reference/getprojectbrief Retrieve a project brief using the Asana Node.js SDK v3. This example shows how to specify optional fields to include in the response. Install the SDK using `npm install asana`. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let projectBriefsApiInstance = new Asana.ProjectBriefsApi(client); let project_brief_gid = "12345"; // String | Globally unique identifier for the project brief. let opts = { 'opt_fields': "html_text,permalink_url,project,project.name,text,title" }; projectBriefsApiInstance.getProjectBrief(project_brief_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Get Project Brief (Python) Source: https://developers.asana.com/reference/getprojectbrief Retrieve a project brief using the Asana Python SDK. This example includes error handling for API exceptions and shows how to specify optional fields. Install the SDK using `pip install asana`. ```python import asana from asana.rest import ApiException from pprint import pprint configuration = asana.Configuration() configuration.access_token = '' api_client = asana.ApiClient(configuration) # create an instance of the API class project_briefs_api_instance = asana.ProjectBriefsApi(api_client) project_brief_gid = "12345" # str | Globally unique identifier for the project brief. opts = { 'opt_fields': "html_text,permalink_url,project,project.name,text,title", # list[str] | This endpoint returns a 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. } try: # Get a project brief api_response = project_briefs_api_instance.get_project_brief(project_brief_gid, opts) pprint(api_response) except ApiException as e: print("Exception when calling ProjectBriefsApi->get_project_brief: %s\n" % e) ``` -------------------------------- ### Get Goals with Node.js SDK v1 Source: https://developers.asana.com/reference/getgoals This example demonstrates how to fetch goals using an older version of the Node.js SDK. It requires installation via npm. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.goals.getGoals({param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Install and Use Asana Ruby Client Source: https://developers.asana.com/reference/getfavoritesforuser Install the Asana Ruby gem. This example demonstrates authenticating with an access token and retrieving a user's favorites, specifying resource types and workspace. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.users.get_favorites_for_user(user_gid: 'user_gid', resource_type: ''resource_type_example'', workspace: ''workspace_example'', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Asana SDK Installation and Usage Source: https://developers.asana.com/reference/gettasksfortag Provides installation instructions and basic usage examples for the Asana SDKs in Python, PHP, and Ruby. ```APIDOC ## Python SDK (v3) ### Installation ```bash pip install asana==3.2.3 ``` ### Usage ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') # Example: Get tasks for a tag result = client.tasks.get_tasks_for_tag(tag_gid, {'param': 'value'}, opt_pretty=True) ``` ## PHP SDK ### Installation ```bash composer require asana/asana ``` ### Usage ```php tasks->getTasksForTag($tag_gid, array('param' => 'value'), array('opt_pretty' => 'true')); ``` ## Ruby SDK ### Installation ```bash gem install asana ``` ### Usage ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end # Example: Get tasks for a tag result = client.tasks.get_tasks_for_tag(tag_gid: 'tag_gid', param: "value", options: {pretty: true}) ``` ``` -------------------------------- ### Get Project Membership (Ruby SDK) Source: https://developers.asana.com/reference/getprojectmembership Example of fetching project membership using the Asana Ruby SDK. Install the gem with 'gem install asana'. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.project_memberships.get_project_membership(project_membership_gid: 'project_membership_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Initialize Asana Client and Create Status Source: https://developers.asana.com/reference/createstatusforobject Authentication setup using a personal access token and example of creating a status update. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.status_updates.create_status_for_object(field: "value", field: "value", options: {pretty: true}) ``` -------------------------------- ### Get Task Dependencies with Asana Ruby SDK Source: https://developers.asana.com/reference/getdependenciesfortask This example illustrates how to get task dependencies using the Asana Ruby SDK. Install the gem with `gem install asana`. Ensure you replace 'PERSONAL_ACCESS_TOKEN' and 'task_gid' with your credentials and the target task ID. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.tasks.get_dependencies_for_task(task_gid: 'task_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Hello World with Asana Node SDK v1 Source: https://developers.asana.com/docs/javascript A 'Hello World' example using the Asana Node.js SDK v1. It shows how to create a client with a personal access token and retrieve basic user details. ```javascript // This sample code utilizes node-asana v1.0.5 -> npm install asana@1.0.5 // Import the library var asana = require('asana'); // Note: Replace this value with your own personal access token var personalAccessToken = '0/123456789....'; // Construct an Asana client var client = asana.Client.create().useAccessToken(personalAccessToken); // Get your user info client.users.getUser("me") .then(function(me) { // Print out your information console.log('Hello world! ' + 'My name is ' + me.name + '!'); }); ``` -------------------------------- ### Get Workspace Membership (Ruby SDK) Source: https://developers.asana.com/reference/getworkspacemembership This Ruby example shows how to get a workspace membership using the Asana Ruby SDK. Install the gem and replace 'PERSONAL_ACCESS_TOKEN' with your token. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.workspace_memberships.get_workspace_membership(workspace_membership_gid: 'workspace_membership_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Hello World with Asana Node SDK v3 Source: https://developers.asana.com/docs/javascript A 'Hello World' example using the Asana Node.js SDK v3. It demonstrates how to configure the client with a personal access token and fetch the current user's information. ```javascript // Import the library const Asana = require('asana'); // Configure client with personal access token let client = new Asana.ApiClient(); let token = client.authentications['token']; token.accessToken = '0/123456789....'; // Construct resource API Instance let usersApiInstance = new Asana.UsersApi(client); let user_gid = "me"; let opts = {}; // Get your user info usersApiInstance.getUser(user_gid, opts).then((result) => { console.log('Hello world! ' + 'My name is ' + result.data.name + '!'); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Create a Project Brief with Asana API Source: https://developers.asana.com/reference/createprojectbrief Use these examples to programmatically create project briefs. Ensure you have the respective client library installed and a valid personal access token. ```php projectbriefs->createProjectBrief($project_gid, array('field' => 'value', 'field' => 'value'), array('opt_pretty' => 'true')) ``` ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.project_briefs.create_project_brief(project_gid: 'project_gid', field: "value", field: "value", options: {pretty: true}) ``` -------------------------------- ### Get Tags for a Task in Ruby Source: https://developers.asana.com/reference/gettagsfortask This Ruby example shows how to fetch tags for a task using the Asana Ruby gem. Install the gem using 'gem install asana'. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.tags.get_tags_for_task(task_gid: 'task_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Get Portfolio Items (Python v3 SDK) Source: https://developers.asana.com/reference/getitemsforportfolio This example shows how to get items for a portfolio using the Asana Python SDK v3. Install the SDK using `pip install asana==3.2.3`. Replace `'PERSONAL_ACCESS_TOKEN'` with your actual token and `'portfolio_gid'` with the portfolio's ID. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.portfolios.get_items_for_portfolio(portfolio_gid, {'param': 'value', 'param': 'value'}, opt_pretty=True) ``` -------------------------------- ### Create Project with Node.js SDK v1 Source: https://developers.asana.com/reference/createproject This example shows how to create a project using the older Node.js SDK (v1). It requires installation via npm and uses a personal access token for authentication. ```javascript const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.projects.createProject({field: "value", field: "value", pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get Portfolio Memberships (Node.js SDK v1) Source: https://developers.asana.com/reference/getportfoliomemberships This example demonstrates how to get portfolio memberships using the older Node.js SDK v1. Install version 1.0.5 of the asana package. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.portfoliomemberships.getPortfolioMemberships({param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Create Project in Node.js Source: https://developers.asana.com/reference/createprojectforteam This Node.js example demonstrates how to create a project using the Asana client library. Replace placeholders with your actual access token and desired project details. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let projectsApiInstance = new Asana.ProjectsApi(client); let body = {"data": {"": "", "": "",}}; // Object | The new project to create. let team_gid = "159874"; // String | Globally unique identifier for the team. let opts = { 'opt_fields': "archived,color,completed,completed_at,completed_by,completed_by.name,created_at,created_from_template,created_from_template.name,current_status,current_status.author,current_status.author.name,current_status.color,current_status.created_at,current_status.created_by,current_status.created_by.name,current_status.html_text,current_status.modified_at,current_status.text,current_status.title,current_status_update,current_status_update.resource_subtype,current_status_update.title,custom_field_settings,custom_field_settings.custom_field,custom_field_settings.custom_field.asana_created_field,custom_field_settings.custom_field.created_by,custom_field_settings.custom_field.created_by.name,custom_field_settings.custom_field.currency_code,custom_field_settings.custom_field.custom_label,custom_field_settings.custom_field.custom_label_position,custom_field_settings.custom_field.date_value,custom_field_settings.custom_field.date_value.date,custom_field_settings.custom_field.date_value.date_time,custom_field_settings.custom_field.default_access_level,custom_field_settings.custom_field.description,custom_field_settings.custom_field.display_value,custom_field_settings.custom_field.enabled,custom_field_settings.custom_field.enum_options,custom_field_settings.custom_field.enum_options.color,custom_field_settings.custom_field.enum_options.enabled,custom_field_settings.custom_field.enum_options.name,custom_field_settings.custom_field.enum_value,custom_field_settings.custom_field.enum_value.color,custom_field_settings.custom_field.enum_value.enabled,custom_field_settings.custom_field.enum_value.name,custom_field_settings.custom_field.format,custom_field_settings.custom_field.has_notifications_enabled,custom_field_settings.custom_field.id_prefix,custom_field_settings.custom_field.input_restrictions,custom_field_settings.custom_field.is_formula_field,custom_field_settings.custom_field.is_global_to_workspace,custom_field_settings.custom_field.is_value_read_only,custom_field_settings.custom_field.multi_enum_values,custom_field_settings.custom_field.multi_enum_values.color,custom_field_settings.custom_field.multi_enum_values.enabled,custom_field_settings.custom_field.multi_enum_values.name,custom_field_settings.custom_field.name,custom_field_settings.custom_field.number_value,custom_field_settings.custom_field.people_value,custom_field_settings.custom_field.people_value.name,custom_field_settings.custom_field.precision,custom_field_settings.custom ``` -------------------------------- ### Initialize Asana Client and Set Up Local Variables Source: https://developers.asana.com/docs/how-to-write-a-script-actions-script This snippet demonstrates how to initialize the Asana client with a personal access token and set up necessary variables like project, task, and workspace GIDs for local testing. It also shows how to instantiate API resource clients. ```javascript const Asana = require('asana'); let client = Asana.ApiClient.instance; let token = client.authentications['token']; // TODO: Replace with your Personal Access Token (PAT) // NOTE: This is only used for testing your script locally token.accessToken = ""; const log = console.log; // Set your project, task and workspace gid here // These values will be provided to you when your script gets executed // We want to emulate that so we set those values here // // TODO: Set these values const project_gid = "123"; const task_gid = "456"; const workspace_gid = "789"; // Set up the resource instances that you plan on using for your script here // Script actions will make these available for you in the script editor // // TODO: instantiate the Asana resources that you plan on using in your script // EX: If you want to make API calls to the tasks endpoint, uncomment the line below // let tasksApiInstance = new Asana.TasksApi(); const run = async () => { // TODO: Write your script here }; run(); ``` ```javascript // Instantiate Asana API resources // TODO: instantiate the Asana resources that you plan on using in your script // EX: If you want to make API calls to the tasks endpoint, uncomment the line below let tasksApiInstance = new Asana.TasksApi(); let storiesApiInstance = new Asana.StoriesApi(); ``` -------------------------------- ### Get Team Memberships (Ruby SDK) Source: https://developers.asana.com/reference/getteammemberships This example shows how to fetch team memberships using the Asana Ruby SDK. Make sure to install the gem using 'gem install asana'. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.team_memberships.get_team_memberships(param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Get Team Memberships (Node.js v1 SDK) Source: https://developers.asana.com/reference/getteammembershipsforteam Example of retrieving team memberships with the Asana Node.js SDK v1. Install version 1.0.5 using `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.teammemberships.getTeamMembershipsForTeam(teamGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get Project Brief (Ruby SDK) Source: https://developers.asana.com/reference/getprojectbrief Use the Ruby SDK to retrieve a project brief. Install the SDK using 'gem install asana'. ```ruby require 'asana' client = Asana::Client.new do |c| c.authentication :access_token, 'PERSONAL_ACCESS_TOKEN' end result = client.project_briefs.get_project_brief(project_brief_gid: 'project_brief_gid', param: "value", param: "value", options: {pretty: true}) ``` -------------------------------- ### Create a Project Brief in Python Source: https://developers.asana.com/reference/createprojectbrief Examples for creating project briefs using different versions of the Asana Python SDK. ```python import asana from asana.rest import ApiException from pprint import pprint configuration = asana.Configuration() configuration.access_token = '' api_client = asana.ApiClient(configuration) # create an instance of the API class project_briefs_api_instance = asana.ProjectBriefsApi(api_client) body = {"data": {"": "", "": "",}} # dict | The project brief to create. project_gid = "1331" # str | Globally unique identifier for the project. opts = { 'opt_fields': "html_text,permalink_url,project,project.name,text,title", # list[str] | This endpoint returns a 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. } try: # Create a project brief api_response = project_briefs_api_instance.create_project_brief(body, project_gid, opts) pprint(api_response) except ApiException as e: print("Exception when calling ProjectBriefsApi->create_project_brief: %s\n" % e) ``` ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.project_briefs.create_project_brief(project_gid, {'field': 'value', 'field': 'value'}, opt_pretty=True) ``` -------------------------------- ### Get Subtasks for a Task (Node.js SDK v1) Source: https://developers.asana.com/reference/getsubtasksfortask This example uses an older version of the Asana Node.js SDK (v1) to retrieve subtasks. Install it using `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.tasks.getSubtasksForTask(taskGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Create a Project Brief in Node.js Source: https://developers.asana.com/reference/createprojectbrief Examples for creating project briefs using different versions of the Asana Node.js SDK. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let projectBriefsApiInstance = new Asana.ProjectBriefsApi(client); let body = {"data": {"": "", "": "",}}; // Object | The project brief to create. let project_gid = "1331"; // String | Globally unique identifier for the project. let opts = { 'opt_fields': "html_text,permalink_url,project,project.name,text,title" }; projectBriefsApiInstance.createProjectBrief(body, project_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.projectbriefs.createProjectBrief(projectGid, {field: "value", field: "value", pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get Task Dependents in Node.js (SDK v3) Source: https://developers.asana.com/reference/getdependentsfortask This example demonstrates how to fetch dependent tasks using the Asana Node.js SDK v3. Install the SDK using `npm install asana`. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let tasksApiInstance = new Asana.TasksApi(client); let task_gid = "321654"; // String | The task to operate on. let opts = { 'limit': 50, 'offset': "eyJ0eXAiOJiKV1iQLCJhbGciOiJIUzI1NiJ9", 'opt_fields': "actual_time_minutes,approval_status,assigned_by,assigned_by.name,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.default_access_level,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.id_prefix,custom_fields.input_restrictions,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.privacy_setting,custom_fields.reference_value,custom_fields.reference_value.name,custom_fields.representation_type,custom_fields.resource_subtype,custom_fields.text_value,custom_fields.type,custom_type,custom_type.name,custom_type_status_option,custom_type_status_option.name,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" }; tasksApiInstance.getDependentsForTask(task_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Get Attachment with Fields (Python SDK v5) Source: https://developers.asana.com/reference/getattachment This Python example retrieves attachment details, specifying optional fields using the Asana SDK v5. Install with 'pip install asana'. ```python import asana from asana.rest import ApiException from pprint import pprint configuration = asana.Configuration() configuration.access_token = '' api_client = asana.ApiClient(configuration) # create an instance of the API class attachments_api_instance = asana.AttachmentsApi(api_client) attachment_gid = "12345" # str | Globally unique identifier for the attachment. opts = { 'opt_fields': "connected_to_app,created_at,download_url,host,name,parent,parent.created_by,parent.name,parent.resource_subtype,permanent_url,resource_subtype,size,view_url", # list[str] | This endpoint returns a 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. } try: # Get an attachment api_response = attachments_api_instance.get_attachment(attachment_gid, opts) pprint(api_response) except ApiException as e: print("Exception when calling AttachmentsApi->get_attachment: %s\n" % e) ``` -------------------------------- ### Create Project for Workspace (Python SDK v3) Source: https://developers.asana.com/reference/createprojectforworkspace This example demonstrates creating a project using the Asana Python SDK v3. Install the SDK using pip and provide your personal access token. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.projects.create_project_for_workspace(workspace_gid, {'field': 'value', 'field': 'value'}, opt_pretty=True) ``` -------------------------------- ### Get Users for a Team in Node.js (SDK v1) Source: https://developers.asana.com/reference/getusersforteam This example shows how to retrieve users for a team using an older version of the Asana Node.js SDK (v1). Install it with `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.users.getUsersForTeam(teamGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Create Project with Python SDK Source: https://developers.asana.com/reference/createproject Demonstrates creating a project using the Asana Python SDK. It requires installing the SDK and configuring your access token. The `opt_fields` parameter allows specifying which fields to include in the response. ```python import asana from asana.rest import ApiException from pprint import pprint configuration = asana.Configuration() configuration.access_token = '' api_client = asana.ApiClient(configuration) # create an instance of the API class projects_api_instance = asana.ProjectsApi(api_client) body = {"data": {"": "", "": "",}} # dict | The project to create. opts = { 'opt_fields': "archived,color,completed,completed_at,completed_by,completed_by.name,created_at,created_from_template,created_from_template.name,current_status,current_status.author,current_status.author.name,current_status.color,current_status.created_at,current_status.created_by,current_status.created_by.name,current_status.html_text,current_status.modified_at,current_status.text,current_status.title,current_status_update,current_status_update.resource_subtype,current_status_update.title,custom_field_settings,custom_field_settings.custom_field,custom_field_settings.custom_field.asana_created_field,custom_field_settings.custom_field.created_by,custom_field_settings.custom_field.created_by.name,custom_field_settings.custom_field.currency_code,custom_field_settings.custom_field.custom_label,custom_field_settings.custom_field.custom_label_position,custom_field_settings.custom_field.date_value,custom_field_settings.custom_field.date_value.date,custom_field_settings.custom_field.date_value.date_time,custom_field_settings.custom_field.default_access_level,custom_field_settings.custom_field.description,custom_field_settings.custom_field.display_value,custom_field_settings.custom_field.enabled,custom_field_settings.custom_field.enum_options,custom_field_settings.custom_field.enum_options.color,custom_field_settings.custom_field.enum_options.enabled,custom_field_settings.custom_field.enum_options.name,custom_field_settings.custom_field.enum_value,custom_field_settings.custom_field.enum_value.color,custom_field_settings.custom_field.enum_value.enabled,custom_field_settings.custom_field.enum_value.name,custom_field_settings.custom_field.format,custom_field_settings.custom_field.has_notifications_enabled,custom_field_settings.custom_field.id_prefix,custom_field_settings.custom_field.input_restrictions,custom_field_settings.custom_field.is_formula_field,custom_field_settings.custom_field.is_global_to_workspace,custom_field_settings.custom_field.is_value_read_only,custom_field_settings.custom_field.multi_enum_values,custom_field_settings.custom_field.multi_enum_values.color,custom_field_settings.custom_field.multi_enum_values.enabled,custom_field_settings.custom_field.multi_enum_values.name,custom_field_settings.custom_field.name,custom_field_settings.custom_field.number_value,custom_field_settings.custom_field.people_value,custom_field_settings.custom_field.people_value.name,custom_field_settings.custom_field.precision,custom_field_settings.custom_field.privacy_setting,custom_field_settings.custom_field.reference_value,custom_field_settings.custom_field.reference_value.name,custom_fie } try { api_response = projects_api_instance.create_project(body, opts) pprint(api_response) } catch(e) { print("Exception when calling ProjectsApi->create_project: %s\n" % e) } ``` -------------------------------- ### Create Portfolio with Node.js SDK Source: https://developers.asana.com/reference/createportfolio This snippet demonstrates creating a portfolio using the Asana Node.js SDK. Install the SDK using 'npm install asana'. ```node const Asana = require('asana'); const client = Asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.portfolios.createPortfolio({ 'workspace': '12345', 'name': 'My Portfolio', 'owner': 'me', 'public': false, 'default_due_on': '2024-12-31', 'color': 'light-blue', 'members': [ 'user@example.com' ] }) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get User Details (Node.js SDK v1) Source: https://developers.asana.com/reference/getuser Fetch user information using the Node.js SDK v1. Install with 'npm install asana@1.0.5'. This example demonstrates basic user retrieval. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.users.getUser(userGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get Task Dependents in Node.js (SDK v1) Source: https://developers.asana.com/reference/getdependentsfortask This example shows how to retrieve dependent tasks using an older version of the Asana Node.js SDK (v1.0.5). Install it with `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.tasks.getDependentsForTask(taskGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Hello World Asana API Request in Ruby Source: https://developers.asana.com/docs/ruby Example of how to make a 'Hello World' GET request to the /users/me endpoint using the Asana Ruby client library. It demonstrates initializing the client with a personal access token and fetching user details. ```ruby require 'asana' personal_access_token = '0/123456789....' client = Asana::Client.new do |c| c.authentication :access_token, personal_access_token end me = client.users.me puts "Hello world! " + "My name is " + me.name + "!" ``` -------------------------------- ### Create a Project Brief in Java Source: https://developers.asana.com/reference/createprojectbrief Uses the Asana Java SDK to authenticate and create a project brief. ```java import com.asana.Client; Client client = Client.accessToken("PERSONAL_ACCESS_TOKEN"); JsonElement result = client.projectbriefs.createProjectBrief(projectGid) .data("field", "value") .data("field", "value") .option("pretty", true) .execute(); ``` -------------------------------- ### Get Audit Log Events in Node.js (SDK v1) Source: https://developers.asana.com/reference/getauditlogevents An alternative Node.js example for retrieving audit log events using Asana SDK v1. Install with `npm install asana@1.0.5`. ```node const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.auditlogapi.getAuditLogEvents(workspaceGid, {param: "value", param: "value", opt_pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Get User Details (Python SDK v3) Source: https://developers.asana.com/reference/getuser Fetch user information using the Python SDK v3. Install with 'pip install asana==3.2.3'. This example shows a simpler way to call the get_user method. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.users.get_user(user_gid, {'param': 'value', 'param': 'value'}, opt_pretty=True) ``` -------------------------------- ### Install Asana Node.js SDK Source: https://developers.asana.com/reference/addfollowersforproject Install the Asana Node.js SDK using npm. This is the first step to using the SDK in your project. ```bash npm install asana ``` -------------------------------- ### Get User Details (Node.js SDK v3) Source: https://developers.asana.com/reference/getuser Retrieve user details using the Node.js SDK v3. Install the SDK using 'npm install asana'. This example shows how to specify optional fields. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let usersApiInstance = new Asana.UsersApi(client); 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 = { 'workspace': "12345", 'opt_fields': "custom_fields,custom_fields.date_value,custom_fields.date_value.date,custom_fields.date_value.date_time,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.id_prefix,custom_fields.input_restrictions,custom_fields.is_formula_field,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.representation_type,custom_fields.text_value,custom_fields.type,email,name,photo,photo.image_1024x1024,photo.image_128x128,photo.image_21x21,photo.image_27x27,photo.image_36x36,photo.image_60x60,workspaces,workspaces.name" }; usersApiInstance.getUser(user_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Create Project Status (Node.js SDK v3) Source: https://developers.asana.com/reference/createprojectstatusforproject This example demonstrates creating a project status using the Asana Node.js SDK v3. Install the SDK using 'npm install asana'. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let projectStatusesApiInstance = new Asana.ProjectStatusesApi(client); let body = {"data": {"": "", "": "",}}; // Object | The project status to create. let project_gid = "1331"; // String | Globally unique identifier for the project. let opts = { 'opt_fields': "author,author.name,color,created_at,created_by,created_by.name,html_text,modified_at,text,title" }; projectStatusesApiInstance.createProjectStatusForProject(body, project_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Get Attachment with Options (Node.js SDK v3) Source: https://developers.asana.com/reference/getattachment This Node.js example demonstrates fetching attachment details with specific fields using the Asana SDK v3. Install the SDK using 'npm install asana'. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let attachmentsApiInstance = new Asana.AttachmentsApi(client); let attachment_gid = "12345"; // String | Globally unique identifier for the attachment. let opts = { 'opt_fields': "connected_to_app,created_at,download_url,host,name,parent,parent.created_by,parent.name,parent.resource_subtype,permanent_url,resource_subtype,size,view_url" }; attachmentsApiInstance.getAttachment(attachment_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Instantiate Project Template (Ruby SDK) Source: https://developers.asana.com/reference/instantiateproject Instantiate a project from a template using the Asana Ruby SDK. This example requires the asana gem to be installed. ```ruby require 'asana' client = Asana::Client.new client.options[:personal_access_token] = 'PERSONAL_ACCESS_TOKEN' result = client.project_templates.instantiate_project(project_template_gid, {'field': 'value', 'field': 'value'}, opt_pretty: true) ``` -------------------------------- ### Instantiate a Project in Java Source: https://developers.asana.com/reference/instantiateproject Use this snippet to initiate project creation from a template using the Asana Java client library. ```java Client client = Client.accessToken("PERSONAL_ACCESS_TOKEN"); ProjectTemplateInstantiateProjectRequest body = new ProjectTemplateInstantiateProjectRequest(); body.name = "New Project Name"; body.team = "12345"; Job job = client.projectTemplates.instantiateProject("12345") .body(body) .execute(); ``` -------------------------------- ### Get Workspace Details (Python SDK v3) Source: https://developers.asana.com/reference/getworkspace This example shows how to fetch workspace information using the Asana Python SDK v3. Install the SDK using 'pip install asana==3.2.3' and replace 'PERSONAL_ACCESS_TOKEN' with your token. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.workspaces.get_workspace(workspace_gid, {'param': 'value', 'param': 'value'}, opt_pretty=True) ``` -------------------------------- ### Get Task Details with Asana Python SDK v3 Source: https://developers.asana.com/reference/gettask This example demonstrates retrieving task details using the older v3 Python SDK. Install it using 'pip install asana==3.2.3'. Replace 'PERSONAL_ACCESS_TOKEN' with your token. ```python import asana client = asana.Client.access_token('PERSONAL_ACCESS_TOKEN') result = client.tasks.get_task(task_gid, {'param': 'value', 'param': 'value'}, opt_pretty=True) ``` -------------------------------- ### Get Subtasks for a Task (Node.js SDK v3) Source: https://developers.asana.com/reference/getsubtasksfortask This example uses the Asana Node.js SDK v3 to fetch subtasks. It includes options for pagination and field selection. Install the SDK using `npm install asana`. ```node const Asana = require('asana'); let client = new Asana.ApiClient(); client.authentications.token.accessToken = ''; let tasksApiInstance = new Asana.TasksApi(client); let task_gid = "321654"; // String | The task to operate on. let opts = { 'limit': 50, 'offset': "eyJ0eXAiOJiKV1iQLCJhbGciOiJIUzI1NiJ9", 'opt_fields': "actual_time_minutes,approval_status,assigned_by,assigned_by.name,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.default_access_level,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.id_prefix,custom_fields.input_restrictions,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.privacy_setting,custom_fields.reference_value,custom_fields.reference_value.name,custom_fields.representation_type,custom_fields.resource_subtype,custom_fields.text_value,custom_fields.type,custom_type,custom_type.name,custom_type_status_option,custom_type_status_option.name,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" }; tasksApiInstance.getSubtasksForTask(task_gid, opts).then((result) => { console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2)); }, (error) => { console.error(error.response.body); }); ``` -------------------------------- ### Create Project using Asana Node.js SDK v1 Source: https://developers.asana.com/reference/createprojectforworkspace This example demonstrates creating a project using the older v1 Node.js SDK. It requires a personal access token for authentication. ```javascript const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.projects.createProjectForWorkspace(workspaceGid, {field: "value", field: "value", pretty: true}) .then((result) => { console.log(result); }); ``` -------------------------------- ### Create Project for Team (Node.js SDK v1) Source: https://developers.asana.com/reference/createprojectforteam This example demonstrates creating a project using an older version of the Asana Node.js SDK. It requires installation via npm and uses a personal access token for authentication. ```javascript const asana = require('asana'); const client = asana.Client.create().useAccessToken('PERSONAL_ACCESS_TOKEN'); client.projects.createProjectForTeam(teamGid, {field: "value", field: "value", pretty: true}) .then((result) => { console.log(result); }); ```