Update contact request error

Hello team,

Trying to update contact details using Freshdesk REST API and currently facing some unexpected errors.

A bit of context: we want to store external information inside contacts custom_fields for easier access to this contact information by other agents. But setting custom property customerId inside custom_fields key-value pair property throws an error from Freshdesk API.

What can be the issue here? Are custom_fields not 100% custom?

Any info on this would be appreciated!

Detailed error meta:

{
"status": 400,
"headers": {
"date": "Fri, 02 Jun 2023 11:46:34 GMT",
"content-type": "application/json; charset=utf-8",
"transfer-encoding": "chunked",
"connection": "close",
"status": "400 Bad Request",
"pragma": "no-cache",
"x-request-id": "81c7e17f-18cc-9a69-9e97-fa0064b486ad",
"x-freshdesk-api-version": "latest=v2; requested=v2",
"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
"x-xss-protection": "1; mode=block",
"x-content-type-options": "nosniff",
"expires": "Wed, 13 Oct 2010 00:00:00 UTC",
"set-cookie": [
"_x_w=44_2; path=/; HttpOnly; secure",
"_x_m=x_c; path=/; HttpOnly; secure"
],
"x-fw-ratelimiting-managed": "true",
"x-ratelimit-total": "50",
"x-ratelimit-remaining": "48",
"x-ratelimit-used-currentrequest": "1",
"x-envoy-upstream-service-time": "143",
"x-trace-id": "00-9425973421fe1bb42657bce11dae092a-2bd7a3c0b51ac1f0-01",
"nel": "{ \"report_to\": \"nel-endpoint-freshdesk\", \"max_age\": 2592000, \"include_subdomains\": true}",
"report-to": "{ \"group\": \"nel-endpoint-freshdesk\", \"max_age\": 2592000, \"include_subdomains\": true, \"endpoints\": [{\"url\": \"[https://edge-admin.us-east-1.freshedge.net/nelreports/freshdesk\](https://edge-admin.us-east-1.freshedge.net/nelreports/freshdesk/)"}]}",
"server": "fwe"
},
"response": "{\"description\":\"Validation failed\",\"errors\":[{\"field\":\"customerId\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"}]}",
"attempts": 1,
"errorSource": "APP"
}

requests.json:

{
  "updateContact": {
    "schema": {
      "method": "PUT",
      "host": "<%= iparam.domain %>.[freshdesk.com](http://freshdesk.com/)",
      "path": "/api/v2/contacts/<%= [context.id](http://context.id/) %>",
      "headers": {
        "Authorization": "Basic <%= encode(iparam.freshdesk_api_key) %>",
        "Content-Type": "application/json"
      }
    }
  }
}

Actual request call:

  const contactDetails = JSON.stringify({
    custom_fields: {
      customerId: customerId,
    },
  });
  const response = await client.request.invokeTemplate("updateContact", {
    context: {
     id: contact.id
    },
    body: contactDetails,
  });

Thanks in advance!
Vitalii

Have you tried making the same call through “Postman” to see if you are seeing the same error or not?

@Saif
Tried to fire the same request with CURL and got the same 400 validation error

curl -v -u MY_API_KEY:X -H 'Content-Type: application/json' -X PUT -d '{ "custom_fields" : { "customerId": "1234567890"} }' 'https://griddynamics-starterkit.freshdesk.com/api/v2/contacts/151031962584'

Response:
Connection #0 to host griddynamics-starterkit.freshdesk.com left intact {"description":"Validation failed","errors":[{"field":"customerId","message":"Unexpected/invalid field in request","code":"invalid_field"}]}%

copy & paste the curl in the postman for more info.
What type is custormerId numeric or alpha?

custormerId value is of type string. FYI, It is not that important for us to have exactly this name of the property, any similar would work for us.

Tried calling this API in Postman, getting the same error. Here is the screenshot of response, let me know if you need something specific here!

please do a get of a contact from postman and put the json of the result.
https://developers.freshdesk.com/api/#view_contact

Here is response for the same customer I was trying update

