I have created a simple Http request API for GET method, where this API will return all information in my database(collection).
When i fetch the API from Wix webpage or directly from any browser, it will success and return all the information.
But when i try to call the API from another 3rd party programs, it will return bad request (400). A similar error also can be trigger by testing this API in a REST API Testing website: https://resttesttest.com/ (this website shows HTTP 0 error, but i know it is bad request (400) because i used fiddler to show the http request information.)
These are my http request source code:-
export async function get_getunitstatus(request){
const response = {
“headers”: {
“Content-Type”: “application/json”,
“Access-Control-Allow-Origin”: “*”,
“Access-Control-Allow-Methods”: “GET, POST, PUT, DELETE, OPTIONS”,
}
};
//let queryresult;
await wixData.query(“BookingAppDatabase”)
.ascending(“entry”)
.find()
.then((results) => {
//console.log(results.items.length);
response.body = {“items”: results.items};
})
return ok(response);
}
and this is the url to call the http request:-
https://databasefujr.com/_functions/getunitstatus
Anyone have any ideas what causes the failure?
Thanks.