# Pick the invoice a credit note corrects

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

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

Pick the invoice a credit note corrects

Name the invoice a supplier's credit note corrects, once: an inbound credit note with a status, its supplier known, above zero and linked to no invoice yet, to a live inbound invoice of the same supplier in its currency; the same pick again answers the link it made. The invoice then reads net of it (`document_status`, `document_open`: Credited, or Partly paid with the rest to pay, and Pay pays the rest). The link is set once: there is no unlink. Another entity's or an absent document is the hidden 404 `document_not_found`; a credit note still being read, a duplicate's loser, one naming no supplier, not above zero or linked to another invoice is 409 `link_not_open`; an invoice that is not one of its supplier's live inbound invoices in its currency is 422 `link_target_invalid`. A client seat, or a firm hat holding `ledger.manage`.

Operation ID: `linkCorrectedInvoice`

### 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": {
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "invoiceId"
        ],
        "additionalProperties": false
      }
    }
  }
}
```

### Responses

#### 200 The invoice it now corrects.

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

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