Hello,
I am working on a way to receive webhooks from my POS provider. I have this working in concept but I am wondering if anybody can point me to a method by which I can validate a secret that will be provided to my POS provider to be in the JSON they send before proceeding with inserting the data into my database.
I used this: https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions
Ideally I would also map their JSON object to specific fields in the database since it includes a ton of information that I do not actually need.
So far I added this to my http-functions.js and it works:
import { created, serverError } from 'wix-http-functions';
import wixData from 'wix-data';
export function post_XXXX(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("XXXXX", body);
} )
.then((results) => {
options.body = {
"inserted": results
};
return created(options);
})
// something went wrong
.catch((error) => {
options.body = {
"error": error
};
return serverError(options);
});
}
Appreciate any help you can provide.