Expose http-function error

here is my code

// In http-functions.js

import {ok, notFound, serverError} from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;

export function get_myFunction(request) {
let options = {

“headers” : {
“Content-Type” : “application/json”
}

};
let table = ‘Members/PrivateMembersData’

let dataOptions = {
“suppressAuth” : true ,
“suppressHooks” : false
};

// query a collection to find matching items
return wixData.query( “Members/PrivateMembersData” ,dataOptions)
.eq( “firstName” , request.path[ 5 ])
.eq( “lastName” , request.path[ 6 ])
.find()
.then( (results) => {
// matching items were found
if (results.items.length > 0 ) {
options.body = {
“items” : results.items
};
return ok(options);
}
// no matching items found
options.body = {
“error” : '${request.path[5]} ${request.path[6]}' was not found
};
return notFound(options);
} )
// something went wrong
. catch ( (error) => {
options.body = {
“error” : error
};
return serverError(options);
} );
}

but im getting this error

{“error”:{“name”:“Error”,“errorGroup”:“User”,“code”:“WD_PERMISSION_DENIED”}}

can anyone help me on this plss

The problem is that you are accessing the Private Members Database without suppressing authorization. See the options parameter here .

Basically do this:

let options = {
   "suppressAuth": true,
   "suppressHooks": true
};

wixData.query("Members/PrivateMembersData",dataOptions)
.eq("firstName", request.path[5]).eq("lastName", request.path[6])
.find(options)

thanks shan i have been stock in this problem for days now and you answer really helped me a lot thank you so much

can you hel me? ive been trying to get “User” info and “my databases in json” api. and cant seem to make any of it work. one day it works next it dont on some. here is the velo backend code i used. and the error its getting today.

this velo code: import { ok, badRequest } from ‘wix-http-functions’;
import wixData from ‘wix-data’;
// Making a common open API for your data collections in Wix Code
// so other systems can consume your data
// Type in the Data Collection names you do allow to be a part
// of the common API functions
let whiteList = [‘VPXTABLES’, ‘Players’, ‘Wheels’, ‘ScoreBoard’, ‘VPinOwners’];
export function get_api(request) {
const response = {
headers: {
‘Content-Type’: ‘application/json’
}
};
// Get name of Data Collection from path[0]
let datacollection = request.path[0];
// DummyData
if (whiteList.includes(datacollection)) {
return wixData.query(datacollection)
.limit(100)
.find()
.then((apiResults) => {
if (apiResults.totalCount > 0) {
response.body = {
items: apiResults.items
};
return ok(response);
}
response.body = {
items: “No items found in the collection.”
};
return ok(response);
});
}
response.body = {
error: “Data Collection is not allowed to be used through this API.”
};
return badRequest(response);
}

-is getting an error of this : Parse error on line 1:
https://www.propperp
^
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{’, ‘[’, got ‘undefined’

EXPOSING HTTP_function API
if anyone is looking to expose their API http_function. this code the velo team and i figured out, it works flawless.
What it does… it looks for the “Whitelist” in the script and pnly opens the databases you put in that whitelist. then it formats it all in perfect JSON for flutter or other calls. it also has a script to not display hidden flies. but you have to make a field in your databases called hidden, make it a Bolene, and the items you don’t want to show in an Api call just check it as true. here is the final code:

import { ok, badRequest } from ‘wix-http-functions’;
import wixData from ‘wix-data’;

// Making a common open API for your data collections in Wix Code
// so other systems can consume your data
// Type in the Data Collection names you do allow to be a part
// of the common API functions
let whiteList = [‘Players’, ‘VPinOwners’, ‘VPXTABLES’];

// Function to filter out hidden items based on a field called “hidden”
function filterHiddenItems(items) {
return items.filter(item => !item.hidden);
}

export function get_api(request) {
const response = {
headers: {
‘Content-Type’: ‘application/json’
}
};

// Get name of Data Collection from path[0]
let datacollection = request.path[0];

// DummyData
if (whiteList.includes(datacollection)) {
return wixData.query(datacollection)
.limit(1000)
.find()
.then((apiResults) => {
if (apiResults.totalCount > 0) {
response.body = {
items: filterHiddenItems(apiResults.items) // Filter out hidden items
};
return ok(response);
}

    response.body = { 
      items: 'No items found in the collection.' 
    }; 
    return ok(response); 
  }) 

}

response.body = {
error: ‘Data Collection is not allowed to be used through this API.’
};
return badRequest(response);
}

Hope this helps someone as it took me 3 months to figure out lol.


  1. i’ve tried to add an oath authorization, and expost posts, groups, messages, forums and other things to the logged in user.

  2. i’ve tried to get it to include an url for the Media instead of Wix:image links that have to be translated. but I have not been able to successfully make either of them happen.