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
Hello @BigKahuna thank you for the report, checking that today
@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:

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: \"\""]}"
Works on my side.
Are you sure you format your body properly? Error suggests that some escape '\' characters are inserted in your body
Are you self hosting ?
@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
let me try with n8n
works well with n8n, there is something we miss

What Twenty version are you hosting please ?
1.0.0
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 ?
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
}
The error might not come from the email update validation
I'm actually using the fields, not raw JSON at the moment
I agree. It's something else.
Mhmm error feedback is not ideal here, this need to be improved, noting
let me try with fields
My bet is phones
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

I tried exluding that and am getting errors then too
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
}

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 😕
Server Log of that last API call
I tried using this and that actually worked.
Do you have an ARRAY field metadata type in this object metadata definition ?
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 ...
Sorry those two are PHONE and EMAIL field metadata type I was thinking about an atomic field metadata array not a composite one
Or could it maybe be expecting an array due to my custom fields?
Mhmm
Could you please try to use 1.0.1
https://github.com/twentyhq/twenty/commit/9f04ccb94a6553f19f6d0ffd563ae6c3799acfe4
Will update now
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
Yes can you share your data model from settings (offuscate if needed)
?
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"}

thanks, no array field 🤔
BTW: Let me say a big THANK YOU for your effort in trying to help me @martmull @prastoin 🫶 !
Of course you're welcome @BigKahuna !
Will try to reproduce on my side once
1.0.2
is shippedSo 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 🤣 ?
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.Indeed, in select and multi select field settings, you will see the API values

Complete fix:
Thanks for the update. I'm over the hump and can now continue the migration :-).
great, very pleased to ear that
Thank you for your patience
Don't hesitate if you have other issues