# Remove Document

**Endpoint**

`DELETE/v2/billing/operation/{id}/document/{documentId}`

**Link**

{% embed url="<https://stagep.tst-apidmndelss.com/openapi/v2.html#/operations/Billing_RemoveDocument>" %}

### **Request**

#### **Path Parameters**

| Parameter        | Type     | Description                               | Required | Example        |
| ---------------- | -------- | ----------------------------------------- | -------- | -------------- |
| **`id`**         | `string` | **Operation ID** to remove document from. | Yes      | `"op_12345"`   |
| **`documentId`** | `string` | **Document ID** to remove from operation. | Yes      | `"doc_abc123"` |

#### **Headers**

| Key             | Value              | Required |
| --------------- | ------------------ | -------- |
| `Authorization` | `Bearer <JWT>`     | Yes      |
| `Accept`        | `application/json` | Yes      |

***

### **Response (200 OK)**

Returns the updated operation object with the specified document removed from the documents array.

#### **Response Fields**

Returns the complete operation object (same structure as Get Operation), with the documents array updated to exclude the removed document.

**Example Response (After Removing One Document):**

```json
{
  "item": {
    "opid": "op_12345",
    "isVisible": true,
    "status": "PENDING",
    "type": "WITHDRAW",
    "paymentType": "SWIFT",
    "createdAt": "2024-05-20T10:30:00Z",
    "updatedAt": "2024-05-21T15:30:00Z",
    "source": {
      "account": {
        "id": "acc_12345",
        "name": "Business USD Account",
        "number": "ACC001",
        "customer": {
          "cuid": "cust_12345",
          "name": "Acme Inc."
        }
      }
    },
    "destination": {
      "counterpartyAccount": {
        "id": "cpa_78901",
        "name": "Supplier Account",
        "number": "IBAN123456789",
        "counterparty": {
          "suid": "suid_abc123",
          "name": "Global Suppliers Ltd",
          "bankName": "International Bank"
        }
      }
    },
    "sourceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "5000",
        "nanos": 0
      }
    },
    "destinationAmount": {
      "sum": {
        "currencyCode": "EUR",
        "units": "4600",
        "nanos": 0
      }
    },
    "commissionAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "25",
        "nanos": 0
      }
    },
    "currentBalanceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "45000",
        "nanos": 0
      }
    },
    "comment": "Q2 supplier payment",
    "isParent": true,
    "reference": "REF202405201234",
    "customer": {
      "cuid": "cust_12345",
      "name": "Acme Inc."
    },
    "documents": [
      {
        "guid": "doc_def456",
        "fileName": "contract_agreement.pdf",
        "size": 2048000,
        "mime": "application/pdf",
        "docType": "OPERATION_DOCUMENT",
        "info": "Service Contract",
        "isLock": false,
        "createAt": "2024-05-21T14:25:00Z"
      }
    ]
  }
}
```

**Example Response (After Removing All Documents):**

```json
{
  "item": {
    "opid": "op_12345",
    "isVisible": true,
    "status": "PENDING",
    "type": "WITHDRAW",
    "paymentType": "SWIFT",
    "createdAt": "2024-05-20T10:30:00Z",
    "updatedAt": "2024-05-21T15:30:00Z",
    "source": {
      "account": {
        "id": "acc_12345",
        "name": "Business USD Account",
        "number": "ACC001",
        "customer": {
          "cuid": "cust_12345",
          "name": "Acme Inc."
        }
      }
    },
    "destination": {
      "counterpartyAccount": {
        "id": "cpa_78901",
        "name": "Supplier Account",
        "number": "IBAN123456789",
        "counterparty": {
          "suid": "suid_abc123",
          "name": "Global Suppliers Ltd",
          "bankName": "International Bank"
        }
      }
    },
    "sourceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "5000",
        "nanos": 0
      }
    },
    "destinationAmount": {
      "sum": {
        "currencyCode": "EUR",
        "units": "4600",
        "nanos": 0
      }
    },
    "commissionAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "25",
        "nanos": 0
      }
    },
    "currentBalanceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "45000",
        "nanos": 0
      }
    },
    "comment": "Q2 supplier payment",
    "isParent": true,
    "reference": "REF202405201234",
    "customer": {
      "cuid": "cust_12345",
      "name": "Acme Inc."
    },
    "documents": []
  }
}
```

***

### **Examples**

#### **Request**

```bash
curl -X DELETE 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document/doc_abc123' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Accept: application/json'
```

#### **Scenario: Removing Multiple Documents**

*Remove documents one by one using separate requests*

```bash
# Remove first document
curl -X DELETE 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document/doc_abc123' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Accept: application/json'

# Remove second document
curl -X DELETE 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document/doc_def456' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Accept: application/json'
```

***

### **Error Responses**

1. **Operation Not Found**:

   ```json
   { "error": "Operation not found: op_99999" }
   ```
2. **Document Not Found**:

   ```json
   { "error": "Document not found: doc_99999" }
   ```
3. **Document Not Attached**:

   ```json
   { "error": "Document doc_abc123 is not attached to operation op_12345" }
   ```
4. **Operation Not Editable**:

   ```json
   { "error": "Cannot modify documents for completed operations" }
   ```
5. **Locked Document**:

   ```json
   { "error": "Document is locked and cannot be removed" }
   ```

***

### **Notes**

* **Document Preservation**: The document itself is not deleted from the system, only the association with the operation is removed
* **Multiple Removal**: Can remove multiple documents by calling the endpoint multiple times
* **Status Restrictions**: Typically cannot remove documents from completed/failed/canceled operations
* **Audit Trail**: Document removal is logged for compliance purposes
* **Locked Documents**: Some documents may be locked (e.g., by compliance team) and cannot be removed

**Typical Use Cases**:

* Correcting mistakenly attached documents
* Replacing outdated documents with updated versions
* Removing unnecessary supporting documents
* Compliance cleanup and document management

**Workflow for Document Replacement**:

1. Remove old document using this endpoint
2. Upload new document via document upload endpoint
3. Attach new document to operation using Add Document endpoint

***

### **Security Considerations**

* Requires proper authorization to modify operation documents
* Operations in certain statuses may be restricted from document modifications
* Some documents may have additional protection/locking mechanisms


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.delos.financial/operations/remove-document.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
