# Finalize an upload

Source: https://amanucci.com/nl/docs/developers/api/artifacts/finalizeUpload

## POST /v1/entities/{entityId}/artifacts/{artifactId}/finalize

Finalize an upload

Step 3 of 3, through the one intake door: the object is verified through the bucket port (it exists; its size and sha256 are what presign bound), its magic bytes must be the declared kind (422 `artifact_kind_mismatch`), and the `artifact` row and what its fate demands — the `import`/`extract` work item, or an email's child artifacts — are written in ONE transaction. A second finalize is duplicate-ok (200, `outcome: exists`); bytes these books already hold under another id answer that artifact (200, `outcome: duplicate`). Everything the artifact needs was pinned at presign, and nothing a client carries is trusted about the file. One optional body field, `answersRequestId`: a `document` ask this file answers — the ask is answered with THIS artifact in the same transaction (the answer is the file, not a note). It must name an open document ask on these books the uploader may answer (a client seat; the addressee rule of `answerClientRequest`), else 422 `request_not_answerable` (403 `owner-required` / `not-addressee` for a member the ask is not for) and nothing is uploaded.

Operation ID: `finalizeUpload`

### Parameters

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

### Request body

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

### Responses

#### 200 Duplicate-ok: this artifact was finalized before.

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

#### 201 The artifact and the work item it entered the loop with.

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

#### 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"
    }
  }
}
```
