CSmith
CSmith

Reputation: 1

404 Error with supabase, when trying to use RPC

I've created a table in supabase that uses an array of int8s (group ids) to hold what groups a user has. Though supabase has no way to append the array so I found a post that talks about making stored procedures, which I tried but I cant get to work with my own table.

Procedure:

create or replace function append_array(new_element int8, id text)
returns void
as
$func$
    update "Users"
    set "UserGroups" = array_append("UserGroups", $1)
    where id = $2
$func$
language sql;

Procedure call

async function createGroup() {
    const { error } = await supabase
    .from('Groups')
    .insert({ Members: [session.user.email], Name: groupName, Editors: [session.user.email] })
    const { errorupdate } = await supabase
    .rpc('append_array', {num: 1000000, email: session.user.email});
    if(error) {
      alert("Error creating group");
      console.log(error);
    }
    if(errorupdate){
      alert("Error updating user info group");
      console.log(errorupdate);
    }

  }

Im using 100000 as a place holder until I can figure out how to use the primary key generated with creating the group. Though when I call the function it returns a 404 error as a response.

Request URL: https://wqamrjqdnsnboscermtz.supabase.co/rest/v1/rpc/append_array Request Method: POST Status Code: 404 Remote Address: 104.18.27.135:443 Referrer Policy: strict-origin-when-cross-origin

https://github.com/orgs/supabase/discussions/2771

I looked through this discussion which and implemented their solution but its not working the way I have it set up right now. I was expecting the UserGroups column (array of int8s) to be updated the group number being add to the array. I very much still a begginner when it comes to web programming so any help would be greatly appricated.

Upvotes: 0

Views: 1969

Answers (1)

dshukertjr
dshukertjr

Reputation: 18680

Your parameter on the database function and rpc call does not match. You can align them like this. This may not be the only thing wrong, but it's a step closer to making the code work.

create or replace function append_array(new_element int8, id uuid)
returns void
as
$func$
    update "Users"
    set "UserGroups" = array_append("UserGroups", $1)
    where id = $2
$func$
language sql;
const { error: errorupdate } = await supabase
    .rpc('append_array', {new_element: 1000000, id: session.user.id});

Upvotes: 0

Related Questions