Invoke edge function on page load

I have an edge function that return object data.

When I test it and send the following in the body:

{
“supplierId”: “82004”
}

I get the correct response.

In weweb, I’m not sure what is mandatory to configure and how to bind the body correctly.

I tried binding javascript to the body, but with no success:

return [{ key: ‘supplierId’, value: globalContext.pageParameters[‘id’] || ‘82004’ }]

Any advice?

Try passing an object, not an array

tried this:

{
“supplierId”: “82004”
}

still no result

You must get some answer when testing, maybe even an error. Check out the logs

name: “Error”
stack: “Error: Failed to send a request to the Edge Function at Object.invokeEdgeFunction (https://cdn.weweb.io/components/f9ef41c3-1c53-4857-855b-f2f6a40b7186/6d5dd36e-d77a-4054-901e-806ac8c56554/dist/ma…”
message: “Failed to send a request to the Edge Function”
cause
name: “FunctionsFetchError”
status: undefined
data: undefined
context

  1. Try running it directly from your Supabase instance to see if you get a more descriptive error (if any).
  2. You can try pluging in your input, expected output, actual output, and current function into some LLM and just start asking questions (e.g., why is this not working).
  3. For what I see, looks like a parsing error. Maybe even from the frontend side.

Check the API call result in the browser’s DevTools >> “Network”

you should clear the contents and after that make your API call. Then you will be able to inspect the result.

This is a JavaScript error, nit a neteork error I think

yeah, maybe. I had several workflows in my project that resulted in the same unrecognizable error inside the editor, but in the dev tools I found a real hint to solve the problem.

I don’t quite remember what the issues were (I suppose CORS issue or changing the general API endpoint URL in Xano)

Flo just fixed this for me on OO: the issue was in the edge function. I needed to update the CorsHeaders. I was missing some of the values.

“Access-Control-Allow-Headers”: "Content-Type, Authorization,x-client-info, apikey, content-type