Update the Custom Field using API

Hi Asana Team,

I have one requirement where i need to update the one text custom field with some specific value automatically whenever task has been created.

The Value of that field will be generated in specific way like ( value of another custom field value + Current Year + Last 6 digits of Asana Code of task ) and need to be updated after creation of that task.



Hi @Sachin_Subhash_Dhama,

You would use the “Update Task” API endpoint to accomplish that:

Read up on it in the docs, and let us know if you have specific questions.

Hi @Phil_Seeman
Thanks for the reply.

How do I run this API when task is being created?
Is there any listeners where I can get the task id which i can use in rest api?
Also I want to get the custom field value of created task which i can use as a parameter for rest api How do i get it?

Is there any plugin where i can write this code logic?


Yes - you have two options.

You can use the Events API - how this works is you call it periodically and it will send you all of the task activity which has occurred since the last time you called it.

Or you can use webhooks - how this works is you register to receive a webhook event each time task activity occurs.

You can read about them both in the API docs and decide which one is more appropriate for your situation.

In both cases, yes, the events include the task ID in the data that comes back from Asana. You then use that ID to read the full task record, which will include the custom field values that exist on that task.

There aren’t any plugins per se, you’ll need to write your own code. But if you’re writing in a language for which Asana has a client library available, I’d recommend you use that so as to save yourself from a bunch of code writing.

@Phil_Seeman how are you today? During my research I realized that you are super active here on the forum, I would like to congratulate you because this type of attitude helps us a lot.

I would like to take advantage of this question but try to adapt it to my case.

We are using a PHP script to create the API for creating a task in an existing project, with its collaborators and assignee person, this is working well, but now we would like to update a custom field option, this custom field has already been created in the project, but we are not able to make it work.

I’m sure that what we are not able to do is this step of updating the custom field

Would you happen to have any tips on where we could go?

Hi @RZ_T,

Can you post the code you’re using to try and update the custom field? Thanks!

sure @Phil_Seeman find it below

// First we create the task
						$result = $asana->createTask(array(
							'workspace' => $workspaceId, // Workspace ID
							'name'      => $taskName, // Name of task
							'notes'     => $taskName.' Created via Portal', // Notes
							'tags'		=> $tagName, 
							'due_on'    => $dueDate,
							'assignee'  => $Assignee, // Assign task to... [Now:Cezar - 276228680639587] [Before: Gabriel - 800859108393810 | BRUNA - 674332302363443]
							'followers' => $FollowerArr, //array('193352372098','132064102863','209184463751','276228680639582','800859108393810') // [Cleide | Richard | Operacional | Cezar | Gabriel] ## We add some followers to the task... (this time by ID), this is totally optional
							'memberships' => [
									'project' => $projectId,
									'section' => $sectionID
							'custom_field' => [
								'gid': '1203395711079141',
								'project' => $projectId,
								'enum_options': [
										'gid': '1203395711079153',
										'color': 'red',
										'enabled': true,
										'name': 'Quente',
										'resource_type': 'enum_option'
						// As Asana API documentation says, when a task is created, 201 response code is sent back so...
						if ($asana->hasError()) {
							echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
						$taskId = $asana->getData()->gid; // Here we have the id of the task that have been created
						// Now we do another request to add the task to a project
						$asana->addProjectToTask($taskId, $projectId);
						$asana->addProjectToTask($taskId, $projectId2);
						$file_data = array('file'=>$file,'finalFilename'=>$imgName,'mimeType'=>'image/jpeg');
						$asana->commentOnTask($taskId,$wMsg); //post message
						if ($asana->hasError()) {
							echo '<font color="#FF0000">Error occurred: '.$asana->responseCode.'. Error while posting data on ASANA.</font>'; //Error while assigning project to task:
						} else {
							echo POST_CREATED.' - <a href="https://app.asana.com/0/'.$projectId.'/'.$taskId.'" target="_blank">'.CLICK_HERE.'</a>'; //'Success to add the task to a project.';

Ah, OK. You are supplying too much information for the custom field option.

Instead, do something like this:

'custom_field' => [
	'1203395711079141' => '1203395711079153'

I don’t know PHP so I can’t guarantee that’s the exact right syntax, but the point is you only want to supply the gid of the custom field and the gid of the enum option to set it to.

1 Like

Great @Phil_Seeman we are going to try

@Phil_Seeman it worked! I would like to thank you very much!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.