Hello, I’m new to wix so I apologize if my error is trivial
I have established a REST API to communicate with some collection (database) stored on my website, my intent is that costumers could use an external app to submit post request to that database. I’ve opened read, write and edit permissions for anyone.
While reading (GET function) works as expected, I’m getting a 403 Forbidden response for PUT/POST requests.
I’ve been using the provided functions from this link - https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions
edited to match my collection.
As the permissions are not the problem, I am puzzled by this response code, My suspicion is that my JSON format is not the same as wix-data is expecting to parse, specifically I’m not sure how to treat the auto generated columns of my collection (_id, _owner etc…)
I’ve tried JSON formats as such (for POST requests):
{"_id":"","_owner":"","_createdDate":"","_updatedDate":"","content":"pod","title":"kip"}
{"content":"pod","title":"kip"}
and as a list containing either of these formats
I also tried editing the “content” and “title” values of a JSON a received from a GET request and post it with a PUT request
Any help would be appreciated!
thanks
Edit: My post function
export function post_order(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then( (body) => {
let entry = {
"title": body["title"],
"content": body["content"]
}
// insert the item in a collection
return wixData.insert("orders", entry);
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}