user6117761
user6117761

Reputation: 11

How to add multiple tags when creating task?

As the title says, how do I add multiple asana tags when creating task? I have this:

var task = {
      "data" : {
          "name" : projectName,
          "workspace" : getAsanaWorkspace(),
          "team" : teamId,
          "notes": desc,
          "tags": [{"id: 123245"},{"id: 456987"},{"id: 124589"}]
        } 
  };

but its not working.

Upvotes: 1

Views: 124

Answers (2)

Dzmitry Dranitski
Dzmitry Dranitski

Reputation: 669

Asana API has https://developers.asana.com/reference/createtask POST method that allows you to create a task. Its Data object has optional tags property which is an array of tag gids.

const Asana = require('asana');

let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = '<YOUR_ACCESS_TOKEN>';

let tasksApiInstance = new Asana.TasksApi();
let body = {"data": {"tags": ["gid1", "gid2", "gid3"], "<PARAM_1>": "<VALUE_1>", "<PARAM_2>": "<VALUE_2>",}}; // Object | The task to create.
let opts = { 
    '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.id_prefix,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.representation_type,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,parent,parent.created_by,parent.name,parent.resource_subtype,permalink_url,projects,projects.name,resource_subtype,start_at,start_on,tags,tags.name,workspace,workspace.name"
};
tasksApiInstance.createTask(body, opts).then((result) => {
    console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
}, (error) => {
    console.error(error.response.body);
});

Please note that this tags property is only available on task creation. If you want to update tags on existing tasks, you should use https://developers.asana.com/reference/addtagfortask instead (this method can only add one tag at a time)

Upvotes: 0

Ian Davids
Ian Davids

Reputation: 35

Have you tried making the tags list just a list of ids rather than a list of hashes?

Upvotes: -1

Related Questions