Invoking Edge Function Bug

Hi everyone,

I’m trying to send a JSON body using the Supabase “Invoke an Edge function” action, but it’s not working as expected.

My Edge Function requires a simple JSON body like { "apiKey": "some-value" } . However, when I use the “Invoke an Edge function” action with the POST method, my function logs show that it receives a completely empty body.

I’ve already confirmed that the function itself is correct, as it works perfectly when I test it directly from the Supabase dashboard or other API tools. The issue seems to be specific to how the WeWeb action sends the body.

I’ve tried configuring the “Body” field with both createObject() and a raw JavaScript object formula, but neither sends the data.

What is the correct way to configure the Body for this action to send a JSON object? Has anyone else run into this?

BTW the REST API works perfectly running this. So it seems that the invoke edge function workflow in weweb has a bug. Any updates

I have seen lots of posts on this exact topic by community but no solution from @DanielL

Thanks for any help!

Have you CORS headers set up properly?

Yeah I have. I was having CORS issues earlier but fixed them

This is seperate.

Hello @tom12345, I noticed that you are sending some unnecessary headers. When you call the edge function through the plugin, Authorization is already sent by default.
If you need the base token, use req.headers.get('Authorization') to get the value.
I will leave a simple example below using CORS and also getting the token to query the table.

import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from 'jsr:@supabase/supabase-js@2';

const corsHeaders = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type'
};
Deno.serve(async (req)=>{
  if (req.method === 'OPTIONS') {
    return new Response('ok', {
      headers: corsHeaders
    });
  }
  try {
    const supabase = createClient(Deno.env.get('SUPABASE_URL') ?? '', Deno.env.get('SUPABASE_ANON_KEY') ?? '', {
      global: {
        headers: {
          Authorization: req.headers.get('Authorization')
        }
      }
    });
    // TODO: Change the table_name to your table
    const { data, error } = await supabase.from('table').select('*');
    if (error) {
      throw error;
    }
    return new Response(JSON.stringify(data), {
      headers: {
        ...corsHeaders,
        'Content-Type': 'application/json'
      },
      status: 200
    });
  } catch (error) {
    return new Response(JSON.stringify({
      error: error.message
    }), {
      headers: {
        ...corsHeaders,
        'Content-Type': 'application/json'
      },
      status: 400
    });
  }
});
2 Likes