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);
}
i’ve tried to add an oath authorization, and expost posts, groups, messages, forums and other things to the logged in user.
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.