call an edge function via webhook

I'm trying to call the edge through its Endpoint URL, but it loads infinitely until it shuts down.
11 Replies
garyaustin
garyaustin3w ago
How are you calling it?
Any error on the call?
Preites
PreitesOP3w ago
I made a very generic function to test, I put the link of the function where it asks to enable the webhook, and the function is called but not executed, test by applying a link from webhook.web, to test the program and it returns but in the supabase it does not return anything
garyaustin
garyaustin3w ago
If you have the check for a JWT on for the function then you need to pass the Service_role key in the Authorization header. I think there is an option for that in the webhook interface.
Preites
PreitesOP3w ago
jwt is disabled
garyaustin
garyaustin3w ago
Then you will need to provide more info, code of the function, what your logs shows, etc for someone to help. That issue is the most common one people hit with webhook and function not being called so it was my first guess.
Preites
PreitesOP3w ago
code: export default async function handler(req) { try { const raw = await req.text(); // recebe o corpo bruto const data = JSON.parse(raw); // parseia o JSON const mensagem = data?.msgContent?.extendedTextMessage?.text ?? "mensagem não encontrada"; console.log("📥 Mensagem recebida:", mensagem); return new Response(JSON.stringify({ status: "ok", mensagem }), { status: 200, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } catch (err) { console.error("❌ Erro na função:", err); return new Response(JSON.stringify({ status: "erro", detalhe: String(err) }), { status: 500, headers: { "Content-Type": "application/json" } }); } } and the logs are just the standard booted and shutdown
garyaustin
garyaustin3w ago
You'll probably have to wait for someone who does more edge functions than I do. I've only used deno.serve in my edge functions. I'm not familiar with the method you are using. Maybe try a test case using a SB hello world to make sure your call is working... https://supabase.com/docs/guides/functions/quickstart#step-2-create-your-first-function
Preites
PreitesOP3w ago
export default async function handler(req) { console.log("➡️ Requisição recebida:", req.method); if (req.method !== "POST") { return new Response(JSON.stringify({ status: "erro", detalhe: "Método não permitido" }), { status: 405, headers: { "Content-Type": "application/json" } }); } try { const body = await req.text(); console.log("📦 Corpo bruto:", body); const data = JSON.parse(body); console.log("✅ JSON parseado:", data); const mensagem = data?.msgContent?.extendedTextMessage?.text ?? "mensagem não encontrada"; console.log("📥 Mensagem recebida:", mensagem); return new Response(JSON.stringify({ status: "ok", recebida: mensagem }), { status: 200, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } catch (err) { console.error("❌ Erro de execução:", err); return new Response(JSON.stringify({ status: "erro", detalhe: String(err) }), { status: 500, headers: { "Content-Type": "application/json" } }); } } I made some modifications based on the link, but it wasn't? Do you have some simple, generic code, just to see how to test when the function is called via webhook?
garyaustin
garyaustin3w ago
I linked a simple hello world function.
No description
garyaustin
garyaustin3w ago
Just do a console.log in that. But that is what I meant by Deno.serve... I've not seen your method, or if I have just did not pay attention to that part of the code.
Preites
PreitesOP3w ago
I achieved

Did you find this page helpful?