@heatherzirajones
I am surely not the best choice for help in this case, but take a look at this example one…
Perhaps you will find some differences between it and your own version.
import {created, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function post_myFunction(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.text()
.then( (body) => {
// insert the item in a collection
return wixData.insert("myUserCollection", JSON.parse(body));
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
And here another one, out of the mentioned example…
export function post_rating(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then((body) => {
return updateStatistics(body["_id"], body["rating"]);
})
.then((results) => {
options.body = {
"inserted": results
};
return created(options);
})
// something went wrong
.catch((error) => {
options.body = {
"error": error
};
return serverError(options);
});
}
async function updateStatistics(productId, rating) {
// Get the rating statistics for the current recipe from the "Ratings" collection.
let stats = await wixData.get('Ratings', productId);
// If statistics data already exist for this recipe:
if (stats) {
stats.rating += rating; // Add the new rating to the total rating points.
stats.count += 1; // increment to indicate one more rating
// Update the new product statistics in the "review-stats" collection.
return wixData.update('Ratings', stats)
}
//If no statistics data exists for this product, create a new statistics item.
stats = {
// Set the statistics item's ID to the current recipe's ID.
_id: productId,
// Set the statistics item's rating to the rating entered by the user.
rating: rating,
// Set the statistics item's ratings count to 1 because this is the first rating.
count: 1
};
// Insert the new recipe statistics item into the Ratings collection.
return wixData.insert('Ratings', stats)
}
Link: Velo: Exposing a Site API with HTTP Functions | Help Center | Wix.com