# Keep one of two documents

Source: https://amanucci.com/fr/docs/developers/api/cases/keepDocument

## POST /v1/entities/{entityId}/cases/{caseId}/keep-document

Keep one of two documents

Keep one of two documents on a live `duplicate_document` case. A duplicate takes `{ artifactId }`, the case's own artifact or the one it duplicates (`missingInfo.existing.artifactId`): keeping the existing one closes the case `evidence` and the new artifact stays evidence only, unless the other document is booked (its file read again onto the existing one's number): that booking is withdrawn, the existing one is booked if it was not, and the case closes `corrected` naming the withdrawing version; keeping the new one makes its newest reading the next version of the existing event, the artifact stapled as its evidence, and closes the case `corrected`. A contested file of one document (`missingInfo.documentId`) takes the file or the one the document's figures are read from: keeping the file closes `corrected` with the version its reading mints, keeping the other closes `evidence`. On a document not yet booked, a kept file whose reading its gate stops is still the one kept (the other `rejected`) and the case closes `evidence`, its gate case opened as what you answer next (`waitsOnCaseId`): the booking waits on it as any gated file's does, as it does on the case a still-unbooked document's figures' file already waits in. On a booked document that keep is refused, `keep_needs_check`, nothing moving: keep the booked file, then correct the booking's entry to what the file states. An invoice that could replace two receipts takes `{ receiptCaseId }`, one of `missingInfo.receipts[].caseId`: the invoice replaces that receipt and both cases close. 409, the case staying live: anything the case does not name is `document_not_in_case`; keeping the new one of a duplicate when its own document is booked onto another event is `keep_new_booked`; keeping the new one of a duplicate whose reading the gate still stops, or a document the world moved under the case, is `case_not_correctable`. Not a signed act: it posts nothing itself. The firm's alone ( (q)): a client seat is 403 `authority-required`. A case the Assembler closed because its document was booked from another of its files (a scan's gate case its e-invoice booked) is 409 `case_booked_from_file`, in words naming the kind of file it was booked from.

Operation ID: `keepDocument`

### Parameters

```json
[
  {
    "schema": {
      "type": "string",
      "format": "uuid"
    },
    "required": true,
    "name": "caseId",
    "in": "path"
  },
  {
    "schema": {
      "type": "string",
      "format": "uuid"
    },
    "required": true,
    "name": "entityId",
    "in": "path"
  }
]
```

### Request body

```json
{
  "required": true,
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/KeepDocument"
      }
    }
  }
}
```

### Responses

#### 200 The document is kept; the case, resolved.

```json
{
  "application/json": {
    "schema": {
      "$ref": "#/components/schemas/KeepDocumentResult"
    }
  }
}
```

#### 401 Dead or absent credential (`unauthenticated`).

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 403 Authenticated, present, and refused: a missing grant, a missing seat, or a missing step-up.

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 404 Absent, or hidden from this asker — the two are indistinguishable (`not-found`).

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 409 The world is not in the state the request assumed: a stale `expectedSeq`, or a transition already made.

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 422 The request did not satisfy the schema (`invalid-input`).

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 429 Too many requests on this door's bucket (`rate-limited`); refused before any handler ran, `Retry-After` says when to come back.

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```

#### 503 Temporarily unavailable; `Retry-After` says when to come back.

```json
{
  "application/problem+json": {
    "schema": {
      "$ref": "#/components/schemas/Problem"
    }
  }
}
```