{
    "active": false,
    "address": null,
    "description": null,
    "email": "aabbasi@griddynamics.com",
    "id": 151031962584,
    "job_title": null,
    "language": "en",
    "mobile": "+16102347663404",
    "name": "Aabbasi",
    "phone": null,
    "time_zone": "Eastern Time (US & Canada)",
    "twitter_id": null,
    "custom_fields": {},
    "tags": [],
    "other_emails": [],
    "facebook_id": null,
    "created_at": "2023-05-24T07:17:10Z",
    "updated_at": "2023-06-02T10:20:58Z",
    "csat_rating": null,
    "preferred_source": "phone",
    "company_id": null,
    "view_all_tickets": null,
    "other_companies": [],
    "unique_external_id": null,
    "avatar": null,
    "first_name": "Aabbasi",
    "last_name": "",
    "visitor_id": "815889b6-fb8f-4757-9714-386177eabeab",
    "org_contact_id": 1661270096565497856,
    "other_phone_numbers": []
}

I think something is not well configured in the custom fields. If I make a query to my freshdesk, the custom fields appear even though they have no content.

image

make a query of the custom fields that you have to see if they are correct.

https://developers.freshdesk.com/api/#list_all_contact_fields

Hmmm, I don’t see custom_fields in the response at all. Do you know why is that?

