I'm getting a validation error updating custom fields on a contact

I’m trying to update custom fields with the REST API on a contact. When I make the request my response message is

"description"=>"Validation failed"

All of my custom fields have the same error on them:

"errors"=>
  [{"field"=>"cf_payment_status", "message"=>"Unexpected/invalid field in request", "code"=>"invalid_field"}]

I’m not sure what the invalid field refers to. All of my custom fields are created in FreshChat and FreshDesk. Is there a specific structure to the request Params that I need to follow? There isn’t any documentation on updating custom_fields.

Here is a sample of my params:

{:cf_payment_status=>nil,
 :cf_contact_payment_gateway_identifier=>"REDACTED",
 :cf_order_number=>nil,
 :cf_order_id=>nil,
 :cf_team_id=>"REDACTED",
 :cf_team_name=>"My Demo Team",
 :cf_product_name=>nil,
 :cf_subdomain=>"nopreferenceshere",
 :cf_currency=>"USD",
 :cf_confirming_gateways=>"false"}

I’ve also tried nesting the params under a custon_fields key, but this still results in the invalid field validation error.

UPDATE:
I’ve discovered what is wrong, and as I mentioned before this could have been avoided if there were documentation on how to update custom fields as it is not very intutive.

You need to define your custom fields without the “cf_” prefix.

"custom_fields"=>{
  "your_custom_field_name_here"=>"some value",
  "your_custom_field_date_value"=>"2024-06-03"}
}

This should help if anyone else is looking to update custom fields and getting an invalid field error.

PS: Keep in mind that date fields must follow the YYYY-MM-DD format.

1 Like