Update contact not working

Hi I am trying to update the contact on the other_companies field.
Docs mention an array of hashes, not sure what this means. What is the correct syntax?
I tried:

curl -u ${fd_api_key}:X -X PUT -H "Content-Type: application/json" -d '{"other_companies":["company_id": "30000147482"]}' "https://dataserviceshub.freshdesk.com/api/v2/contacts/30009644980"

error: {“code”:“invalid_json”,“message”:“Request body has invalid json format”}

Also tried

curl -u ${fd_api_key}:X -X PUT -H "Content-Type: application/json" -d '{"other_companies":["30000147482"]}' "https://dataserviceshub.freshdesk.com/api/v2/contacts/30009644980"

Error: {“description”:“Validation failed”,“errors”:[{“field”:“other_companies”,“message”:“It should contain elements of type key/value pair only”,“code”:“datatype_mismatch”}]}

please help.

1 Like

Hi Rakesh,

Welcome to community :slight_smile:

You need to provide other_companies in this format:

"other_companies":[
     { "company_id":25, "view_all_tickets":true },
     { "company_id":26, "view_all_tickets":false }
], 

Your request should look like this:

curl -u ${fd_api_key}:X -X PUT -H "Content-Type: application/json" -d '{"other_companies":[{company_id: "30000147482"}]}' "https://dataserviceshub.freshdesk.com/api/v2/contacts/30009644980"

Let me know if this doesn’t work. :slight_smile:

2 Likes

I’m trying a similar thing, but with code copied directly from Freshdesk

curl -v -u ${fd_api_key}:X -H ‘Content-Type: application/json’ -X PUT -d ‘{ “name”:“Clark Kent”, “job_title”:“Journalist”, “other_emails”: [“louis@freshdesk.com”, “jonathan.kent@freshdesk.com”] }’ ‘https://silhelpdesk.freshdesk.com/api/v2/contacts/432

gets back
curl: (3) bad range in URL position 44:
Kent, job_title:Journalist, other_emails: [louis@freshdesk.com, jonathan.kent@freshdesk.com] }

Hi @kodemonki

This command will help you to update an existing contact details of id 432

Just a gentle check, did you replace 432 with the required valid Id?

This error is possibly due to the cURL URL Globbing.
Can you try adding --globoff at the end of the command and execute it.

Yes, but here’s a more complete example.

PS C:\Users\kodemonki> curl -v -u ${fd_api_key}:X -H ‘Content-Type: application/json’ -X PUT -d ‘{ “name”:“Bob Dylan” }’ ‘https://silhelpdesk.freshdesk.com/api/v2/contacts/72013213777
curl: (3) unmatched close brace/bracket in URL position 7:
Dylan }
^

PS C:\Users\kodemonki> curl -v -u ${fd_api_key}:X -H ‘Content-Type: application/json’ -X PUT -d ‘{ “name”:“Bob Dylan” }’ ‘https://silhelpdesk.freshdesk.com/api/v2/contacts/72013213777’ --globoff

  • Closing connection -1
    curl: (3) URL using bad/illegal format or missing URL
    …lots of other stuf…
    {“code”:“invalid_json”,“message”:“Request body has invalid json format”}* Connection #0 to host silhelpdesk.freshdesk.com left intact

Seems, the issue is with json or its format.
Can you try executing this command with your API key

curl -v -u yourapikey:X -H 'Content-Type: application/json' -X PUT -d '{ "name":"Bob Dylan", "job_title":"Journalist", "other_emails": ["louis@freshdesk.com", "jonathan.kent@freshdesk.com"] }' 'https://silhelpdesk.freshdesk.com/api/v2/contacts/72013213777' --globoff

It does look like that, but I’m surprised the API docs would have an error in their examples.

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