Issue posting custom_fields updates through Asana RestAPI

I am updating a task filed in a test project to reflect the time elapsed since creation in a clear way.

I am using the client.tasks.update(task[‘gid’], params=data) function to post this data format:

{
    "data": {
        "custom_fields": [
            {
                "gid": "1202936345777676",
                "enabled": true,
                "multi_enum_values": [
                    {
                        "gid": "1202936345777694",
                        "resource_type": "enum_option",
                        "enabled": true,
                        "name": "< 1 Month",
                        "color": "indigo"
                    }
                ],
                "name": "Age",
                "description": "",
                "created_by": {
                    "gid": "1202108515356173",
                    "name": "Carlo A. Fernandez Benedetto",
                    "resource_type": "user"
                },
                "display_value": "< 1 Month",
                "resource_subtype": "multi_enum",
                "resource_type": "custom_field",
                "type": "multi_enum"
            }
        ]
    }
}

The Asana.error I get is: “ValueError: dictionary update sequence element #0 has length 1; 2 is required”

Any help on the solution would be greatly appreciated

Hi,

Here’s the expected format to update a task’s custom fields:

{
 '123455':'a value',
'90364':'42'
}

the first number is the field gid, the second value is the actual value you want, either a dropdown option gid, a text, a number…

Make sure to check out the body parameter on the right of the documentation.

Does this help?

Hi Bastien!

Thank you for your answer! Not sure what you mean on the 3rd line of your json, maybe you could help me with the context of my data? It is a custom drop down menu I created to display text in a column of the list view.

I tried with

{
    "data": {
        "custom_fields": {
            "1202936345777676": "1 Month or ++"
        }
    }
}

And with:

{
    "data": {
        "custom_fields": {
            "1202936345777676": "1202936345777694"
        }
    }
}

Both return the same issue.

“ValueError: dictionary update sequence element #0 has length 1; 2 is required”

What would be the 2nd level required?

"Age" : "< 1 Month" ?

I am not 100% sure but try the following:

{
custom_fields:{
'1202936345777676':['1202936345777694']
}
}

I’ll explain if it works :slight_smile:

Hi Bastian,

Thank you again, but no luck with that either, I tried with this validated json:

{
  "data": {
    "custom_fields": {
      "1202936345777676": [
        "1202936345777680"
      ]
    }
  }
}

& with only:

{
  "custom_fields": {
    "1202936345777676": [
      "1202936345777680"
    ]
  }
}

I still get the same json lenght issue:

ValueError: dictionary update sequence element #0 has length 1; 2 is required

Can you use Postman for example to validate the format and numbers are correct before moving to another tech stack?

The numbers for the custom fields are taken from the full task view that displays them and are correct. According to this: https://community.zapier.com/featured-articles-65/how-to-update-custom-fields-on-an-asana-task-9381

{
  "data": {
    "custom_fields": {
      "1202936345777676": "1202936345777680"
    }
  }
}

Should work, but according to the asana error, my dictionary here on pos 0 (“data”) has a lenght of 1 when 2 is needed, so I don’t know what is expected. We dont have time to download Postman and check for this, but is a simple dict. length (ie. format) error. Is there any example or logs on how other users update this?

Could I please contact your API product owner, devs or support?

You can email api-support@asana.com, the Asana dev team almost never answers here.

2 Likes

In case anyone runs into this, for custom fileds:

Incorrect:
{
"data": {
"custom_fields": {
"1203012693580045": "1203012693586629"
}
}
}

Correct:
{
"custom_fields": {
"1203012693580045": "1203012693586629"
}
}

Issue solved, thank you again!

1 Like