I want to specify the ObjectId of new records created using a POST operation so that I can later update records with the same key. However, when I try and do this, I get the following error:
{
“code”: 1000,
“message”: “Entity with ID 12345 not found”,
“errorData”: {}
}
When I try this operation without using the Object ID, records are created without error and the server allocates an ObjectId.
Am I trying to do something incorrectly, or is this approach not possible?
The issue is in the JS-SDK which is used in the Codeless.
When you try to save an object with the “objectId” property the SDK thinks the object is already created and we try to update it, and since on the server there is no object with this objectId = 12345 it fails.
We will consider possible solutions for this.
As workaround you can use HTTPs Block for sending the right request. here is a valid request: curl -X POST -H 'Content-Type:application/json' 'https://api.backendless.com/YOUR_APP_ID/YOUR_API_KEY/data/YOUR_TABLE_NAME' -d '{"objeectId":"12345"}'
Just wondering how important it is for you to have your own ID?
If you provide your case with more details we would try to find the best solution for you.
I need to make regular updates to the Backendless DB from a timer. This involves getting records from an external service (some of which are new and some of which have been updated since the last timer run) and then writing them to Backendless. Therefore an upsert would be much better option, and presumably with better performance than me manually checking whether a record exists first and then performing either an insert or update as appropriate.
My understanding is that Backendless uses the objectId for upserts. If it were possible to use other columns that would be OK.
Also I have tested your suggested HTTP Block and found a similar problem.
POST Inserts OK but Update (i.e. specifying an existing objectId) gives the following error:
{
“code”: 1062,
“message”: “Duplicate entry ‘12348’ for key ‘PRIMARY’”,
“errorData”: {}
}
PUT Updates OK but trying an insert gives the following error:
{
“code”: 1000,
“message”: “Entity with ID 12347 not found”,
“errorData”: {}
}
This is kind of what you might expect for POSTs and PUTs but still leaves me having to do a separate call for inserts and updates.