Hi, I am stuck trying to get an API call (Supabase function, not a table query) to succeed when the function requires input parameters. Here's what I have working. I purposely dialed back the function to just do something very basic, so it's easier to focus on the issue:
Supabase Function:
DROP FUNCTION fn_testparm;
CREATE OR REPLACE FUNCTION fn_testparm(p1 int)
RETURNS TABLE (
id int,
title text,
is_deleted boolean
)
AS $$
BEGIN
-- userid != null (not passed in properly)
IF p1 IS NULL THEN
RAISE EXCEPTION 'Missing p1';
END IF;
-- get data
RETURN QUERY
SELECT 1000 as id, 'Test Title' as Title, false as is_deleted;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE EXCEPTION 'No users';
WHEN OTHERS THEN
RAISE EXCEPTION 'Error: %', SQLERRM;
END
$$ LANGUAGE plpgsql;
SELECT * FROM fn_testparm(3);
The select (last line) call works within Supabase Query window.
Then I define the API within FlutterFlow:
and the Variables (which I'm currently assuming is how one would pass parameters)
And then I test it within FlutterFlow:
See failed message:
I also tried running using the same headers, and parameter in both Insomnia and Postman. It provides a different error.
And then finally, if I remove the p1 parameter from the function, and test that, it returns successfully everywhere I try (see below modified function, and a example run in FF.
DROP FUNCTION fn_testparm;
CREATE OR REPLACE FUNCTION fn_testparm()
RETURNS TABLE (
id int,
title text,
is_deleted boolean
)
AS $$
BEGIN
-- userid != null (not passed in properly)
--IF p1 IS NULL THEN
-- RAISE EXCEPTION 'Missing p1';
--END IF;
-- get data
RETURN QUERY
SELECT 1000 as id, 'Test Title' as Title, false as is_deleted;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE EXCEPTION 'No users';
WHEN OTHERS THEN
RAISE EXCEPTION 'Error: %', SQLERRM;
END
$$ LANGUAGE plpgsql;
SELECT * FROM fn_testparm();
and from Insomnia (no parm):
So, I think either I just don't know how to supply parameters, or maybe they aren't supported on the rest/v1/rpc POST. I haven't found any other examples using the API call approach. There are examples of how to use javascript. Here's what Supabase provides as example templates on how to call this API:
Without parameter (Javascript version):
and the BASH version...
With the parameter (Javascript):
and the BASH version...
Any help on how to get past his parameter passing issue would be amazing, Thanks!