[
    {
        "editable_in_signup": true,
        "id": 151001078523,
        "name": "name",
        "label": "Full name",
        "position": 1,
        "required_for_agents": false,
        "type": "default_name",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Full name",
        "required_for_customers": true,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078508,
        "name": "job_title",
        "label": "Title",
        "position": 2,
        "required_for_agents": false,
        "type": "default_job_title",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Title",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": true,
        "id": 151001078509,
        "name": "email",
        "label": "Email",
        "position": 3,
        "required_for_agents": false,
        "type": "default_email",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Email",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078510,
        "name": "phone",
        "label": "Work phone",
        "position": 4,
        "required_for_agents": false,
        "type": "default_phone",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Work phone",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078511,
        "name": "mobile",
        "label": "Mobile phone",
        "position": 5,
        "required_for_agents": false,
        "type": "default_mobile",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Mobile phone",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078512,
        "name": "other_phone_numbers",
        "label": "Other phone numbers",
        "position": 6,
        "required_for_agents": false,
        "type": "default_other_phone_numbers",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Other phone numbers",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078513,
        "name": "twitter_id",
        "label": "Twitter",
        "position": 7,
        "required_for_agents": false,
        "type": "default_twitter_id",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Twitter",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078514,
        "name": "company_name",
        "label": "Company",
        "position": 8,
        "required_for_agents": false,
        "type": "default_company_name",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Company",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078515,
        "name": "address",
        "label": "Address",
        "position": 9,
        "required_for_agents": false,
        "type": "default_address",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Address",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078516,
        "name": "time_zone",
        "label": "Time zone",
        "position": 10,
        "required_for_agents": false,
        "type": "default_time_zone",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Time zone",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z",
        "choices": {
            "American Samoa": "(GMT-11:00) American Samoa",
            "International Date Line West": "(GMT-11:00) International Date Line West",
            "Midway Island": "(GMT-11:00) Midway Island",
            "Hawaii": "(GMT-10:00) Hawaii",
            "Alaska": "(GMT-09:00) Alaska",
            "Pacific Time (US & Canada)": "(GMT-08:00) Pacific Time (US & Canada)",
            "Tijuana": "(GMT-08:00) Tijuana",
            "Arizona": "(GMT-07:00) Arizona",
            "Mazatlan": "(GMT-07:00) Mazatlan",
            "Mountain Time (US & Canada)": "(GMT-07:00) Mountain Time (US & Canada)",
            "Central America": "(GMT-06:00) Central America",
            "Central Time (US & Canada)": "(GMT-06:00) Central Time (US & Canada)",
            "Chihuahua": "(GMT-06:00) Chihuahua",
            "Guadalajara": "(GMT-06:00) Guadalajara",
            "Mexico City": "(GMT-06:00) Mexico City",
            "Monterrey": "(GMT-06:00) Monterrey",
            "Saskatchewan": "(GMT-06:00) Saskatchewan",
            "Bogota": "(GMT-05:00) Bogota",
            "Eastern Time (US & Canada)": "(GMT-05:00) Eastern Time (US & Canada)",
            "Indiana (East)": "(GMT-05:00) Indiana (East)",
            "Lima": "(GMT-05:00) Lima",
            "Quito": "(GMT-05:00) Quito",
            "Atlantic Time (Canada)": "(GMT-04:00) Atlantic Time (Canada)",
            "Caracas": "(GMT-04:00) Caracas",
            "Georgetown": "(GMT-04:00) Georgetown",
            "La Paz": "(GMT-04:00) La Paz",
            "Santiago": "(GMT-04:00) Santiago",
            "Newfoundland": "(GMT-03:30) Newfoundland",
            "Brasilia": "(GMT-03:00) Brasilia",
            "Buenos Aires": "(GMT-03:00) Buenos Aires",
            "Greenland": "(GMT-03:00) Greenland",
            "Montevideo": "(GMT-03:00) Montevideo",
            "Mid-Atlantic": "(GMT-02:00) Mid-Atlantic",
            "Azores": "(GMT-01:00) Azores",
            "Cape Verde Is.": "(GMT-01:00) Cape Verde Is.",
            "Casablanca": "(GMT+00:00) Casablanca",
            "Dublin": "(GMT+00:00) Dublin",
            "Edinburgh": "(GMT+00:00) Edinburgh",
            "Lisbon": "(GMT+00:00) Lisbon",
            "London": "(GMT+00:00) London",
            "Monrovia": "(GMT+00:00) Monrovia",
            "UTC": "(GMT+00:00) UTC",
            "Amsterdam": "(GMT+01:00) Amsterdam",
            "Belgrade": "(GMT+01:00) Belgrade",
            "Berlin": "(GMT+01:00) Berlin",
            "Bern": "(GMT+01:00) Bern",
            "Bratislava": "(GMT+01:00) Bratislava",
            "Brussels": "(GMT+01:00) Brussels",
            "Budapest": "(GMT+01:00) Budapest",
            "Copenhagen": "(GMT+01:00) Copenhagen",
            "Ljubljana": "(GMT+01:00) Ljubljana",
            "Madrid": "(GMT+01:00) Madrid",
            "Paris": "(GMT+01:00) Paris",
            "Prague": "(GMT+01:00) Prague",
            "Rome": "(GMT+01:00) Rome",
            "Sarajevo": "(GMT+01:00) Sarajevo",
            "Skopje": "(GMT+01:00) Skopje",
            "Stockholm": "(GMT+01:00) Stockholm",
            "Vienna": "(GMT+01:00) Vienna",
            "Warsaw": "(GMT+01:00) Warsaw",
            "West Central Africa": "(GMT+01:00) West Central Africa",
            "Zagreb": "(GMT+01:00) Zagreb",
            "Athens": "(GMT+02:00) Athens",
            "Bucharest": "(GMT+02:00) Bucharest",
            "Cairo": "(GMT+02:00) Cairo",
            "Harare": "(GMT+02:00) Harare",
            "Helsinki": "(GMT+02:00) Helsinki",
            "Jerusalem": "(GMT+02:00) Jerusalem",
            "Kaliningrad": "(GMT+02:00) Kaliningrad",
            "Kyiv": "(GMT+02:00) Kyiv",
            "Pretoria": "(GMT+02:00) Pretoria",
            "Riga": "(GMT+02:00) Riga",
            "Sofia": "(GMT+02:00) Sofia",
            "Tallinn": "(GMT+02:00) Tallinn",
            "Vilnius": "(GMT+02:00) Vilnius",
            "Baghdad": "(GMT+03:00) Baghdad",
            "Istanbul": "(GMT+03:00) Istanbul",
            "Kuwait": "(GMT+03:00) Kuwait",
            "Minsk": "(GMT+03:00) Minsk",
            "Moscow": "(GMT+03:00) Moscow",
            "Nairobi": "(GMT+03:00) Nairobi",
            "Riyadh": "(GMT+03:00) Riyadh",
            "St. Petersburg": "(GMT+03:00) St. Petersburg",
            "Volgograd": "(GMT+03:00) Volgograd",
            "Tehran": "(GMT+03:30) Tehran",
            "Abu Dhabi": "(GMT+04:00) Abu Dhabi",
            "Baku": "(GMT+04:00) Baku",
            "Muscat": "(GMT+04:00) Muscat",
            "Samara": "(GMT+04:00) Samara",
            "Tbilisi": "(GMT+04:00) Tbilisi",
            "Yerevan": "(GMT+04:00) Yerevan",
            "Kabul": "(GMT+04:30) Kabul",
            "Ekaterinburg": "(GMT+05:00) Ekaterinburg",
            "Islamabad": "(GMT+05:00) Islamabad",
            "Karachi": "(GMT+05:00) Karachi",
            "Tashkent": "(GMT+05:00) Tashkent",
            "Chennai": "(GMT+05:30) Chennai",
            "Kolkata": "(GMT+05:30) Kolkata",
            "Mumbai": "(GMT+05:30) Mumbai",
            "New Delhi": "(GMT+05:30) New Delhi",
            "Sri Jayawardenepura": "(GMT+05:30) Sri Jayawardenepura",
            "Kathmandu": "(GMT+05:45) Kathmandu",
            "Almaty": "(GMT+06:00) Almaty",
            "Astana": "(GMT+06:00) Astana",
            "Dhaka": "(GMT+06:00) Dhaka",
            "Urumqi": "(GMT+06:00) Urumqi",
            "Rangoon": "(GMT+06:30) Rangoon",
            "Bangkok": "(GMT+07:00) Bangkok",
            "Hanoi": "(GMT+07:00) Hanoi",
            "Jakarta": "(GMT+07:00) Jakarta",
            "Krasnoyarsk": "(GMT+07:00) Krasnoyarsk",
            "Novosibirsk": "(GMT+07:00) Novosibirsk",
            "Beijing": "(GMT+08:00) Beijing",
            "Chongqing": "(GMT+08:00) Chongqing",
            "Hong Kong": "(GMT+08:00) Hong Kong",
            "Irkutsk": "(GMT+08:00) Irkutsk",
            "Kuala Lumpur": "(GMT+08:00) Kuala Lumpur",
            "Perth": "(GMT+08:00) Perth",
            "Singapore": "(GMT+08:00) Singapore",
            "Taipei": "(GMT+08:00) Taipei",
            "Ulaanbaatar": "(GMT+08:00) Ulaanbaatar",
            "Osaka": "(GMT+09:00) Osaka",
            "Sapporo": "(GMT+09:00) Sapporo",
            "Seoul": "(GMT+09:00) Seoul",
            "Tokyo": "(GMT+09:00) Tokyo",
            "Yakutsk": "(GMT+09:00) Yakutsk",
            "Adelaide": "(GMT+09:30) Adelaide",
            "Darwin": "(GMT+09:30) Darwin",
            "Brisbane": "(GMT+10:00) Brisbane",
            "Canberra": "(GMT+10:00) Canberra",
            "Guam": "(GMT+10:00) Guam",
            "Hobart": "(GMT+10:00) Hobart",
            "Melbourne": "(GMT+10:00) Melbourne",
            "Port Moresby": "(GMT+10:00) Port Moresby",
            "Sydney": "(GMT+10:00) Sydney",
            "Vladivostok": "(GMT+10:00) Vladivostok",
            "Magadan": "(GMT+11:00) Magadan",
            "New Caledonia": "(GMT+11:00) New Caledonia",
            "Solomon Is.": "(GMT+11:00) Solomon Is.",
            "Srednekolymsk": "(GMT+11:00) Srednekolymsk",
            "Auckland": "(GMT+12:00) Auckland",
            "Fiji": "(GMT+12:00) Fiji",
            "Kamchatka": "(GMT+12:00) Kamchatka",
            "Marshall Is.": "(GMT+12:00) Marshall Is.",
            "Wellington": "(GMT+12:00) Wellington",
            "Chatham Is.": "(GMT+12:45) Chatham Is.",
            "Nuku'alofa": "(GMT+13:00) Nuku'alofa",
            "Samoa": "(GMT+13:00) Samoa",
            "Tokelau Is.": "(GMT+13:00) Tokelau Is."
        }
    },
    {
        "editable_in_signup": false,
        "id": 151001078517,
        "name": "language",
        "label": "Language",
        "position": 11,
        "required_for_agents": false,
        "type": "default_language",
        "default": true,
        "customers_can_edit": true,
        "label_for_customers": "Language",
        "required_for_customers": false,
        "displayed_for_customers": true,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z",
        "choices": {
            "ar": "Arabic",
            "bs": "Bosnian",
            "bg": "Bulgarian",
            "ca": "Catalan",
            "zh-CN": "Chinese",
            "zh-TW": "Chinese (Traditional)",
            "hr": "Croatian",
            "cs": "Czech",
            "da": "Danish",
            "nl": "Dutch",
            "en": "English",
            "et": "Estonian",
            "fil": "Filipino",
            "fi": "Finnish",
            "fr": "French",
            "de": "German",
            "el": "Greek",
            "he": "Hebrew",
            "hu": "Hungarian",
            "is": "Icelandic",
            "id": "Indonesian",
            "it": "Italian",
            "ja-JP": "Japanese",
            "ko": "Korean",
            "lv-LV": "Latvian",
            "lt": "Lithuanian",
            "ms": "Malay",
            "nb-NO": "Norwegian",
            "pl": "Polish",
            "pt-BR": "Portuguese (BR)",
            "pt-PT": "Portuguese/Portugal",
            "ro": "Romanian",
            "ru-RU": "Russian",
            "sr": "Serbian",
            "sk": "Slovak",
            "sl": "Slovenian",
            "es": "Spanish",
            "es-LA": "Spanish (Latin America)",
            "sv-SE": "Swedish",
            "th": "Thai",
            "tr": "Turkish",
            "uk": "Ukrainian",
            "vi": "Vietnamese"
        }
    },
    {
        "editable_in_signup": false,
        "id": 151001078518,
        "name": "tag_names",
        "label": "Tags",
        "position": 12,
        "required_for_agents": false,
        "type": "default_tag_names",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Tags",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078519,
        "name": "description",
        "label": "About",
        "position": 13,
        "required_for_agents": false,
        "type": "default_description",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "About",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078520,
        "name": "unique_external_id",
        "label": "Unique external ID",
        "position": 15,
        "required_for_agents": false,
        "type": "default_unique_external_id",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Unique external ID",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078521,
        "name": "twitter_profile_status",
        "label": "Twitter Verified Profile",
        "position": 16,
        "required_for_agents": false,
        "type": "default_twitter_profile_status",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Twitter Verified Profile",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    },
    {
        "editable_in_signup": false,
        "id": 151001078522,
        "name": "twitter_followers_count",
        "label": "Twitter Follower Count",
        "position": 17,
        "required_for_agents": false,
        "type": "default_twitter_followers_count",
        "default": true,
        "customers_can_edit": false,
        "label_for_customers": "Twitter Follower Count",
        "required_for_customers": false,
        "displayed_for_customers": false,
        "created_at": "2023-03-13T05:26:46Z",
        "updated_at": "2023-03-13T05:26:46Z"
    }
]

In the result that you indicate, the custom_field customerId does not appear

Are you sure you have it configured correctly in the administration section?

Oh, that’s interesting!!!
I didn’t know we need to create custom fields first in the admin panel, my understanding was that we can simply populate custom_fields with different properties

I’ve tried to create custom field with the name I need in Customer Fields config section and everything seem to work fine, thanks for that!

I have a few questions regarding this:

  • If our app from marketplace needs this custom field to be present for agent that is using our app what is the best way to create this field for the agent?

  • I believe besides manual approach we can use Create A Contct Field REST API endpoint, is that correct?

  • When and how would you suggest creating this custom field? Should this be done on installation for every agent separately or once for every domain?

Any info would be helpful here!!!

Thanks,
Vitalii

1 Like

Hello.
The way to create the field is the one that I have indicated previously.
If the Rest API allows you to create fields, you will be able to do so.
The fields are domain level and I think you can create them whenever you want.

By the way, I am a Freshdesk user, not part of the Freshdesk team…:blush:

@Victor_Casajuana_Mas oh, sorry for bothering then… You made my day though, thanks a lot :slight_smile:

1 Like

@Saif @kaustavdm will anyone from freshdesk team be able to answer questions a posted above?

Thanks in advance,
Vitalii