# Grant or revoke a capability

Source: https://amanucci.com/fr/docs/developers/api/grants/appendGrant

## POST /v1/entities/{entityId}/grants

Grant or revoke a capability

Open or close one door — an APPEND under optimistic concurrency, never an update, so the history of who decided what survives. `expectedSeq` is the pinned-row key: a retry is duplicate-ok, a concurrent edit is a 409. Invoicing needs document access: granting `documents.issue` while `documents.exchange` is not granted is 409 `grant_needs_exchange`, nothing written, and revoking `documents.exchange` revokes `documents.issue` too, in the same act, under the same reason. The CLIENT grants, so no firm-side capability reaches this route at all.

Operation ID: `appendGrant`

### Parameters

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

### Request body

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

### Responses

#### 200 The appended version, or the identical one a retry found already there.

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

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