"supabase_functions.http_request" does not exist when called in function #22668
-
When a user registers I want to trigger sending the corresponding email via a REST API. This is not supported by Supabase, so I want to achieve this via a webhook calling an edge function. Webhooks with edge functions are not supported in a local setup and require hard-coding URLs and credentials, so I want to use a custom function which accesses credentials from I would appreciate any hint, thanks! Function and hookCREATE OR REPLACE FUNCTION public.trigger_edge_function()
RETURNS TRIGGER AS $$
DECLARE
base_url TEXT;
service_key TEXT;
request_url TEXT;
auth_header jsonb;
BEGIN
SELECT decrypted_secret
INTO base_url
FROM vault.decrypted_secrets
WHERE name = 'supabase_functions_base_url';
SELECT decrypted_secret
INTO service_key
FROM vault.decrypted_secrets
WHERE name = 'service_role_key';
request_url := base_url || '/dummy';
auth_header := '{"Content-type":"application/json","Authorization":"Bearer ' || service_key || '"}';
select supabase_functions.http_request(
request_url,
'POST',
auth_header,
'{}',
'1000'
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = supabase_functions, extensions, public, pg_temp;
CREATE OR REPLACE TRIGGER dummy_hook
AFTER INSERT ON public.my_users_table
FOR EACH ROW
EXECUTE FUNCTION public.trigger_edge_function(); Error
Further observationsThe following webhook/trigger created via UI works as expected: CREATE TRIGGER foo AFTER INSERT ON public.my_users_table FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('http://host.docker.internal:54321/functions/v1/dummy', 'POST', '{"Content-type":"application/json"}', '{}', '1000') The following standalone statement fails with the original error (except all fields are "unknown" in the function signature): select supabase_functions.http_request('http://host.docker.internal:54321/functions/v1/dummy', 'POST', '{"Content-type":"application/json"}', '{}', '1000') |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Why don't you just use the http or pg_net extension instead of trying to get the webhook code involved. |
Beta Was this translation helpful? Give feedback.
Why don't you just use the http or pg_net extension instead of trying to get the webhook code involved.