Skip to content

Upsert Multiple Objects

Description

This operation creates and/or updates multiple objects in the database. The operation receives a collection of objects as the argument. For every object in the collection it checks if an object already exists in the database and in that case updates it with the property values in the object. Otherwise, the object is saved in the database. To check if an object exists in the database, Backendless uses the value of the objectId property.

Method

PUT

Endpoint URL

The xxxx.backendless.app is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.

https://xxxx.backendless.app/api/data/bulkupsert/<table-name>

where:

Argument                Description
<table-name> Name of the data table where the operation must apply changes.

Request Headers

None.

Request Body

Must be a list of objects containing the mandatory "objectId" property, representing a unique identifier of a record stored in the data table or a record that will be inserted in the data table. Furthermore, the object properties must match the column names of a target data table.

// Sample list containing objects  
[  
    {  
        "objectId":"297BEFCD-2992-4724-8AAC-F3EB00E413D2",  
        "email":"alice@yourmail.com",  
        "age":25  
    },  
    {  
        "objectId":"EDC639B5-4993-42E4-939C-F05CBA75B544",  
        "email":"peter@yourmail.com",  
        "age":60  
    }  
]

Response Body

An array of the objectId values of updated or inserted objects.

Example

The example below upserts two objects in the "Person" data table.

curl --location --request PUT 'https://xxxx.backendless.app/api/data/bulkupsert/Person \  
--header 'Content-Type: application/json' \  
--data-raw '[  
    {  
        "objectId":"297BEFCD-2992-4724-8AAC-F3EB00E413D2",  
        "email":"alice@yourmail.com",  
        "age": 25  
    },  
    {  
        "objectId":"8CCC0E0C-C1AB-4B29-B632-821A00863FA7",  
        "email":"peter@yourmail.com",  
        "age": 60  
    }  
]

Codeless Reference

data_api_bulk_upsert_1

where:

Argument                Description
table name Name of the data table where the operation inserts and/or updates objects.
objects A list of objects to update or create.
return upserted objectIds When this box is checked, the operation returns a list of objectId values of updated or inserted objects.

Returns a list containing objectId values of updated or inserted objects.

Consider the following records in the Person data table:

data_api_bulk_upsert_2

The example below updates two objects in the Person data table:

data_api_bulk_upsert_3

The output will look as shown below after the Codeless logic runs. Values in the "age" and "email" columns were modified.

data_api_bulk_upsert_4

The operation returns the array of objectId values:

data_api_bulk_upsert_5