Unable to save document (form submissions) with REST API #914
-
Hi, const formSubmission = {
form: '<some-mongo-id>',
submissionData: [
{ field: ...', value: '...' },
...
} const res = await apiFetch('<api-url>/form-submissions', {
body: JSON.stringify(formSubmission),
method: 'POST',
}) const formData = new FormData()
formData.append('_payload', JSON.stringify(formSubmission))
const res = await apiFetch('<api-url>/form-submissions', {
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
},
method: 'POST',
}) Neither of these approaches work. They return validation error that prop Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That should work... Here is a snippet pulled from a site my team built. const dataToSend = Object.entries(data).map(([name, value]) => ({
field: name,
value
}));
const req = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/form-submissions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
form: formID,
submissionData: dataToSend
})
}) |
Beta Was this translation helpful? Give feedback.
That should work...
Here is a snippet pulled from a site my team built.