Cloud Code: Save REST Response in two Tables and build object relation

I’m trying to save an API response from an external source in a Backendless table. It works except with the nested arrays. The data are coming from an MLS system (Real Estate), each object (Property) has an array for Media (images). My idea is to save the x media files per property in a separate table and connect the property in one table via object relation with the media files from the other table (One to n).

Here is a screenshot how the JSON response looks like:

Here is my CODELESS Cloud Code for testing.

From my table “Properties”, I’m trying to save all media in the table “Media” and create a ONE-to-MANY relation from Properties to Media

I tried a bunch of things but most of the time when I’m trying to get the data inside the Media array, I get the error 0 “Objects must be provided and must be an array of objects.”

Is that something I can achieve with Codeless?

Thanks in advance!

Hello @Benjamin_Maares

When you use upsert it relies on the objectId property, when it persists in the payload and on the server, there is an object with the objectId it updates the object on the server, but when there is no object with provided objectId or the objectId wasn’t provided it always creates a new one.

so, bulkUsert won’t work for you because you load objects from the external service and these objects do not contain the objectId property.

I can recommend you to use deepSave feature, which saves a new object with its relations.

Regards, Vlad

Hi @vladimir-upirov,

Thanks a lot for your reply.

I’m getting a unique ID from the external database (Lets call it propertyID). Unfortunately, I cannot change from the Backendless objectID to the propertyID but what if I set the constrain for the propertyID to unique and indexed? Then it should look for the ID and only update the data if property exists or create a new one if propertyID doesn’t exist. What do you think?

But I’ll also check the option with the deepSave feature.

I’ll keep you posted


I’m not sure, let me ask our backend team

I just received an answer from my colleague,

so usert works only with the objectId property