Anyone trying to expose the api for their CMS! here you Go!

put this in your backend and name is http-function.js

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

// Function to convert the Wix image URL to an external accessible URL
function convertWixImageUrl(wixImageUrl) {
  if (wixImageUrl.startsWith('wix:image://v1/')) {
    let convertedUrl = wixImageUrl.replace('wix:image://v1/', 'https://static.wixstatic.com/media/');
    const match = convertedUrl.match(/\/([^/]+)$/);
    if (match && match[1]) {
      convertedUrl = convertedUrl.replace(match[0], '');
    }
    return convertedUrl;
  } else {
    return wixImageUrl;
  }
}

// Function to recursively convert Wix image URLs in an object
function convertWixImageUrlsInObject(obj) {
  for (let prop in obj) {
    if (typeof obj[prop] === 'string') {
      obj[prop] = convertWixImageUrl(obj[prop]);
    } else if (typeof obj[prop] === 'object') {
      convertWixImageUrlsInObject(obj[prop]);
    }
  }
}

// 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 (change each ‘database’ for your name of your database on query side ie: ’items’
let whiteList = ['ReplacewithDatabseName', 'ReplacewithDatabseName1', 'ReplacewithDatabseNameect'];

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) // You can set a reasonable limit here for performance reasons
      .ascending('title') // Sort alphabetically by title in ascending order
      .find()
      .then((apiResults) => {
        if (apiResults.totalCount > 0) {
          // Convert Wix image URLs in the response before sending to the client
          apiResults.items.forEach((item) => {
            convertWixImageUrlsInObject(item);
          });

          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);
}

My next problem to add is that i want it to allow access to Posts, messages, groups, forums, and other things if the request has the sites Oath Key in the header. but this works perfect for now. and it even allows you to get the images url instead of the wix.image link that dont work in flutter yet. Hope this helps anyone as it was hard to get done. lots of help from wix and GPT chat. but its clean and works awesome! enjoy

1 Like

for anyone listening. I think im making more headway. I now have all my wix api data in my flutterflow app and ita beautiful and super fast. I found that wonderpush works well with web push notificatins and adds to wix quite nice. Now looking at wix Headless trying to change its sdk into flutterflow! Wix please make a FlutterFlow Plugin! Please!!! flutter flow is an amazing flutter app builder that is visual just like wix! Anyway. any advise would be nice. i’ll keep ya’ll posted on progress

Use Wix Headless for these type of things. Wix Headless—The Headless Solution Built for You | Wix.com

You can use Wix Headless to access your Wix Apps data and APIs in your custom build mobile app/website/web app basically anything you work on.

1 Like

Yes. but wix headless SDK is javascript and not compatible with flutter or flutter flowyet? :(. been trying so hard lol

I think there are REST APIs too. So you can make requests to APIs without SDK.

REST Portal (wix.com)

1 Like

thank you! that helps allot!

read that page. it says you have to use wix headless? wix headless requires the sdk for auth. Fluter dart does not support SDK javascript. so i cant import them into FlutterFlow. forces me to use my api code in backend. but this does not allow me auth or blogs or anything like this. cant wait for that to work one day:)

There should be REST APIs for the same things:

Request An Access Token | REST (wix.com)

Login V 2 | REST (wix.com)

1 Like

i have tried and tried to get that to work. and flutterflow just opened its new custom login. so if i can get that working it will all be. done. but its docs are not lining up with wix docs. and im missing someyhing. i can share with you a demo wix project and a flutterflow project i made for testing. and you can see if you like. hom=nestly this has been so hard. but I’ve gotten far. the code i am using for my cms is working flawless. but id much rather do it with the headless if i can ever get it attached. flutterflow supports, firebase, backendless, pocketbase, onesignal, stripe and many others, out the box. but wix ive been trying to get auth working for 6 months straight 10 hours plus a day. :(. maybe im just missing something.

i could never. get headless to work outside of wix apps.