# Add Document

**Endpoint**

`POST/v2/billing/operation/{id}/document`

**Link**

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

First, you need to use the **Upload Document** method. In response, we receive a document ID, which we then specify in the **Add Document** method. The URL in the method must include the ID of the operation to which we are attaching the document: `{{baseUrl}}/v2/billing/operation/5b55db86-17e5-4612-81f9-29d3bd5082a1/document`

### **Request**

#### **Path Parameters**

| Parameter | Type     | Description                             | Required | Example                                  |
| --------- | -------- | --------------------------------------- | -------- | ---------------------------------------- |
| **`id`**  | `string` | **Operation ID** to attach document to. | Yes      | `"5b55db86-17e5-4612-81f9-29d3bd5082a1"` |

#### **Headers**

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

#### **Request Body (JSON)**

| Field            | Type     | Description & Requirements                                          | Required | Example             |
| ---------------- | -------- | ------------------------------------------------------------------- | -------- | ------------------- |
| **`documentId`** | `string` | **ID of the document** (must be previously uploaded to the system). | Yes      | `"doc_abc123"`      |
| **`name`**       | `string` | **Document display name** (for reference).                          | No       | `"Invoice_Q2_2024"` |

**Example Request Body:**

```json
{
  "documentId": "doc_abc123",
  "name": "Supplier Invoice Q2 2024"
}
```

**Example Request Body (Minimal):**

```json
{
  "documentId": "doc_xyz789"
}
```

***

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

Returns the updated operation object with the newly attached document included in the documents array.

#### **Response Fields**

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

**Example Response:**

```json
{
  "item": {
    "opid": "5b55db86-17e5-4612-81f9-29d3bd5082a1",
    "isVisible": true,
    "status": "PENDING",
    "type": "WITHDRAW",
    "paymentType": "SWIFT",
    "createdAt": "2024-05-20T10:30:00Z",
    "updatedAt": "2024-05-21T14:20:00Z",
    "source": {
      "account": {
        "id": "	Ug6wl1EwArKX",
        "name": "Business USD Account",
        "number": "ACC001",
        "customer": {
          "cuid": "D7k3xbc-ERrj-lde9k1t3XuaE",
          "name": "Acme Inc."
        }
      }
    },
    "destination": {
      "counterpartyAccount": {
        "id": "	Uk8wl1EwArKJ",
        "name": "Supplier Account",
        "number": "IBAN123456789",
        "counterparty": {
          "suid": "D8j3xbc-ERrj-lde4k1t3XuaO",
          "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": "D7k3xbc-ERrj-lde9k1t3XuaE",
      "name": "Acme Inc."
    },
    "documents": [
      {
        "guid": "doc_abc123",
        "fileName": "invoice_q2_2024.pdf",
        "size": 1024000,
        "mime": "application/pdf",
        "docType": "OPERATION_DOCUMENT",
        "info": "Supplier Invoice Q2 2024",
        "isLock": false,
        "createAt": "2024-05-21T14:20:00Z"
      }
    ]
  }
}
```

**Example Response (Multiple Documents):**

```json
{
  "item": {
    "opid": "5b55db86-17e5-4612-81f9-29d3bd5082a1",
    "isVisible": true,
    "status": "PENDING",
    "type": "WITHDRAW",
    "paymentType": "SWIFT",
    "createdAt": "2024-05-20T10:30:00Z",
    "updatedAt": "2024-05-21T14:20:00Z",
    "source": {
      "account": {
        "id": "	Ug6wl1EwArKX",
        "name": "Business USD Account",
        "number": "ACC001",
        "customer": {
          "cuid": "D7k3xbc-ERrj-lde9k1t3XuaE",
          "name": "Acme Inc."
        }
      }
    },
    "destination": {
      "counterpartyAccount": {
        "id": "	Uk6wl1EwArKr",
        "name": "Supplier Account",
        "number": "IBAN123456789",
        "counterparty": {
          "suid": "D8j3xbc-ERrj-lde4k1t3XuaO",
          "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": "D8j3xbc-ERrj-lde4k1t3XuaO",
      "name": "Acme Inc."
    },
    "documents": [
      {
        "guid": "doc_abc123",
        "fileName": "invoice_q2_2024.pdf",
        "size": 1024000,
        "mime": "application/pdf",
        "docType": "OPERATION_DOCUMENT",
        "info": "Supplier Invoice Q2 2024",
        "isLock": false,
        "createAt": "2024-05-21T14:20:00Z"
      },
      {
        "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"
      }
    ]
  }
}
```

