Having difficulty with Asana API and updating custom field values in Node

I’m sure I’m probably just missing something simple, but for the life of me I can’t update a custom field on a task. Here are the various snippets I’ve tried:

client.tasks.updateTask( my_task_id, { my_custom_field_id: update_value })

client.tasks.updateTask( my_task_id, {“custom_fields”: {my_custom_field_id: update_value} })
//this one returns an Invalid Request error

client. tasks.updateTask( my_task_id, {“data”: {“custom_fields”: { my_custom_field_id: update_value} } })

For each of the above, I’ve tried with and without quotes around: data, custom_fields, and my_custom_field_id

Note: I’m using the actual numbers, not variable names, until I get it working.
Note: I was initially attempting to update a custom date field, but I also can’t even update a custom text field.
Note: I’ve been getting custom field data from tasks for years now without issue. This is the first I’m trying to update custom fields.

What am I doing wrong?

Oddly, I can update the field through the API documentation Try It for Node – but the code shown doesn’t change with the inputs in the documentation.

It’s always:

client.tasks.updateTask(taskGid, {field: “value”, field: “value”, pretty: true})

I assume the button performs the operation in a standard way, and not the language selected (which makes sense). But looking at the header details, I don’t see how my code isn’t doing the same thing.

Hi @Alexander_Fouse,

From my understand it looks like you are trying to update a custom field value on a task through our Update a task endpoint. Here’s how you would do this with our node-asana v1.0.2 client library:

const asana = require('asana');

const client = asana.Client.create().useAccessToken("<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>");
const taskGid = "<YOUR_TASK_GID>"

client.tasks.updateTask(taskGid, {custom_fields: {"<YOUR_CUSTOM_FIELD_GID>": "<CUSTOM_FIELD_VALUE>"}})
    .then((result) => {
        console.log(result);
    });

I think the difference here is no need for the quotes for “custom_fields” key. Your last request also has a space in between the client and tasks → client. tasks → should be client.tasks


Oddly, I can update the field through the API documentation Try It for Node – but the code shown doesn’t change with the inputs in the documentation.

Our documentation site does not support trying our client libraries through it so when you make changes to the field inputs/text inputs in our docs it will not change in the sample code editor to the right. This will only work for shell and other samples like Axios, Node-fetch etc…

1 Like

Thank you!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.