ObjectId: Using your own instead of the server's

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?

Please, provide appId, and the table name where you try this.
Also it would be good to see the entire request.

p.s. the default type of objectId is STRING.

Thanks Oleg,

AppId is 95594B0A-1972-7690-FF14-F883764C3B00

There is an API call in Business Logic called newbillableitem which demonstrates this
Table is BillableItem

Sample body is:
{
“id”: “12345”,
“item_code”: “Test Code”,
“name”: “Test Item”,
“price”: 10.15,
“tax”: “1”,
“created_at”: “”,
“updated_at”: “”,
“item_type”: “Thing”,
“ownerid”: “api@novansa.com.au”,
“archived_at”: “”,
“objectId”: “12345”
}

I am using a string type for objectId

I’ve tried and for me everything works fine.
Did you checked, that objectId is STRING in both cases?

Yes I think so.

See pics showing body and codeless block:

The cURL for this is:

curl -X “POST” “https://api.backendless.com/95594B0A-1972-7690-FF14-F883764C3B00//services/integration/newbillableitem”
-H ‘Content-Type: application/json’
-H ‘Accept: application/json’
-d $‘{
“id”: “12345”,
“item_code”: “Test Code”,
“name”: “Test Item”,
“price”: 10.15,
“tax”: “1”,
“created_at”: “”,
“updated_at”: “”,
“item_type”: “Thing”,
“ownerid”: “api@novansa.com.au”,
“archived_at”: “”,
“objectId”: “12345”
}’

Hello @Andrew_Schox

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"}'

Regards, Vlad

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.

Regards, Vlad

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.

Hello @Andrew_Schox

We created a ticket (BKNDLSS-22679) to add the ability to do an upsert. As the status of this task changes, we will notify you in this topic.

Hi, guys! The feature was implemented, it is avaialable in all our SDKs

Regards,
Marina