Creating New Task with Custom Fields

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.

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.

1 Like

Thanks Jeff. Yes It worked.

Thanks,
Kavitha.

1 Like