I have been trying to add a database record using a http-function POST through a URL. I am getting the error: " Failed to load resource: the server responded with a status of 404 " This is the code in http-functions.js file;
import { ok, badRequest,notFound, serverError,created } from 'wix-http-functions';
import wixData from 'wix-data';
export function post_addPayment(request) {
const data = request.body; // Assuming you send the data as JSON in the request body
// Define the collection name and data schema
const collectionName = 'Payments';
const dataSchema = {
"phone": data.phone,
"amount": data.amount
};
// Insert the record into the database
return wixData.insert(collectionName, dataSchema)
.then(result => {
return ok({ "body": "Record added successfully" });
})
.catch(error => {
return badRequest({ "body": "Error adding record" });
});
}
export function get_payments(request){
let options={
"headers":{
"content-Type": "application/json"
}
};
let auth = {
"suppressAuth": true,
"suppressHooks": true
};
return wixData.query("Payments")
.find(auth)
.then( (results) => {
if(results.items.length>0){
options.body={
"items":results.items
}
return ok(options);
}
options.body ={
"error": 'Email account ${email} not subscribed'
};
return notFound(options)
} )
.catch ((error)=>{
options.body={
"error":error
};
return serverError(options)
})
}
export function post_add(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then( (body) => {
// insert the item in a collection
return wixData.insert("Payments", body);
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
The adding url for the above code is;
https://ericbelyon.wixsite.com/test/_functions/addPayment/
Anyone with an idea how this can be resolved ?