API3
jeff_dte at June 5th, 2017 14:04 — #1
I'm trying to create/edit contacts with addresses, phone numbers, and email addresses. I'm using C#, so there's no client available. I'm able to create/edit contacts with only names using query string parameters (request bodies seem to be ignored aside from creating the auth hash?), but I don't seem to be able to get the format correct for the rest. For example, I've tried to hit the endpoint:
contacts/59306dfbb503ae69cfa1f792.json?partial=1&first_name=modified2&last_name=name&emails=[%7B%22type%22:%22work%22,%22value%22:%22fake@ddress.com%22%7D]
... and it tells me that emails must be an array. Doing something similar with addresses results in an error saying that there must be an array with exactly one address. What is the correct format for these? Should the information be in the POST/PUT body or is it always ignored? Thank you.
liam at June 6th, 2017 07:39 — #2
Hello Jeff,
I would always suggest sending updates as a post JSON body rather than in the url query string. Here I found an example of how to do it with HtttpWebRequest
.
If you want to use the url's query string, you will need to encode arrays and objects as follows:
contacts/59306dfbb503ae69cfa1f792.json?partial=1&first_name=modified2&last_name=name&emails[][type]=work&emails[][value]=fake@ddress.com&emails[][type]=work&emails[][value]=fake@address2.com
This will parse the following params:
Parameters: {"partial"=>"1", "first_name"=>"modified2", "last_name"=>"name", "emails"=>[{"type"=>"work", "value"=>"fake@ddress.com"}, {"type"=>"work", "value"=>"fake@address2.com"}], "add_new_contact"=>"true"}
But this is an awkward format as the array of objects depends on the order in which the nested object properties are sent, so I would again advise sending a JSON post body instead of the query string
Kind regards,
Liam
jeff_dte at June 6th, 2017 08:35 — #3
In that case, I appear to have a problem with signing the request. I'm using the C# sample code and the provided example, but my pre-HMAC-SHA256 string differs in the request body portion. Here's what I get:
mine: 4e0046526381906f7e000002.1401366488.PUT.813617379a1e9903964546d9668042cb39c5d73f.77a6f18527cad414cf63541918fb86a9dffe4159
example:
4e0046526381906f7e000002.1401366488.PUT.813617379a1e9903964546d9668042cb39c5d73f.9970204aa4ec9813b84652747b33142ac6dc2821
Everything but the body appears to be correct. My body:
string requestBody = "{\"first_name\":\"John\", \"last_name\":\"Doe\"}";
For what it's worth, this says the request body hashes to 77a6f18527cad414cf63541918fb86a9dffe4159 also.
liam at June 6th, 2017 09:35 — #4
Your value ("77a6f18527cad414cf63541918fb86a9dffe4159") is correct Jeff. The Post body & URL in the example were updated but the hash values are outdated.
I'm updating our docs now. I'm getting the same values as yourself for the hash functions
jeff_dte at June 6th, 2017 10:58 — #5
So, I've made progress. I've moved everything into the POST body and my signature seems fine. With this body, however:
{"first_name":"jeff","last_name":"test","emails":[{"type":"work","value":"fake@ddress.com"}],"partial":1}
I get this response:
{"status":400,"message":"Invalid request data","error_name":"invalid_request_data","error_message":"A validation error has occurred","errors":{"last_name":"Lastname or company name must be provided","company_name":"Lastname or company name must be provided"}}
Am I missing something simple?
jeff_dte at June 7th, 2017 09:31 — #6
To follow up on this, I'm hitting the "contacts.json" endpoint with the POST body indicated in the previous post. If I hit "contacts.json?last_name=test" with the same body, I get a contact with only the last name set. The body is ignored entirely, which was my original problem.
EDIT: I think I've sorted it out. I wasn't setting the content type header. Thank you for the help!
Powered by Discourse, best viewed with JavaScript enabled