Supabase RPC call

Hi,

const { data, error } = await wwlib.wwPlugins.supabase.instance.rpc('get_active_customers', { p_days });

if (!error) {
  return data;
} else {
  return error;
}

I’m trying to get this simple script to work but there’s nothing returned. RLS has been disabled the and function has been tested on command line via the Supabase REST interface.

Can someone please help. I have been stuck for days. :sweat_smile:

Why don’t you use REST?

@hongchuan - I believe the parameter is a JSON and the property name(s) needs to be passed

for example if your function in supabase is “FUNCTION get_active_customers(ndays int)” then rpc(‘get_active_customers’, { ndays:p_days }); assuming p_days is your var

Let me know if this work.

Cheers

Yes, that’s the issue, not specifying the param name. I still can’t wrap my head around why instead of using REST someone would use RPC from the SDK instance for something this trivial. I’d say the instance is big guns, where as calling a function is fairly simply done with REST too.

Thanks @sleeusis @Broberto
I’m finding my way around. Thanks for the advice. FYI, I tried REST too, but not getting the desired outcome. :sweat_smile:

The REST call is returning an empty object.

Check out if you have any RLS, and if the function works. Might be an error in the setup also. I think if you try to remove the result.key, that might give you a different response actually.

I disable RLS for troubleshooting. Removing result.key returns empty object too.
On Supabase logs, the http code is 200

On CLI it works fine.

I must be missing something very minor, but I just can’t seem to find it.

Thanks @Broberto

I’d also try disabling the proxy, I think I don’t use that in my rest calls.

I managed to solve it. Weweb expects an object or an arrange. My SQL function was returning the actual count of active customer in int format.

I modified it to return the all the active customers in rows and got it to work.

Thanks @Broberto !

1 Like

If that was the issue you could just go and return a constructed jsonb object with key count and value your count I think