Error When Exposing Website API

I tried to expose an http get function in order to get the list of users registered to my website, and possibly use it in an external application. I will use this application to allow registered users to book online directly through the said app.

However, when I test my recently created http-function, I get an error.

This is my code for the function:

export function get_usersQuery(request) {
const options = {
headers: {
“Content-Type”: “application/json”
}
};

return wixData.query(“Members/PrivateMembersData”).find().then( (results) => {
if (results.items.length > 0) {
options.body = {
“items”: results.items
};
return ok(options);
}
}). catch ( (error) => {
options.body = {
“error”: ${error} **this** is that error that idk what it is
}
return serverError(options);
});
}

BTW: I am accessing the API correctly /_functions/usersQuery

Can anyone help me? You guys are amazing already, helping me with this would be insanely awesome.

Thanks in Advance

See the following example for details on exposing an API:

Expose and Access Site APIs

Use MyApi and MyApiClient to expose and access external APIs.

Thank you for that! I read the example, and from my understanding – I must first create a get_ which will return the promise or response object if succeeds. Then I need to create a page to expose that API using wix-fetch module?