# Api & Custom Fields

**URL:** <https://forum.asana.com/t/api-custom-fields/1733>\
**Category:** API & Developers\
**Created:** [13 April 2017 12:42 UTC](https://forum.asana.com/t/api-custom-fields/1733 "2017-04-13T12:42:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierluigi\_Vinciguerr](https://luna1.co/8d76cd.png) [@Pierluigi\_Vinciguerr](https://forum.asana.com/u/Pierluigi_Vinciguerr)\
**Post date:** [13 April 2017 12:42 UTC](https://forum.asana.com/t/api-custom-fields/1733/1 "2017-04-13T12:42:27Z")

</div>

Hi,  
i need to update (or create) via API (curl) a task, with some custom fields (enum type) populated.  
Just as an example, i have this custom field with these 4 options:  
{“id”:318336795802518,“enum\_options”:  
[{“id”:318336795802519,“enabled”:true,“name”:“A Miss”},  
{“id”:318336795802520,“enabled”:true,“name”:“A Country miss”},  
{“id”:318336795802521,“enabled”:true,“name”:“A Country price anomaly”},  
{“id”:318336795802522,“enabled”:true,“name”:“B Anomaly”}],“name”:“Bug Type”,“type”:“enum”},

The job id i need to update is 318401568256461, so my curl expression is:  
curl --request PUT -H “Authorization: Bearer MYAPIKEY” [https://app.asana.com/api/1.0/tasks/318401568256461](https://app.asana.com/api/1.0/tasks/318401568256461) --data-urlencode “custom\_fields:{318336795802518:318336795802520}”

I don’t get any error but the job is not updated. Do i miss something? Thanks

---

<div class="post-metadata">

**Author:** ![Shannon\_McNeil](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/shannon_mcneil/32/402_2.png) [@Shannon\_McNeil](https://forum.asana.com/u/Shannon_McNeil)\
**Post date:** [15 April 2017 01:39 UTC](https://forum.asana.com/t/api-custom-fields/1733/2 "2017-04-15T01:39:15Z")

</div>

Looping in one of Asana’s Developer Relations Leads, @Matt_Bramlage, who I’m hoping can help get your issue addressed! 🙂

---

<div class="post-metadata">

**Author:** ![Matt\_Bramlage](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/matt_bramlage/32/145_2.png) [@Matt\_Bramlage](https://forum.asana.com/u/Matt_Bramlage)\
**Post date:** [24 April 2017 23:21 UTC](https://forum.asana.com/t/api-custom-fields/1733/3 "2017-04-24T23:21:16Z")

</div>

Hi there!

Sorry for such a long delay - things have been quite active over here!

Setting custom fields with input being form data can be quite tricky. If you’re using JSON, your format is spot on:

```
"data": {
    "custom_fields":{
        318336795802518:318336795802520
    }
}

```

with form data (which is what `--data-urlencode` sends, setting the content type to `application/x-www-form-urlencoded`) you have to get the [path specifier](https://asana.com/developers/documentation/getting-started/input-output-options) just right in order for it to work. This means a successful request would be

```
curl --request PUT -H "Authorization: Bearer MYAPIKEY" \
https://app.asana.com/api/1.0/tasks/3184015682564611 \
--data-urlencode "custom_fields.318336795802518=318336795802520"

```

Hopefully this will work for you!

---

<div class="post-metadata">

**Author:** ![James\_Ferreira](https://luna1.co/8d76cd.png) [@James\_Ferreira](https://forum.asana.com/u/James_Ferreira)\
**Post date:** [23 August 2017 20:28 UTC](https://forum.asana.com/t/api-custom-fields/1733/4 "2017-08-23T20:28:11Z")

</div>

I’m not able to update the custom fields and get “errors”:[{“message”:"custom\_fields: Value is not valid JSON:

```
{ 
  "id":392096801051329,
  "custom_fields":{
    "24321869754625":"Test", 
    "188798652655039":197365168746421 
  },
  "due_on":"2017-08-01",
  "name":"James",
}   

```

It seems to be in the format provided and If I remove the custom\_fields parameter I am able to update my task. What is missing?

---

<div class="post-metadata">

**Author:** ![Pauline](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/pauline/32/13020_2.png) [@Pauline](https://forum.asana.com/u/Pauline)\
**Post date:** [15 February 2018 09:42 UTC](https://forum.asana.com/t/api-custom-fields/1733/5 "2018-02-15T09:42:00Z")

</div>

Hello,

I would like to recover my tasks with the custom field and others information but I can’t do it.  
Can you give me the URL knowing I have this one for now et I want to have theses information too.  
[https://app.asana.com/api/1.0/projects/557333570332796/tasks?opt\_fields=name,due\_on,completed,assignee,memberships.section.name&opt\_pretty](https://app.asana.com/api/1.0/projects/557333570332796/tasks?opt_fields=name,due_on,completed,assignee,memberships.section.name&opt_pretty)

Thank you !

---

<div class="post-metadata">

**Author:** ![Taylor\_Steil](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/taylor_steil/32/16940_2.png) [@Taylor\_Steil](https://forum.asana.com/u/Taylor_Steil)\
**Post date:** [8 May 2018 03:24 UTC](https://forum.asana.com/t/api-custom-fields/1733/6 "2018-05-08T03:24:54Z")

</div>

Same boat here as James\_Ferreira. I can’t seem to update the custom field no matter what kind of format I try.

```plaintext
  var headers = {
    'Authorization': 'Bearer API_KEY'
  };
  
  var formData = "custom_fields.661393451384417=123";
  
// var formData = {
// 'custom_fields': {661393451384417: 123},
// };

  //formData['custom_fields'][fieldId.toString()] = value;
  var options = {
    'method': 'put',
    'headers': headers,
    'payload': formData
  };
  var response = UrlFetchApp.fetch('https://app.asana.com/api/1.0/tasks/' + taskId, options);
  Logger.log(response.getContentText());
}

```

What are we doing wrong?

---

<div class="post-metadata">

**Author:** ![Kris\_Rhen](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/kris_rhen/32/8870_2.png) [@Kris\_Rhen](https://forum.asana.com/u/Kris_Rhen)\
**Post date:** [18 May 2018 17:07 UTC](https://forum.asana.com/t/api-custom-fields/1733/7 "2018-05-18T17:07:21Z")

</div>

Did you ever hear back from anyone? I’m stuck in the exact same situation. Thanks!

---

<div class="post-metadata">

**Author:** ![Raul\_Reyes](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/raul_reyes/32/17752_2.png) [@Raul\_Reyes](https://forum.asana.com/u/Raul_Reyes)\
**Post date:** [24 May 2018 22:31 UTC](https://forum.asana.com/t/api-custom-fields/1733/8 "2018-05-24T22:31:34Z")

</div>

This does not work. Even on regular CURL on the terminal I get “Could not interpret 683685779381761 as an identifier in custom\_fields.683685779381761”

This is the CURL request and I am trying to set an number custom field  
curl --request PUT -H “Authorization: Bearer MYKEY”   
[https://app.asana.com/api/1.0/tasks/686202313755564](https://app.asana.com/api/1.0/tasks/686202313755564)   
–data-urlencode “custom\_fields.683685779381761=36”

Please Advise

---

<div class="post-metadata">

**Author:** ![James\_Cullis](https://luna1.co/8d76cd.png) [@James\_Cullis](https://forum.asana.com/u/James_Cullis)\
**Post date:** [20 September 2018 10:05 UTC](https://forum.asana.com/t/api-custom-fields/1733/9 "2018-09-20T10:05:01Z")

</div>

Did anyone get a response to this issue? I am having the exact some problem. I’ve tried every different combination of calls without success.

Help!

Thanks

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [20 September 2018 12:41 UTC](https://forum.asana.com/t/api-custom-fields/1733/10 "2018-09-20T12:41:35Z")

</div>

Hi James,

Can you post some specific code that you’ve tried which hasn’t worked? I think having that as a starting point might make it easier to provide some advice.

---

<div class="post-metadata">

**Author:** ![Andrew13](https://luna1.co/8d76cd.png) [@Andrew13](https://forum.asana.com/u/Andrew13)\
**Post date:** [21 September 2018 11:27 UTC](https://forum.asana.com/t/api-custom-fields/1733/11 "2018-09-21T11:27:30Z")

</div>

Phil\_Seeman, nothing form the suggested above does not work. We need just working example of how to update custom field

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [21 September 2018 15:10 UTC](https://forum.asana.com/t/api-custom-fields/1733/12 "2018-09-21T15:10:56Z")

</div>

@Matt_Bramlage Hey Matt, these guys are correct - I just tried the CURL syntax you suggested above (and a bunch of variations of it) and got the same error.

For example, given a task with a text custom field having id 744020393575926, if I do:

`curl --request PUT -H "authorization: Bearer MY-PERSONAL-ACCESS-TOKEN" https://app.asana.com/api/1.0/tasks/718125926216046 --data-urlencode "custom_fields.744020393575926=A field updated from CURL"`

that results in the error `Could not interpret 744020393575926 as an identifier in custom_fields.744020393575926.`

---

<div class="post-metadata">

**Author:** ![James\_Cullis](https://luna1.co/8d76cd.png) [@James\_Cullis](https://forum.asana.com/u/James_Cullis)\
**Post date:** [21 September 2018 15:12 UTC](https://forum.asana.com/t/api-custom-fields/1733/13 "2018-09-21T15:12:01Z")

</div>

Method 1 (with 2 goes at the correct uri):

Dim uri1 As String = String.Format(“[https://app.asana.com/api/1.0/tasks/{0}?custom\_fields:{1}:{2}](https://app.asana.com/api/1.0/tasks/%7B0%7D?custom_fields:%7B1%7D:%7B2%7D)”, taskId, customFieldId, value)  
Dim uri2 = String.Format(“[https://app.asana.com/api/1.0/tasks/{0}?custom\_fields.{1}={2}](https://app.asana.com/api/1.0/tasks/%7B0%7D?custom_fields.%7B1%7D=%7B2%7D)”, taskId, customFieldId, value)

```
    Dim request As HttpWebRequest = WebRequest.Create(uri1)
    request.Headers.Add(String.Format("Authorization: Bearer {0}", token))
    request.Method = "PUT"
    request.ContentType = "application/x-www-form-urlencoded"

    Dim response As HttpWebResponse = request.GetResponse()

```

Method2:

```
Dim uri As String = String.Format("tasks/{0}", taskId)

    request.Headers.Add(String.Format("Authorization: Bearer {0}", token))
    request.Method = "PUT"
    request.ContentType = "application/json"

    Dim cfParams As New Dictionary(Of String, Object)
    cfParams.Add(customFieldId, value)

    Dim parameters As New Dictionary(Of String, Object)
    parameters.Add("custom_fields", cfParams)

    Dim json As String = JsonConvert.SerializeObject(parameters)

    Using writer As New StreamWriter(request.GetRequestStream())
        writer.Write(json)
    End Using

    Dim response As HttpWebResponse = request.GetResponse()

```

Any guidance/help would be much appreciated.

Regards

---

<div class="post-metadata">

**Author:** ![Phil\_Seeman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/phil_seeman/32/81525_2.png) [@Phil\_Seeman](https://forum.asana.com/u/Phil_Seeman)\
**Post date:** [21 September 2018 15:46 UTC](https://forum.asana.com/t/api-custom-fields/1733/14 "2018-09-21T15:46:31Z")

</div>

@James_Cullis

Your Method 2 looks very close; just add this extra line below your “SerializeObject” line:

```
Dim json As String = JsonConvert.SerializeObject(parameters)
json = "{\"data\":" + json + "}"

```

Also, I set the following on my request object (this is in C#):

```
            request.AllowWriteStreamBuffering = false;
            request.ContentType = "application/json";
            request.Accept = "Accept=application/json";
            request.SendChunked = false;
            request.ContentLength = json.Length;

```

---

<div class="post-metadata">

**Author:** ![James\_Cullis](https://luna1.co/8d76cd.png) [@James\_Cullis](https://forum.asana.com/u/James_Cullis)\
**Post date:** [21 September 2018 17:41 UTC](https://forum.asana.com/t/api-custom-fields/1733/15 "2018-09-21T17:41:45Z")

</div>

Great thanks. That has worked 🙂 I think the API reference could be clearer and provide a code example using the parameters you outlined (and maybe in a couple of different languages). Just for clarity!

---

<div class="post-metadata">

**Author:** ![Andrew13](https://luna1.co/8d76cd.png) [@Andrew13](https://forum.asana.com/u/Andrew13)\
**Post date:** [24 September 2018 11:21 UTC](https://forum.asana.com/t/api-custom-fields/1733/16 "2018-09-24T11:21:10Z")

</div>

PHP example that works for me.  
`
$taskId = ‘830265114072917’;
$customFieldId = ‘832291596179375’;
$value = ‘test value’;`

`
```
    $data = [
        'data' => [
            'custom_fields' => [
                $customFieldId => $value
            ]
        ]
    ];

    $url = 'https://app.asana.com/api/1.0/tasks/%s';
    $url = sprintf($url, $taskId);

    $fetch_request = curl_init($url);
    curl_setopt($fetch_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($fetch_request, CURLOPT_HEADER, false);
    curl_setopt($fetch_request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($fetch_request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($fetch_request, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($fetch_request, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($fetch_request, CURLOPT_POSTFIELDS, json_encode($data));

    curl_setopt($fetch_request, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        "authorization: Bearer $this->secret",
    ]);

    $response = curl_exec($fetch_request);

    $result = json_decode($response, true);

```
`

---

<div class="post-metadata">

**Author:** ![joehanna](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/joehanna/32/21945_2.png) [@joehanna](https://forum.asana.com/u/joehanna)\
**Post date:** [2 January 2019 10:15 UTC](https://forum.asana.com/t/api-custom-fields/1733/17 "2019-01-02T10:15:21Z")

</div>

Hi @Matt_Bramlage

How can I specify multiple custom fields in the one packet? I have tried making "custom\_fields  
an array but it won’t work. If custom\_fields is specified more than once, the last one wins.

I can’t work out how to create a task and specify multiple custom fields in one call.

Your assistance would be greatly appreciated.

Thanks in advance  
Joe

---

<div class="post-metadata">

**Author:** ![Matt\_Bramlage](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/matt_bramlage/32/145_2.png) [@Matt\_Bramlage](https://forum.asana.com/u/Matt_Bramlage)\
**Post date:** [3 January 2019 00:34 UTC](https://forum.asana.com/t/api-custom-fields/1733/18 "2019-01-03T00:34:43Z")

</div>

Hey all, catching back up on backlog here.

@Phil_Seeman It’s not well documented (I’ll create a follow up task to fix this) but indexing into arrays using form data is done with square brackets _both_ for offset-based arrays (like `collaborators[0]`, `collaborators[1]`) and for associative arrays (using IDs). Try:

```
curl --request PUT -H "authorization: Bearer MY-PERSONAL-ACCESS-TOKEN"
https://app.asana.com/api/1.0/tasks/718125926216046 --data-urlencode
"custom_fields[744020393575926]=A field updated from CURL"

```

This is also how you can set multiple fields at once @joehanna - by sending multiple `--data-urlencode` command line params with different custom fields indexed this way I was able to check that this did the right thing:

```
curl -v -H "Authorization: Bearer $ASANA_PERSONAL_ACCESS_TOKEN"
--request POST --data-urlencode "projects=$ASANA_SANDBOX_PROJECT"
--data-urlencode "custom_fields[166943917002516]=Some string"
--data-urlencode "custom_fields[158477440529071]=5"
https://app.asana.com/api/1.0/tasks

```

---

<div class="post-metadata">

**Author:** ![joehanna](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/joehanna/32/21945_2.png) [@joehanna](https://forum.asana.com/u/joehanna)\
**Post date:** [3 January 2019 00:56 UTC](https://forum.asana.com/t/api-custom-fields/1733/19 "2019-01-03T00:56:51Z")

</div>

Thanks for your quick reply @Matt_Bramlage. Much appreciated

---

<div class="post-metadata">

**Author:** ![p-g](https://luna1.co/8d76cd.png) [@p-g](https://forum.asana.com/u/p-g)\
**Post date:** [13 August 2022 02:01 UTC](https://forum.asana.com/t/api-custom-fields/1733/20 "2022-08-13T02:01:49Z")

</div>

Any solutions on this for JavaScript / App script?  
Getting the same error:

> [@Api & Custom Fields](https://forum.asana.com/t/api-custom-fields/1733/4):
>
> I’m not able to update the custom fields and get “errors”:[{“message”:"custom\_fields: Value is not valid JSON: { "id":392096801051329, "custom\_fields":{ "24321869754625":"Test", "188798652655039":197365168746421 }, "due\_on":"2017-08-01", "name":"James", } It seems to be in the format provided and If I remove the custom\_fields parameter I am able to update my task. What is missing?

[Next page](https://forum.asana.com/t/api-custom-fields/1733.md?page=2)
