Can't Add additionalEmails via API

As far as I can tell, I should be able to send an array, e.g. "additionalEmails": ["gruen@blau.de"]. But when I do, I get back this error: 400 - "{"statusCode":400,"error":"SyntaxError","messages":["Unexpected token 'g', \"gruen@blau.de\" is not valid JSON"]}" Honestly don't know what this means or what to do about it.
42 Replies
martmull
martmull3mo ago
Hello @BigKahuna thank you for the report, checking that today
martmull
martmull3mo ago
@BigKahuna I might miss something, it looks to work properly on our side. Can you share your request body? Here a working example to create one person:
{
"name": {
"firstName": "Raphaelle",
"lastName": "Sporer"
},
"emails": {
"primaryEmail": "agustina.nolan@hotmail.com",
"additionalEmails": [
"agustina.nolan+test1@hotmail.com",
"agustina.nolan+test2@hotmail.com"
]
}
}
{
"name": {
"firstName": "Raphaelle",
"lastName": "Sporer"
},
"emails": {
"primaryEmail": "agustina.nolan@hotmail.com",
"additionalEmails": [
"agustina.nolan+test1@hotmail.com",
"agustina.nolan+test2@hotmail.com"
]
}
}
No description
BigKahuna
BigKahunaOP3mo ago
I'll recheck later today and get back to you. I tried passing this again: "emails": { "primaryEmail": "blau@gruen.de", "additionalEmails": [ "gruen@blau.studio" ] } And I am now getting an error basically saying that I am not passing an array but a string: 400 - "{"statusCode":400,"error":"BadRequestException","messages":["malformed array literal: \"\""]}"
martmull
martmull3mo ago
{"emails": { "primaryEmail": "blau@gruen.de", "additionalEmails": [ "gruen@blau.studio" ] }}
{"emails": { "primaryEmail": "blau@gruen.de", "additionalEmails": [ "gruen@blau.studio" ] }}
Works on my side. Are you sure you format your body properly? Error suggests that some escape '\' characters are inserted in your body
Prastoin
Prastoin3mo ago
Are you self hosting ?
BigKahuna
BigKahunaOP3mo ago
@prastoin I am. And I tried removing the emails too. Then I get new errors, e.g. "unexpected end of JSON" and such. Not sure what the underlying cause of all this is. Using n8n for my API calls. I get the impression it's not really the JSON, but rather how it is interpreted server-side
martmull
martmull3mo ago
let me try with n8n
martmull
martmull3mo ago
works well with n8n, there is something we miss
No description
Prastoin
Prastoin3mo ago
What Twenty version are you hosting please ?
BigKahuna
BigKahunaOP3mo ago
1.0.0
Prastoin
Prastoin3mo ago
Mmhmm indeed should be good Are you updating a custom object field or a standard object field ? Also is it the only update sent to through the payload no others fields ?
BigKahuna
BigKahunaOP3mo ago
Also custom object fields. Here's what I'm sending: { "body": { "academicTitle": "", "salutation": "Herr", "formOfAddress": "Du", "nickname": "Andi", "language": "DE", "name": { "firstName": "firstName", "lastName": "lastName" }, "emails": { "primaryEmail": "blau@rot.de", "additionalEmails": [ "gruen@blau.com", "rot@gelb.de" ] }, "linkedinLink": { "primaryLinkUrl": "https://linkedin.com/in/profile/someone" }, "jobTitle": "Geschäftsführer", "phones": "", "companyId": "000711d4-6e74-4fc2-8d43-27c7302f0b1b" }, "headers": { "Authorization": "hidden", "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/;q=0.9, image/;q=0.8, /;q=0.7" }, "method": "POST", "uri": "https://crm.mydomain.com/rest/people", "gzip": true, "rejectUnauthorized": true, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "encoding": null, "json": false, "useStream": true }
Prastoin
Prastoin3mo ago
The error might not come from the email update validation
BigKahuna
BigKahunaOP3mo ago
I'm actually using the fields, not raw JSON at the moment I agree. It's something else.
Prastoin
Prastoin3mo ago
Mhmm error feedback is not ideal here, this need to be improved, noting
martmull
martmull3mo ago
let me try with fields
Prastoin
Prastoin3mo ago
My bet is phones
martmull
martmull3mo ago
with fields, using the PUT endpoint to update a record, it does not seems to work properly with n8n But no error though, just wrong data after update
No description
BigKahuna
BigKahunaOP3mo ago
I tried exluding that and am getting errors then too
BigKahuna
BigKahunaOP3mo ago
Even this doesn't work: { "body": { "academicTitle": "", "salutation": "Herr", "formOfAddress": "Du", "nickname": "Andi", "language": "DE", "name": { "firstName": "firstName", "lastName": "lastName" }, "linkedinLink": { "primaryLinkUrl": "https://linkedin.com/in/profile/someone" }, "jobTitle": "Geschäftsführer", "companyId": "000711d4-6e74-4fc2-8d43-27c7302f0b1b" }, "headers": { "Authorization": "hidden", "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/;q=0.9, image/;q=0.8, /;q=0.7" }, "method": "POST", "uri": "https://crm.inside360.studio/rest/people", "gzip": true, "rejectUnauthorized": true, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "encoding": null, "json": false, "useStream": true }
No description
BigKahuna
BigKahunaOP3mo ago
I'm actually trying to migrate all my data via the API. SOmeone messed up the field data in Pipedrive and using Excel would take me even longer 😕
BigKahuna
BigKahunaOP3mo ago
Server Log of that last API call
BigKahuna
BigKahunaOP3mo ago
I tried using this and that actually worked.
Prastoin
Prastoin3mo ago
Do you have an ARRAY field metadata type in this object metadata definition ?
BigKahuna
BigKahunaOP3mo ago
Two, actually: The additionalEmails and additionalPhones. But removing them did not eliminate the error. Don't see any other array and am not forming one on purpose ...
Prastoin
Prastoin3mo ago
Sorry those two are PHONE and EMAIL field metadata type I was thinking about an atomic field metadata array not a composite one
BigKahuna
BigKahunaOP3mo ago
Or could it maybe be expecting an array due to my custom fields?
BigKahuna
BigKahunaOP3mo ago
Will update now
Prastoin
Prastoin3mo ago
Erf this won't have an impact anw as the data already exists in local We're currently about to ship 1.0.2 that contains a retro-compatible command Unfortunately I won't be able to give your issue a deep sight until at least 2 hours When the 1.0.2 is shipped I'll let you know so we could put the array issue on the side but honestly would be suprising to be this
martmull
martmull3mo ago
Yes can you share your data model from settings (offuscate if needed) ?
BigKahuna
BigKahunaOP3mo ago
If I have a custom field such as this: salutation Type:string enum HERR FRAU MR MS What is the expected format for the API? I am using {"salutation": "Herr"}
BigKahuna
BigKahunaOP3mo ago
No description
martmull
martmull3mo ago
thanks, no array field 🤔
BigKahuna
BigKahunaOP3mo ago
BTW: Let me say a big THANK YOU for your effort in trying to help me @martmull @prastoin 🫶 !
Prastoin
Prastoin3mo ago
Of course you're welcome @BigKahuna ! Will try to reproduce on my side once 1.0.2 is shipped
BigKahuna
BigKahunaOP3mo ago
So I just deleted one field after another until the request went through. What I learned: It's the custom fields that are the problem: academicTitle, salutation and formOfAddress specifically. Apparently, filling them via {"fieldName": "value"} is not cutting it and causing issues. Not sure of the cause though. Should I be using a different syntax? Further testing: Apparently the API expects me to transmit the values for these custom fields in all caps (e.g. "HERR" or "SIE". Even though I set "Herr" and "Sie" as values in the custom fields themselves. BTW: They are also displayed as "Herr" and "Sie" on the frontend after creation. Am I the first one to try this or was everyone else that much smarter 🤣 ?
martmull
martmull3mo ago
jeez, they are select and multiSelect fields, did not catch that, indeed value should be set specifically for those No there is no doc for those, we really need one 😅 lets me provide you an example {"accademicTitle": [], ...} (instead of {"accademicTitle": "", ...}) should fix the issue accademicTitle is a multiSelect, so expecting an array value, not a string (this is what the error message says, very badly 😑) Sorry for the disturbance — we shouldn't have to struggle this much over such an issue.
martmull
martmull3mo ago
Indeed, in select and multi select field settings, you will see the API values
No description
martmull
martmull3mo ago
Complete fix:
{
"academicTitle": [],
"salutation": "HERR",
"formOfAddress": "DU",
...
}
{
"academicTitle": [],
"salutation": "HERR",
"formOfAddress": "DU",
...
}
BigKahuna
BigKahunaOP3mo ago
Thanks for the update. I'm over the hump and can now continue the migration :-).
martmull
martmull3mo ago
great, very pleased to ear that Thank you for your patience Don't hesitate if you have other issues

Did you find this page helpful?