# Unable to fetch custom fields through asana API

**URL:** <https://forum.asana.com/t/unable-to-fetch-custom-fields-through-asana-api/83412>\
**Category:** API & Developers\
**Tags:** custom-fields, tasks\
**Created:** [13 May 2020 22:00 UTC](https://forum.asana.com/t/unable-to-fetch-custom-fields-through-asana-api/83412 "2020-05-13T22:00:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon97086195](https://luna1.co/8d76cd.png) [@anon97086195](https://forum.asana.com/u/anon97086195)\
**Post date:** [13 May 2020 22:00 UTC](https://forum.asana.com/t/unable-to-fetch-custom-fields-through-asana-api/83412/1 "2020-05-13T22:00:33Z")

</div>

I am trying to fetch task details after update through asana API. I am able to fetch all task details except custom fields. It is giving me an error like string to array conversion. Could someone please help me out?  
Below is the code I am using for this:

```
$data = array(
    "data" => array(
        "workspace" => "XXXXXXXXXXXXXXXXXX",
       // "projects" => array('XXXXXXXXXXXXXX'),
        "name" => $row[1],
        "notes" => $row[5],
        "assignee" => $id,
		 "custom_fields" => $cust,
		
    )
);

$data_json = json_encode($data);

$url1 = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
 $api = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_USERPWD, $api);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
// Execute curl and assign returned data
$response = curl_exec($ch);
 
// Close curl
curl_close($ch);
$html = json_decode($response, true);

$asana_id= $html['data']['gid'];
$assignee_gid = $html['data']['assignee']['gid'];
$assignee = $html['data']['assignee']['name'];
$description= $html['data']['notes'];
//to fecth custom_fields
echo $html['data']['custom_fields']['gid'];

```

I am facing issue here: echo $html[‘data’][‘custom\_fields’][‘gid’];

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:06 UTC](https://forum.asana.com/t/unable-to-fetch-custom-fields-through-asana-api/83412/2 "2025-05-30T19:06:53Z")

</div>

Closed on 30 May 2025 19:06 UTC


