So I’m trying to insert data into a database via http POST from my iOS app, and… it works about 30% of the time. The remaining time I’m getting this back from the server:
[“error”: {
errorGroup = User;
name = JsonSyntaxError;
}]
(the first of my 4 database fields is called ‘name’, which is a string- the rest are all numbers)
Thing is, I’ve written a test function to resubmit exactly the same POST request data repeatedly so I’m sure (to the best of my knowledge) that the JSON I’m sending it is fine, but as I say it only works about 30% of the time, the remaining time I get this syntax error response.
Here’s what I’m using to on the Wix side:
export function post_scoreboard(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then( (body) => {
// insert the item
return wixData.insert("Scoreboard", body);
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}