Backend function returns status 200 but a blank page with POSTMAN

Hello !

I’m having trouble with

BACKEND http-functions.js

Working in

Velo Backend + wix-events.v2

What I’m trying to do

I try for a given eventId to return its categories in Json format

What I’ve tried so far :

import { ok, notFound, serverError } from "wix-http-functions";
import { categories } from "wix-events.v2";

export async function get_eventCategories(request) {
  try {
    const url = new URL(request.url);
    const eventId = url.searchParams.get("eventId");

    if (!eventId) {
      return notFound({ error: "Missing eventId parameter" });
    }

    const results = await categories.listEventCategories(eventId);
    const eventCategories = results.items || [];

    return ok({
      eventId,
      categories: eventCategories,
      message:
        eventCategories.length === 0
          ? "This event has no category"
          : "Success",
    });
  } catch (error) {
    return serverError({ error: error.message });
  }
}

Extra context

With POSTMAN :

mydomain/_functions/eventCategories?eventId=a_valid_event_id_having_a_category

returns a status 200 but a completely blank body

Why?

SOLVED : listEventCategories needed to be elevated

// backend/http-functions.js
import { ok, serverError } from 'wix-http-functions';
import { categories } from 'wix-events.v2';
import { elevate } from 'wix-auth';

const elevatedListEventCategories = elevate(categories.listEventCategories);

export async function get_listEventCategories(request) {
  try {
    const url = new URL(request.url);
    const eventId = url.searchParams.get('eventId');
    if (!eventId) return ok({ body: { success: false, error: 'Missing eventId' } });

    const raw = await elevatedListEventCategories(eventId);
    const categoriesArray = Array.isArray(raw) ? raw : (raw && raw.categories) || [];

    return ok({ body: { success: true, categories: categoriesArray } });
  } catch (err) {
    console.error('get_listEventCategories error:', err);
    return serverError({ body: { success: false, error: err?.message || String(err) } });
  }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.