API Custom Field issues

Frustrated with PUT’ing custom fields. I’m using javascript (google script).

As per:
[Updating a custom field using ASANA Python API - Stack Overflow]

and another thread I found and now can’t find again in which you say an “obscure” bug was found.

the root issue is that API isn’t symmetrical so can’t FETCH and PUT a task (the JSON exactly as it’s FETCHed) without a “Value cannot be an array error” as custom fields are not expected to be an array when posted for some reason

but in trying to workaround by only updating the custom field rather than the whole task with {‘data’: {‘custom_fields’: id : new-value}} using the id I get from FETCHing the task I get “Custom field with ID id is not on given object”, I can’t figure out what’s going on there.

Be great to see some working javascript to FETCH a task, change a custom field value and PUT it.

Thanks

What I can say is that fetching data gives you object like {id:X} while pushing data needs to push only the id. Does it help?
cc @Diakoptis who is the best at API stuff :stuck_out_tongue:

Thanks, not to worry I sorted it

How? :stuck_out_tongue: share your solution for others :wink:

2 Likes

For reference, I’ll post a result here after spending some time figuring it out:

PUT https://app.asana.com/api/1.0/tasks/<task gid>
Content-Type: application/json; charset=utf-8
Authorization: Bearer <token>

{
  "data": {
    "gid": "<task gid>",
    "custom_fields": {
        "<custom field gid>": <new value: int, "string", "enum">
    }
  }
}
1 Like

This is the current work-around for this issue.
Seems like you cannot directly add the custom_fields along with the creation of the task.
You need to create a task first and update this task afterwards for the custom_fields.

Anyway. Thanks Cristian!

Are you sure? @Phil_Seeman can you confirm this? I am 99% sure you can create a task along with its custom field value.

Hi @Mikel1,

@Bastien_Siebman is correct; you can definitely add custom fields when creating a new task.

The most common issue I see where that process fails is when one attempts to add a custom field to a project where that custom field has not been added to that project; that is, it’s not part of the project’s custom_field_settings collection.