Hi, I'm having an error saying - Payload values do...
# help
s
Hi, I'm having an error saying - Payload values do not match URL in primary key column(s), and this is what I did to update my user data const response = await axios.put("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users?id=eq." + user.id, { column: user.value }, { headers: { 'apikey': config.SUPABASE_KEY, 'Authorization':
Bearer ${config.SUPABASE_KEY}
, 'Content-Type': 'application/json', 'Accept': 'application/json', } }) I really appreciate the help 🙂
n
Hello @Sagieq! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
o
Hi why not use the Supabase SDK instead of axios? @Sagieq
Would be easier to fix, or even just fix it
s
This is coming from API I created, The fronted request this from my API
o
I mean, i get that, but I'm not sure if it's the best way to interact with the database
s
when new user the, insert user into database is working, when it comes to updating the user data, it gives me an error
or the user data from database is not updating
From what I understand having, environment in the fronted side is not safe
That is why my fronted only request from API, then the API secures the secrets and all
Well, I have reasons that is why I prefer this way
o
The SDK does what you do, but easier. While you're not using the master key, and only the anon key, it is totally secure 🙂
I get that, that's why I will not force you to use the SDK
I'm not sure why you get this error. Can you share the entity in your table please?
Would be easier to understand the primary key error
s
The table name is users
if (res.data.length > 0) { // Update user with new token const response = await axios.put("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users?id=eq." + res.data[0].id, { facebook_token: user.facebook_token }, { headers: { 'apikey': config.SUPABASE_KEY, 'Authorization':
Bearer ${config.SUPABASE_KEY}
, 'Content-Type': 'application/json', 'Accept': 'application/json', } }).then(res => { done(null, user); }).catch(err => { console.log('Error updating user: ', err); }); } else { // Create user in supabase await axios.post("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users", user, { headers: { 'apikey': config.SUPABASE_KEY, 'Authorization':
Bearer ${config.SUPABASE_KEY}
, 'Content-Type': 'application/json', 'Accept': 'application/json', } }).then(res => { done(null, user); }).catch(err => { console.log('Error creating user: ', err); }) }
The Updating part is where I get the error
o
Copy code
js
if (res.data.length > 0) {
    // Update user with new token
    const response = await axios.put("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users?id=eq." + res.data[0].id,
        { facebook_token: user.facebook_token }, {
        headers: {
            'apikey': config.SUPABASE_KEY,
            'Authorization': `Bearer ${config.SUPABASE_KEY}`,
            'Content-Type': 'application/json',
            'Accept': 'application/json',
        }
    }).then(res => {
        done(null, user);
    }).catch(err => {
        console.log('Error updating user: ', err);
    });
} else {
    // Create user in supabase
    await axios.post("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users", user, {
        headers: {
            'apikey': config.SUPABASE_KEY,
            'Authorization': `Bearer ${config.SUPABASE_KEY}`,
            'Content-Type': 'application/json',
            'Accept': 'application/json',
        }
    }).then(res => {
        done(null, user);
    }).catch(err => {
        console.log('Error creating user: ', err);
    })
}
I changed nothing, only reindented the code
In the code above, everything works fine?
s
the Create user is supabase works
o
Only the create user?
s
the Update user does not
Yes
o
hmmm
Is ``id`` a primary column?
s
I deleted the user created, then test again
It always create new user data if the user does not exist in database
o
hmmmmm
What happens if you change the ``column`` name? (in the body you send)
s
Sorry I don't understand this part, what do mean change the
column
name?
update the name instead?
o
In this code:
Copy code
const response = await axios.put("https://odbdnnohjmaybjdceqlo.supabase.co/rest/v1/users?id=eq." + user.id,
                { column: user.value }, {
                headers: {
                    'apikey': config.SUPABASE_KEY,
                    'Authorization': Bearer ${config.SUPABASE_KEY},
                    'Content-Type': 'application/json',
                    'Accept': 'application/json',
                }
            })
What happens if you change the ``user.value`` by something else?
Ooooooooh waaaaait
This code looks wrong to me, you're trying to change a column named "column", it can't work
But, your code with ``facebook_token`` looks good to me, so it's weird it doesn't work
is ``Payload values do not match URL in primary key column(s)`` the whole error?
s
not thats the data->messages->
I'll send a screenshot
You want the whole error?
Its kinda long error
Error: Request failed with status code 400
statusMessage: 'Bad Request',
o
The message is enough i think, but i can't figure it out
s
I followed the supabase api /bash
Same here I really don't have a clue how to fix this or at least to debug why its happening
o
This is really weird. I guess the best way to find a way to fix it would be to create a discussion on the Github, so the team can see it and fix it if it is an issue https://github.com/supabase/supabase/discussions
s
Before I came here, I did search for solution, seems I did not find any
o
There is not a lot of solution because everyone else is using the sdk 😅 but it is good to have people like you, we can find bugs/issues!
s
Thank you Sir, I really appreciate your help 🙂
o
Sorry to not be able to help you more on this 😅
s
No problem, I was actually hoping that I was doing it wrong, and I just missed something, guess I have to create a discussion for this, Thank you again Sir 🙂
g
@Sagieq Any reason you are using put instead of patch? put requires all columns be filled it, versus patch which will update specified columns. https://postgrest.org/en/stable/api.html#put
o
Ooooooooh, the error makes sense to me now!
Wait, he really used something else than what the api said? 😂 Damn i thought Sagieq just copied paste, i didn't check the method xD
Garry has a better look than me, i'm 99% sure the verb is the issue
s
Ohhhh, I did not know that, I will try that in a minute
Yeah, I change the put to patch and it works! Thank you guys, Have a great day 🍻