Can't update custom field value using Asana API

Please read this before posting

Hello,

I’m trying to update custom field value using ```
PUT /custom_fields/{custom_field_gid}

but for some reason i can't update its value. The thing is that i get 200 as a response, but the custom field value is not updated. I tried using postman, curl and node.js request-promise but the result is always the same.  in postman i'm using PUT https://app.asana.com/api/1.0/custom_fields/1115652263994341
{ "data": { "number_value": 10.5}}
and this is the response i get: 
{
    "data": {
        "gid": "1115652263994341",
        "id": 1115652263994341,
        "resource_type": "custom_field",
        "resource_subtype": "number",
        "type": "number",
        "name": "sum hours",
        "description": "",
        "is_global_to_workspace": true,
        "precision": 1
    }
}

this is my cURL:  curl --request PUT -H "Authorization: Bearer {token}" https://app.asana.com/api/1.0/custom_fields/1115652263994341 --data-urlencode "number_value=15.5"
The response is the same as above.

And this is node.js reques-promise:
 let uri = 'https://app.asana.com/api/1.0/custom_fields/'+singleCustomField.gid;
                                const options = {
                                    method: 'PUT',
                                    uri: uri,
                                    body: {
                                        data: {
                                                number_value: singleCustomField.number_value + tasks.tracked
                                        }

                                    },
                                    json: true, // Automatically stringifies the body to JSON
                                    headers: {
                                        'User-Agent': 'Request-Promise',
                                        'Content-Type': 'application/json',
                                        'Authorization': 'Bearer {token}'
                                    }
                                };
                                rp(options)
                                    .then(function (parsedBody) {
                                       console.log('success!!!', parsedBody)
                                    })
                                    .catch(function (err) {
                                        // POST failed...
                                        console.log(err);
                                    });
Could someone please help me because i really don't know what am i doing wrong?

Hi @Nikola_Lucin,

Others have had this same issue - see this thread for more info:

@Ross_Grambo or @Joe_Trollo, maybe you can lend a hand here?

1 Like

The issue here is that you’re trying to update the definition of a custom field, not the value of a custom field on a task. The API call you want is something like

PUT /tasks/<task-id>

{
  "data": {
    "custom_fields": {
      "1115652263994341": "10.5"
    }
  }
}
1 Like

Oh, sorry, @Joe_Trollo, personally I didn’t look closely enough before I summoned you :slight_smile: and assumed it was the same issue as that other thread.

For future reference, perhaps you could take a look at that other thread? We were never able to get it to work using CURL - it returns the task we updated and returns a 200, but the returned object doesn’t contain the change we submitted.

2 Likes

Thanks Joe_Trollo, that did the trick for me :slight_smile:

Hi Joe, any chance you can have a look on my problem. I see that your suggestion helps others but for some reason I keep hetting errors. This is what I did to test it in Postman:

Thanks!

Hey Ben,

That error is expected because we expect json data, and the postman is treating that field as:

custom_fields: "1234567890:Test Value"

rather than

custom_fields: {
  "1234567890": "Test Value"
}

I’d recommend using the “raw” option in postman and typing the json in there.

Cheers,
Ross

Thank you Ross for the quick reply here!
I tried to paste your syntax to Postman and get an error again. Any chance you can guide me on what should I put in the Postman (Raw) box? I’m not a developer so just need the correct template in order to use on my integration tool. Once I’ll have it I’ll place the future values dynamically inside. Thanks!

1 Like

Oh sorry I didn’t include the full json body.

Pick raw, on the right orange dropdown pick json.

The full thing should be:

"data": {
  "custom_fields": {
    "23456789": "Test Value"
  }
}

Ok… I’ve found it :slight_smile:

1 Like

Hi again Ross,
Can you please provide the syntax which update multiple custom fields?

Thanks!

Should be:

"data": {
  "custom_fields": {
    "23456789": "Test Value",
    "987654321": "Test Value 2"
  }
}

Getting this error:
“message”: “Could not parse request data, invalid JSON”, See below

@ben.bachar,

I don’t see anything wrong at a glance, but try pasting that body code into a validator, like https://jsonlint.com/ .

The extra newlines might be the issue or some of the quotes might be “ or ” rather than ".

Thanks. Succeed. There was a missing { in the first line :slight_smile:

1 Like