Skip to content

Deleting a single object

Important

This operation deletes a single object in the database. To delete more than one object, use the bulkDelete operation documented in the Deleting multiple objects chapter of this guide.

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 object to be deleted is 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",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": "OBJECT-ID"
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "DELETE", this designates the operation as "deleting a single object". The object to delete in the database is defined in the "payload" property.
"table" The value must contain the name of the table where the object 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" The value is mandatory. Must contain a string which is the objectId value of the object to delete.

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",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
        "___ref": true,
        "opResultId": "PREVIOUS-OPRESULT-ID",
        "resultIndex": VALUE,
        "propName": "objectId"
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "DELETE", this designates the operation as "deleting a single object". The object to delete in the database is defined in the "payload" property.
"table" The value must contain the name of the table where the object 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" The value is mandatory. Must contain a reference to a result from another operation in the same transaction. The contents of "payload" may vary depending on the operation where the result is coming from:
If the operation is Retrieving objects, the "payload" must contain values for the "opResultId", "resultIndex" and "propName" properties:
"payload": {
  ___ref": true,
  "opResultId": "RETRIEVING-OBJECTS-OPRESULT-ID",
  "resultIndex": VALUE,
  "propName": "objectId"
}

If the operation is Saving multiple objects, the "payload" must contain values for the "opResultId", and "resultIndex" properties:
"payload": {
  ___ref": true,
  "opResultId": "SAVING-MULTIPLE-OBJECTS-OPRESULT-ID",
  "resultIndex": VALUE
}

If the operation is Saving single object, the "payload" must contain value only for the "opResultId" property:
"payload": {
  ___ref": true,
  "opResultId": "SAVING-SINGLE-OBJECT-OPRESULT-ID"
}

If the operation is Updating single object, the "payload" must contain value only for the "opResultId" property:
"payload": {
  ___ref": true,
  "opResultId": "UPDATING-SINGLE-OBJECT-OPRESULT-ID"
}
``` |

</div></div>

## Return Value


This operation returns the timestamp when the object was deleted from the database. 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:

######
<ul class="nav nav-tabs" role="tablist">  <li role="presentation" class="active"><a href="#tx-delete-single-rest-ex" class="hash" aria-controls="hash" role="tab" data-toggle="tab">objectId</a></li>  <li role="presentation" class><a href="#tx-delete-single-rest-opresult-ex" class="class" aria-controls="class" role="class" data-toggle="tab">Operation Result</a></li> </ul><div class="tab-content"><div role="tabpanel" class="tab-pane active" id="tx-delete-single-rest-ex" >


Request:



URL: 
POST https://api.backendless.com/APP-ID/REST-API-KEY/transaction/unit-of-work
 Request header: 
Content-Type:application/json
 Request body: 
```json
{
  "operations": [
    {
      "operationType": "DELETE",
      "table": "Order",
      "opResultId": "deleteOrderOperation",
      "payload": "97A1DFF8-214D-781B-FF8F-5E8261889F00"
    }
  ]
}

Response:

{
    "success": true,
    "error": null,
    "results": {
        "deleteOrderOperation": {
            "type": "DELETE",
            "result": 1586039750970
        }
    }
}

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'",
        "pageSize":1
      }
    },
    {
      "operationType": "DELETE",
      "table": "Order",
      "opResultId": "deleteOrderOperation",
      "payload": {
            "___ref":true,
            "opResultId":"findOrderOperation",
            "resultIndex":0,
            "propName":"objectId"
      }
    }    
  ]
}

Response:

{
    "success": true,
    "error": null,
    "results": {
        "findOrderOperation": {
            "type": "FIND",
            "result": [
                {
                    "orderId": null,
                    "orderStatus": "invalid",
                    "created": 1586029376000,
                    "updated": 1586051786000,
                    "objectId": "BC8B738C-B1B0-DA83-FFC5-E7ECCAADC700",
                    "amount": 1.0,
                    "deliveryDate": null,
                    "ownerId": null,
                    "___class": "Order"
                }
            ]
        },
        "deleteOrderOperation": {
            "type": "DELETE",
            "result": 1586051969709
        }
    }
}