Hi, I’m having trouble passing an object from React to Express, and then creating an airtable record in Express.
In react, i am sending an http request to Express via:
finalSubmit() {
const airtableObj = {
title: ‘hi’,
}
fetch(‘api/submit’,{
method: ‘POST’,
body: JSON.stringify(airtableObj),
headers: {“Content-Type”: “application/json”}
})
}
In Express, I am doing:
app.post(’/api/submit’, jsonParser, async (req, res) => {
const newStudy = JSON.stringify(req.body);
await console.log(newStudy);
table.create(newStudy, function(err, record) {
if (err) {console.log(err); res.json(err)} else {console.log(record), res.json(‘Success!’)}
});
})
(If I do table.create({“title”:“hi”} instead of table.create(newStudy), everything works fine)
However, I keep getting:
Class {
error: ‘INVALID_REQUEST_UNKNOWN’,
message:
‘Invalid request: parameter validation failed. Check your request data.’,
statusCode: 422 }
Sorry for the newbie question, but is there something wrong with how I am manipulating my data with JSON?
Thanks