Debug edge function trigger on cli
I'm trying to trigger a local (cli) edge function using a database webhook trigger, and hope to use the database NEW (payload.record) values inside the edge function.
For the moment, I just want to debug the connection and validate what the webhook sent to the edge function. So I have an edge function that just returns the payload sent by the webhook as a 200 response.
How do I capture this response when called from the webhook (not from the CLI itself)? One thing that makes me suspicious that it'll work is that the webhook created by the Supabase dashboard doesn't show a payload at all: create trigger test_trigger after insert on public.ios_apps for each row execute function supabase_functions.http_request('http://127.0.0.1:54321/functions/v1/test_trigger', 'POST', '{"Content-type":"application/json","Authorization":"Bearer xxxx"}', '{}', '5000');
How do I capture this response when called from the webhook (not from the CLI itself)? One thing that makes me suspicious that it'll work is that the webhook created by the Supabase dashboard doesn't show a payload at all: create trigger test_trigger after insert on public.ios_apps for each row execute function supabase_functions.http_request('http://127.0.0.1:54321/functions/v1/test_trigger', 'POST', '{"Content-type":"application/json","Authorization":"Bearer xxxx"}', '{}', '5000');
2 Replies
Found my own answer, sort-of: https://medium.com/israeli-tech-radar/postgresql-trigger-based-audit-log-fd9d9d5e412c
Medium
PostgreSQL Trigger-Based Audit Log
If your app has data that is editable by users, you’ll probably want to keep a log of those changes. There are many approaches to doing so…
Are you referencing the edge function correctly. Taking a look at this guide https://supabase.com/docs/guides/database/webhooks#local-development it seems local development should be
http://host.docker.internal:54321/functions/Database Webhooks | Supabase Docs
Trigger external payloads on database events.