# Creating New Task with Custom Fields

**URL:** <https://forum.asana.com/t/creating-new-task-with-custom-fields/5397>\
**Category:** API & Developers\
**Created:** [25 July 2017 17:24 UTC](https://forum.asana.com/t/creating-new-task-with-custom-fields/5397 "2017-07-25T17:24:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![College\_of\_Humanitie](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/college_of_humanitie/32/5275_2.png) [@College\_of\_Humanitie](https://forum.asana.com/u/College_of_Humanitie)\
**Post date:** [25 July 2017 17:24 UTC](https://forum.asana.com/t/creating-new-task-with-custom-fields/5397/1 "2017-07-25T17:24:45Z")

</div>

Hi,

I am trying to create new task using php curl . I have trouble creating custom fields while creating the task . I am not sure how the format of the custom fields needs to be.

I am getting this phrase in the error “phrase”:“19 drunk urchins look hungrily”.

/\* Example 1 \*/

$customFields = array(  
3456 =\>10800,  
);  
$cust = json\_encode($customFields);

$fields = array(

‘notes’ =\> $notes,  
‘name’ =\> $name,  
‘projects’ =\> $pid,  
‘custom\_fields’ =\>$cust,  
);

$curl = curl\_init();  
curl\_setopt\_array($curl, array(  
CURLOPT\_URL =\> $url,  
CURLOPT\_POST =\> 1,  
CURLOPT\_POSTFIELDS =\> $fields,  
));  
curl\_setopt($curl, CURLOPT\_HTTPHEADER, array($header));

/\* Example 2 \*/

I tried creating custom fields using this too

$customFields = array(array(  
‘id’ =\>3456,  
‘name’=\> ‘Cost’,  
‘number\_value’=\>10500,  
‘type’=\>‘number’,  
));  
$cust = json\_encode($customFields);

Please assist.

Thanks,  
Kavitha.

---

<div class="post-metadata">

**Author:** ![Jeff\_Schneider](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jeff_schneider/32/146_2.png) [@Jeff\_Schneider](https://forum.asana.com/u/Jeff_Schneider)\
**Post date:** [26 July 2017 00:18 UTC](https://forum.asana.com/t/creating-new-task-with-custom-fields/5397/2 "2017-07-26T00:18:10Z")

</div>

Hi Kavitha,

You’ve found an obscure bug in our API errors, congratulations! The good news is that it should be a simple fix on your side.

Our API doesn’t expect the nested custom fields object to be a string. If you remove line 4 `$cust = json_encode($customFields); ` where you encode the array and then set `custom_fields’ =>$customFieldst` on line 11, it should work.

---

<div class="post-metadata">

**Author:** ![College\_of\_Humanitie](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/college_of_humanitie/32/5275_2.png) [@College\_of\_Humanitie](https://forum.asana.com/u/College_of_Humanitie)\
**Post date:** [28 July 2017 18:27 UTC](https://forum.asana.com/t/creating-new-task-with-custom-fields/5397/3 "2017-07-28T18:27:21Z")

</div>

Thanks Jeff. Yes It worked.

Thanks,  
Kavitha.

---

<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:09 UTC](https://forum.asana.com/t/creating-new-task-with-custom-fields/5397/4 "2025-05-30T19:09:17Z")

</div>

Closed on 30 May 2025 19:09 UTC


