Skip to content

Deleting multiple objects

This operation deletes multiple objects from the database. To add this operation to a Unit Of Work request, use the following operation in the request payload. The payloads are organized by how the objects to be deleted are identified:

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "DELETE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "unconditional" : [ "objectId VALUE", "objectId VALUE", "objectId VALUE" ]
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "DELETE_BULK", this designates the operation as "deleting multiple objects". The objects to delete in the database are defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be deleted.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "unconditional" The value is mandatory. Must contain a JSON array. The array contains objectId values identifying the objects which will be deleted by this operation.

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "DELETE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "unconditional" : "where clause query to identify objects"
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "DELETE_BULK", this designates the operation as "deleting multiple objects". The objects to delete in the database are defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be deleted.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "conditional" The value is mandatory. Must contain a string value which is a where clause query.The server runs the query in the "table" table to identify the objects which will be deleted by this operation.

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "DELETE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "unconditional" : {
            "___ref":true,
            "opResultId":"OPERATION ID OF FIND OR BULK CREATE OPERATION"
        }
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "DELETE_BULK", this designates the operation as "deleting multiple objects". The objects to delete in the database are defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be deleted.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "unconditional" The value is mandatory. Must contain a JSON object with the structure as shown above. The "opResultId" property must contain operation result id of a previous operation in the same transaction. These previous operations can be either Retrieving objects or Saving multiple objects.

Return Value

This operation returns the number of deleted objects. The returned value can be used in other operations of the same transaction.

Example

The examples below demonstrate the usage of the operation for all possible ways to reference the object that should be deleted:

Request:

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "operations": [
    {
      "operationType": "DELETE_BULK",
      "table": "Order",
      "opResultId": "deleteOrderOperation",
      "payload": {
        "unconditional" : [
            "BB9311B4-2713-C723-FF5E-D070A58FB800",
            "121593FD-308D-91C6-FF40-E58EEC435A00",
            "C46323B7-22C3-37BA-FF2A-999678849600"
            ]
      }
    }    
  ]
}

Response:

{
    "success": true,
    "error": null,
    "results": {
        "deleteOrderOperation": {
            "type": "DELETE_BULK",
            "result": 3
        }
    }
}

Request:

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "operations": [
    {
      "operationType": "DELETE_BULK",
      "table": "Order",
      "opResultId": "deleteOrderOperation",
      "payload": {
        "conditional" : "orderStatus = 'invalid'"
      }
    }    
  ]
}

Response:

{
    "success": true,
    "error": null,
    "results": {
        "deleteOrderOperation": {
            "type": "DELETE_BULK",
            "result": 1
        }
    }
}

Request:

URL:

POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "operations": [
    {
      "operationType": "FIND",
      "table": "Order",
      "opResultId": "findOrderOperation",
      "payload": {
        "whereClause":"orderStatus = 'invalid'"
      }
    },
    {
      "operationType": "DELETE_BULK",
      "table": "Order",
      "opResultId": "deleteOrderOperation",
      "payload": {
        "unconditional" : {
            "___ref":true,
            "opResultId": "findOrderOperation"
        }
      }
    }    
  ]
}

Response:

{
    "success": true,
    "error": null,
    "results": {
        "findOrderOperation": {
            "type": "FIND",
            "result": [
                {
                    "orderId": null,
                    "orderStatus": "invalid",
                    "created": 1586057024000,
                    "updated": 1586057028000,
                    "objectId": "1BB1BEEB-4E1E-ED1D-FF6C-AF6AF9341C00",
                    "amount": null,
                    "deliveryDate": null,
                    "ownerId": null,
                    "___class": "Order"
                }
            ]
        },
        "deleteOrderOperation": {
            "type": "DELETE_BULK",
            "result": 1
        }
    }
}