Update Contact Custom Field


(Seth Webster) #1

I am trying to use the REST API to update a custom field for a contact. I have looked up the database name from Admin->Settings (customField) and have read that there needs to be an underscore preceding the database name (_customField). The data type for my field is text. Here is the request I am sending to PATCH “https://api.infusionsoft.com/crm/rest/v1/contacts/userId?access_token=access_token” (userID and access_token values replaced of course)

custom_fields: [
{
content: ‘test’,
id: ‘_customField’
}
]

And here is the response I get from Infusionsoft:

message: 'Input value is invalid: _customField'

The docs seem to say that the content should be an object, but do not specify what that object should contain.

Are there errors in my request and how can I successfully update a contact custom field?


Can't figure out how to add custom_fields in contact create
(John Borelli) #2

I know id has to be an integer. content would be something like {"_customField":“test”}


(Seth Webster) #3

Thanks John. I think I have it figured out. Here is what I did:

GET to /contactCustomFields and loop through the returned data comparing the label to ‘customField’. Once I found the element that matched the label, I grabbed the id from it and made a PATCH request to /contacts/userId

custom_fields: [
{
content: ‘test’,
id: IdFromLoop
}
]

And that seems to work. But it also seems very clunky. It is kinda silly to have to make two requests (find field id, then send data) just to update a contact. And my inner programmer voice tells me that looping through data like that is not great for performance. Is there a better way to go about doing this?


(Jon Smith) #4

The issue is that the Id should be a numeric value. In essence you are saying update custom field 17 with this data as an example. The name of the custom field isn’t needed since the id will map it to the correct field for that contact record.

The List Contact Custom Fields GET will get the id needed to update the correct value: https://developer.infusionsoft.com/docs/rest/#!/Contact/listCustomFieldsUsingGET

Assuming that you are wanting to update a custom field that is text and returned an id of 13 this would be what is passed:

custom_fields: [
{
content: “test”,
id: “13”
}
]


(Mike Garcia) #5

Is there a way to submit an array of custom fields to update by just giving the ContactId of the contact to be updated something like:

		$call = new xmlrpcmsg("DataService.updateCustomField", array(
		php_xmlrpc_encode($this->api_key), 		#The encrypted API key
		php_xmlrpc_encode(intval($CID)),		#The contact ID
		php_xmlrpc_encode($custom_fields),		#The contact details

This is the data I am trying to save:

"Title"               => $fields['inf_field_Title'],
"FirstName"           => $fields['inf_field_FirstName'],
"LastName"            => $fields['inf_field_LastName'],
"Email"               => $fields['inf_field_Email'],
"Phone1"              => $fields['inf_field_Phone1'],
"City"                => $fields['inf_field_City'],
"PostalCode"  	      => $fields['inf_field_PostalCode'],
"ApplicationInterest" => $fields['inf_custom_ApplicationInterest'],
"StructureType1"      => $fields['inf_custom_StructureType1'],
"BuildRequest"        => $fields['inf_custom_BuildRequest'],
"Comments"            => $fields['inf_custom_Comments']

(Bradley Booth) #6

The call you are referencing is updating the actual custom field definition. Both the XML/RPC and REST APIs support setting custom fields when updating a contact. DataService.update allows for updating custom fields on a contact and the REST update contact allows for it as well.

For XML/RPC you use _fieldName example _shoeColor. For REST you provide a custom_fields array using the actual numeric id of the custom field

custom_fields: [
  {
   content: 'test',
   id: 123
  }
]```