***

### **Examples**

#### **Request**

```bash
curl -X POST 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Content-Type: application/json' \
  -d '{
    "documentId": "doc_abc123",
    "name": "Supplier Invoice Q2 2024"
  }'
```

#### <mark style="color:red;">Request with Multiple Documents</mark>

*Note: Call endpoint multiple times to add multiple documents*

```bash
# First document
curl -X POST 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Content-Type: application/json' \
  -d '{
    "documentId": "doc_abc123",
    "name": "Invoice Q2 2024"
  }'

# Second document  
curl -X POST 'https://stagep.tst-apidmndelss.com/v2/billing/operation/op_12345/document' \
  -H 'Authorization: Bearer eyJhbGci...wNLGA' \
  -H 'Content-Type: application/json' \
  -d '{
    "documentId": "doc_def456",
    "name": "Contract Agreement"
  }'
```

***

### <mark style="color:red;">Error Responses</mark>

1. **Operation Not Found**:

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

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

   ```json
   { "error": "Document already attached to this operation" }
   ```
4. **Operation Not Editable**:

   ```json
   { "error": "Cannot modify documents for completed operations" }
   ```

***

### **Notes**

* **Document Pre-upload**: Documents must be uploaded to the system first (via separate document upload endpoint)
* **Multiple Documents**: Can attach multiple documents to a single operation
* **Document Types**: Various document types supported (invoices, contracts, statements, etc.)
* **Status Restrictions**: Typically cannot add documents to completed/failed/canceled operations
* **Audit Trail**: Document attachments are logged for compliance

**Typical Workflow**:

1. Upload document via document upload endpoint → returns `documentId`
2. Create operation or get existing operation ID
3. Attach document to operation using this endpoint
4. Operation appears in operation details with attached documents

Request sample

```
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjE2NCwiZXhwIjoxNzYxNjU0MTQ3LCJrZXkiOiI1Y2ZiOGZjN2RmYjk4ZjVkYmIyZTgwNTVkZWFhN2U2Zjk4MzEyYmE3Iiwib3RwX3ZlcmlmaWVkIjpmYWxzZX0.uTzFrsUHSQp0zdU86OnQVlbWafLlJi3tSvx0bKzBRjk
id*: 8248956e-a002-4404-aafc-be8fd8dc16b6
```

```postman_json
{
  "documentId": "string",
  "name": "string"
}
{
  "documentId": "string",
  "name": "string"
}
```

Response sample

```postman_json
{
  "item": {
    "operationId": "8248956e-a002-4404-aafc-be8fd8dc16b6",
    "isVisible": true,
    "status": "PENDING",
    "type": "EXCHANGE",
    "paymentType": "EMPTY",
    "createdAt": "2025-10-28T12:09:33Z",
    "updatedAt": "2025-10-28T12:11:33Z",
    "source": {
      "counterpartyAccount": {
        "id": "string",
        "name": "",
        "number": "",
        "counterparty": null,
        "customer": null
      }
    },
    "destination": {
      "counterpartyAccount": {
        "id": "string",
        "name": "",
        "number": "",
        "counterparty": null,
        "customer": null
      }
    },
    "sourceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "98",
        "nanos": 0
      },
      "default": {
        "currencyCode": "USD",
        "units": "98",
        "nanos": 0
      }
    },
    "destinationAmount": {
      "sum": {
        "currencyCode": "USDT_ERC20",
        "units": "98",
        "nanos": 0
      },
      "default": {
        "currencyCode": "USD",
        "units": "98",
        "nanos": 0
      }
    },
    "commissionAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "2",
        "nanos": 0
      },
      "default": {
        "currencyCode": "USD",
        "units": "2",
        "nanos": 0
      }
    },
    "currentBalanceAmount": {
      "sum": {
        "currencyCode": "USD",
        "units": "835",
        "nanos": 800000002
      },
      "default": {
        "currencyCode": "USD",
        "units": "835",
        "nanos": 800000002
      }
    },
    "comment": "testapi",
    "isParent": false,
    "reference": "string",
    "customer": {
      "id": "D7k3xbc-ERrj-lde9k1t3XuaE",
      "name": ""
    },
    "documents": []
  }
}
```


---

# 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/add-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.
