How to create a webhook for a supabase edge function with SQL?

196 views Asked by At

Let's say I have an edge function called "hello-world".

Question 1

How can I rewrite the SQL example from the supabase documentation to trigger the edge function "hello-world" in sql (e.g. without the supabase GUI)?

create trigger "my_webhook" after insert
on "public"."my_table" for each row
execute function "supabase_functions"."http_request"(
  'http://localhost:3000',
  'POST',
  '{"Content-Type":"application/json"}',
  '{}',
  '1000'
);

Question 2

If the edge function must read another rls secured database table, do I have to call the edge function with a postgres role? How would I implement that with the SQL webhook?

1

There are 1 answers

0
tobias hassebrock On BEST ANSWER

Simply add the the edge function url as https parameter and an Authorization header in the first paranthese:

create or replace trigger "send-push-hook" after insert
on authenticated_access.notifications_by_user for each row
execute function supabase_functions.http_request(
  'https://<project-url>.supabase.co/functions/v1/<function-name>',
  'POST',
  '{
    "Content-Type":"application/json",
    "Authorization": "Bearer <your authorization for example service role key>"
    }',
  '{}',
  '1000'
);