JesterOC
(Jessie OC)
1
Using JS fetch I get user
“https://api.backendless.com/FF55A111-06AF-7EB1-FFDE-B5B62760CA00/[secretkey]/data/Users/find”
then I do user.PAID = true
then i try update
POST https://api.backendless.com/FF55A111-06AF-7EB1-FFDE-B5B62760CA00/[secretkey]/api/data/Users/upsert
returns 404 (Not Found)
HTTP error! status: 404
Yet shortly afterwards the Users table in database gets updated with the POST value(s)
idk why the 404 the console log reports!?
here is my JS Code… response.ok returns false
async function updateUserViaPost(user,_id,_hidden) {
try {
user.PAID = true;
const response = await fetch(
“https://api.backendless.com/“+_id+”/“+_hidden+”/api/data/Users/upsert”,
{
mode: “cors”,
method: “POST”,
headers: { “Content-Type”: “application/json” },
body: JSON.stringify(user),
}
);
if (!response.ok) {
//Handle errors.
console.error(`HTTP error! status: ${response.status}`);
return null;
}
…
Hi @JesterOC
It looks like the issue is with the HTTP method used for the request.
According to the Upsert Single Object documentation, the upsert
operation should be performed using the PUT
method instead of POST
.
Try changing your request to:
PUT https://api.backendless.com/FF55A111-06AF-7EB1-FFDE-B5B62760CA00/[secretkey]/api/data/Users/upsert
Let me know if you need any further help!
Regards,
Viktor
JesterOC
(Jessie OC)
3
it failed with 404… but backendless database updated a few seconds later with new PUT values in user… same as POST
JesterOC
(Jessie OC)
4
https://xxxx.backendless.app/api/data/[table_name]/upsert
is what the REST docs said…
so i had
https://api.backendless.com/“+_id+”/“+_hidden+”/api/data/Users/upsert
but my previous call to get the user was already working… so i has
https://api.backendless.com/“+_id+”/“+_hidden+”/data/Users/find
to do that.
and i noticed it does not have api/ before data/Users/find
so i removed that and now it works great…