---
title: "REST - Delete"
canonical: "https://help.agiloft.com/space/HELP/43714569/REST+-+Delete"
format: markdown
---
> Macro (anchor)

The EWDelete operation deletes the specified records. If any specified record can't be successfully deleted, none of the records are deleted.

- **Returns**: nothing, when the operation is successful; an error message when the operation is unsuccessful.
- **Supported Content-Type**: <span style="color: #505050">application/</span>x-www-form-urlencoded
- <span style="color: #333333">Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see </span>[REST Interface](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).
- Additionally, the URL must contain one or more record identifiers and the delete rule name, and optionally the substitute record identifiers.

#### Notes

The **deleteRule** parameter defines one of the following strategies to be applied for dependent records:

- ERROR_IF_DEPENDANTS - operation fails when there are any dependent records.
- APPLY_DELETE_WHERE_POSSIBLE - tries to delete all dependent records. When delete cannot be done, an attempt to unlink the record is made.
- DELETE_WHERE_POSSIBLE_OTHERWISE_UNLINK - same as above.
- APPLY_UNLINK - tries to unlink dependent records.
- UNLINK_WHERE_POSSIBLE_OTHERWISE_DELETE - tries to unlink all dependent records; when unlink cannot be done an attempt to delete the record is made.
- REPLACE_WITH_ANOTHER - tries to link dependent records to the substitute one specified in replacementKeys.

The **subs** parameter is taken in consideration only if the deleteRule REPLACE_WITH_ANOTHER is specified. If used, this parameter should contain identifiers of records from the same table to be used as substitutes. For each record dependent on the record being deleted, a record with a corresponding replacement key will become the parent one.

> ⚠️ - If the specific strategy fails, the error message returned will suggest alternatives to be used.
> ⚠️ - If APPLY_DELETE_WHERE_POSSIBLE or DELETE_WHERE_POSSIBLE_OTHERWISE_UNLINK strategies are used and the configuration of the knowledgebase allows it, a special "Fast Delete" algorithm is used.

## Example

Assume an instance of Agiloft is available on localhost, port 8080 and is called "Demo". Delete the record updated in the [REST Update Example](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43714575).

The following request is issued: 

```javascript
 https://localhost:8080/ewws/EWDelete?$KB=Demo
    &$table=Contacts.Employees&$login=admin&$password=qwerty
    &$lang=en&id=358&deleteRule=APPLY_DELETE_WHERE_POSSIBLE 
```

## JavaScript Example

Here is an example for a JavaScript-based client that invokes the REST interface via AJAX: 

```javascript
    function xmlhttpGet (strURL) {
        var xmlHttpReq=false;
        var self=this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            try {
                netscape.security.PrivilegeManager.
enablePrivilege("UniversalBrowserRead");
            } catch (e) {
                alert("Permission UniversalBrowserRead denied.");
            }
            self.xmlHttpReq=new XMLHttpRequest();
        }// IE
        else if (window.ActiveXObject) {
            self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP");
        }
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.onreadystatechange=requestComplete;
        self.xmlHttpReq.send(null);
    }
    function requestComplete() {
        if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") {
            alert ("Delete completed");
        }
    }
    function main() {
        xmlhttpGet('https://localhost:8080/ewws/EWDelete?$KB=Demo
        &$table=Contacts.Employees&$login=admin&$password=qwerty
        &$lang=en&id=358
        &deleteRule=APPLY_DELETE_WHERE_POSSIBLE');
    } 
```

# Error Codes

The below error codes are for EWDelete only, but are not an extensive list of possible error codes. For any errors not listed here, consult the General Error Codes section of [https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

|  |  |  |  |
| --- | --- | --- | --- |
| **Scenario** | **Type** | **Code** | **Description** |
| When the deleteRule is NULL OR if deleteRule = REPLACE_WITH_ANOTHER and substitute is null | VALIDATION | 400 | EWWrongDataException → One has to specify deleteRule, id and substitute values. |
| When the record with recordId passed in the request doesn’t exist | VALIDATION | 400 | EWWrongDataException → Record with index <indexForMultipleIds> and key <recordId> not found |
| When the recordIds passed in the request for deleting contains linked records and deleteRule = APPLY_DELETE_WHERE_POSSIBLE or DELETE_WHERE_POSSIBLE_OTHERWISE_UNLINK | VALIDATION | 409 | EWOperationException → Operation cannot be done. Not all records can be removed. |
| When the deleteRule = ERROR_IF_DEPENDANTS and the record has dependants | VALIDATION | 409 | EWOperationException → Operation cannot be done. Record has <noOfDependants> dependants |
| When the deleteRule = APPLY_UNLINK and the unlink cannot be performed | VALIDATION | 409 | EWOperationException → Operation cannot be done. Impossible to UNLINK the following relationship: <relationship>. This relationship may be removed with the following rule(s): <ruleDetails>. |
| When the deleteRule = APPLY_DELETE_WHERE_POSSIBLE or DELETE_WHERE_POSSIBLE_OTHERWISE_UNLINK and the unlink cannot be performed | VALIDATION | 409 | EWOperationException → Operation cannot be done. Impossible to DELETE or UNLINK the following relationship: <relationship>. This relationship may be removed with the following rule(s): <ruleDetails>. |
| When the deleteRule = UNLINK_WHERE_POSSIBLE_OTHERWISE_DELETE and the unlink or delete cannot be performed | VALIDATION | 409 | EWOperationException → Operation cannot be done. Impossible to UNLINK or DELETE the following relationship: <relationship>. This relationship may be removed with the following rule(s): <ruleDetails>. |
| When the deleteRule = REPLACE_WITH_ANOTHER and the replace cannot be done | VALIDATION | 409 | EWOperationException → Operation cannot be done. Impossible to REPLACE the following relationship: <relationship>. This relationship may be removed with the following r |

> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)