Thank you, so I moved my code from get_stylistsAPI.jsw to http-functions.js and it now is giving me better results. I am now getting 500 internal server telling me “The Stylists collection was removed, so y…data, create a new collection with the same name.” The thing is I have a collection called Stylists and I have two submissions in that table. Here is how my http-functions.js file looks:
import { ok , serverError } from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;
export async function get_stylists ( request ) {
const options = {
“suppressAuth” : true ,
“suppressHooks” : true
};
**try** {
const results = **await** wixData . query ( "Stylists" ). find ( options );
const stylists = results . items . map ( item => {
**return** {
firstName : item . firstName ,
lastName : item . lastName ,
phone : item . phone ,
email : item . email ,
streetAddress : item . streetAddress ,
city : item . city ,
regionStateProvince : item . regionStateProvince ,
country : item . country ,
postalZipCode : item . postalZipCode ,
longAnswerField : item . paragraphField ,
shortAnswerField : item . shortAnswerField
};
});
**return** ok ({
headers : {
"Content-Type" : "application/json" ,
"Access-Control-Allow-Origin" : "https://example.io" ,
"Access-Control-Allow-Headers" : "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" ,
"Access-Control-Allow-Methods" : "GET, POST, OPTIONS"
},
body : {
stylists
}
});
} catch ( error ) {
console . error ( error );
**return** serverError ({
headers : {
"Content-Type" : "application/json" ,
"Access-Control-Allow-Origin" : "https://example.io" ,
"Access-Control-Allow-Headers" : "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" ,
"Access-Control-Allow-Methods" : "GET, POST, OPTIONS"
},
body : {
error : error . message
}
});
}
}