# Send a document

Source: https://amanucci.com/nl/docs/developers/api/documents/sendDocument

## POST /v1/entities/{entityId}/documents/{documentId}/send

Send a document

Send a document: a draft is finalized first, as `finalizeDocument` would, then each rail of the plan is tried until one delivers — Peppol, falling back to the email when it refuses or fails; `rail` starts the plan there (`email`), or names `download` alone. Each attempt is one row, recorded before its rail is asked; a refused or failed delivery is an answer (200), the document then `ready` to be sent again. Judged before anything is written, so a draft nobody can receive is never numbered: Peppol for a quote is 422 `rail_not_for_kind`, no rail at all 422 `no_recipient`; finalize's own refusals as `finalizeDocument` answers them. Idempotent by `sendId`: a replay answers the same send, writing nothing; a send id another document's send holds is 409 `send_id_conflict`. A quote a newer one replaces is 409 `quote_superseded`; a document revised after `expectedRevisionSeq`, 409 `revision_conflict`; nothing written for either. While an attempt of the document is in flight (its rail's answer not yet recorded, as after `send_unsettled`), a new send is 409 `send_in_flight`, its rail never asked: that answer may have reached the customer.

Operation ID: `sendDocument`

### Parameters

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

### Request body

```json
{
  "required": true,
  "content": {
    "application/json": {
      "schema": {
        "type": "object",
        "properties": {
          "expectedRevisionSeq": {
            "type": "integer",
            "minimum": 0,
            "description": "The draft's head revision the sender reviewed (`getDocument`'s `revisionSeq`): a document revised since is 409 `revision_conflict`, nothing written, so a revise from another tab never goes out unseen; a finalized document's head is frozen with it, so the read's `revisionSeq` still names it (Send again). An email attempt goes only to the address its document names as it stands (`document_send_recipient_current`): a readdress that lands between the plan and its email attempt is 409 `revision_conflict` too, after the draft was numbered or a Peppol attempt was recorded, which stay; the document is then numbered and not sent, to be reviewed and sent again. Absent: no revision is pinned."
          },
          "rail": {
            "type": "string",
            "enum": [
              "peppol",
              "email",
              "download"
            ],
            "description": "A delivery rail (`document_send_rail_vocabulary`): `peppol` (the customer's endpoint, from the entity's participant id, over the deployment's Peppol rail: the not-live one refuses every attempt in fixed words and the email follows, the demo one a deployment without real clients may wire answers delivered without sending anything), `email` (the customer's first address) or `download` (delivered once its attempt is recorded)."
          },
          "sendId": {
            "type": "string",
            "format": "uuid",
            "description": "A uuid v7 the client mints for this send: its idempotency key, and its first attempt's id."
          }
        },
        "required": [
          "sendId"
        ],
        "additionalProperties": false
      }
    }
  }
}
```

### Responses

#### 200 The send's attempts and the document's first delivery.

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

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