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?
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?
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: Keap REST API
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:
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