# Getting started

Your first call against the Risk Register REST API. Curl-based, ~5 minutes from zero to a working risk created via the API.

By the end of this you'll have:

1. Minted a personal access token.
2. Listed the registers in your org.
3. Created a new risk in a register.
4. Verified the risk by reading it back.
5. Practised an idempotent retry.

You'll need: a Risk Register account, command-line `curl`, command-line `jq` (optional, for pretty-printing). Plan tier doesn't matter - personal access tokens are available on every plan including Free.

## Step 1: Mint a personal access token

In the app, navigate to **Personal access tokens** in your user menu (or visit `/account/personal-access-tokens` directly).

Click **Create token**, give it a memorable name (e.g. "Curl tutorial"), keep **Make changes** (step 3 creates a risk directly, which **Ask me first** doesn't allow), and click **Create**.

Copy the plaintext token immediately. It's shown **once** and never again. If you lose it, revoke and create a new one - the existing one is unrecoverable.

A personal access token (PAT) looks like:

```
rr_pat_live_<43 base64url characters>
```

For the rest of this tutorial, export it as an environment variable so the examples are copy-pasteable:

```bash
export RR_PAT="rr_pat_live_..."
```

## Step 2: List your registers

```bash
curl -s https://riskregister.com/api/v1/registers \
  -H "Authorization: Bearer $RR_PAT" | jq .
```

You should see something like:

```json
{
  "data": [
    {
      "id": "8f3a2b1c-7d9e-4f0a-b3c5-d2e6f7a8b9c0",
      "registerRef": "REG-0001",
      "name": "Information security risks",
      "slug": "information-security",
      "type": "enterprise",
      "status": "active",
      "scoringMatrixKind": "iso31000_5x5",
      "reviewCadence": "quarterly",
      "createdAt": "2026-05-15T10:00:00.000Z",
      "updatedAt": "2026-05-28T12:00:00.000Z"
    }
  ],
  "pagination": {
    "next_cursor": null,
    "has_more": false
  },
  "requestId": "..."
}
```

If your org has no registers yet, `data` is empty. Create one first, in the app or with `POST /api/v1/registers`.

Note the `registerRef` (`REG-0001`). Every entity has a human-readable per-org ref alongside its UUID. You can use either at every path that takes an id - they resolve to the same row. The rest of this tutorial uses refs because they're easier to read.

## Step 3: Create a risk

Pick a register ref from the list above. Every risk also needs a category, given by its UUID. List the categories your organisation can use and copy one's `id`:

```bash
curl -s https://riskregister.com/api/v1/risk-categories \
  -H "Authorization: Bearer $RR_PAT" | jq '.data[] | {id, name}'
```

Now POST a risk, with that `id` in place of `<category-uuid>`:

```bash
curl -s -i -X POST https://riskregister.com/api/v1/registers/REG-0001/risks \
  -H "Authorization: Bearer $RR_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Lost laptop with customer data",
    "description": "An employee laptop containing customer data is lost or stolen.",
    "categoryId": "<category-uuid>",
    "inherentLikelihood": 3,
    "inherentImpact": 5,
    "residualLikelihood": 2,
    "residualImpact": 4,
    "treatment": "mitigate",
    "status": "open"
  }'
```

A few things to notice:

- `-i` shows response headers - useful for the next step.
- `categoryId` is a category's UUID, from `GET /api/v1/risk-categories`. A name or slug is refused with `400 VALIDATION_ERROR`.
- Score fields range 1–5 on the default `iso31000_5x5` matrix. On a `simple_3x3` matrix register, the same fields range 1–3.
- `treatment` is one of `mitigate`, `accept`, `transfer`, `avoid`. `status` is `open`, `under_review` or `closed` when you create or edit a risk. The fourth status, `accepted`, is set only by a formal acceptance, `POST /api/v1/risks/{id}/accept`, which records the rationale and any expiry; setting `accepted` any other way returns `400` with subcode `ACCEPTANCE_REQUIRED`. The `accept` treatment is a different field and needs no acceptance: it records the intended response, not the sign-off.

Expected response (truncated):

```
HTTP/1.1 201 Created
ETag: W/"0000019018a5e3c2"
X-RateLimit-Limit-Mutations: 100
Content-Type: application/json

{
  "data": {
    "id": "5dba8a3c-9b71-4f9b-9b9a-3b8b2a1c4d2e",
    "riskRef": "RISK-0042",
    "title": "Lost laptop with customer data",
    "...": "..."
  },
  "requestId": "..."
}
```

Save the `riskRef`:

```bash
RISK_REF="RISK-0042"
```

## Step 4: Read it back

```bash
curl -s https://riskregister.com/api/v1/risks/$RISK_REF \
  -H "Authorization: Bearer $RR_PAT" | jq .
```

The response is the same DTO shape as the POST response, wrapped in `{ data, requestId }`.

The server emits an `ETag` header on every single-resource GET. The POST response in step 3 carried one too. Send it back on a later PATCH to make the change safe against concurrent edits: see [ETag and optimistic concurrency](https://riskregister.com/docs/etag-concurrency.md).

## Step 5: Practise an idempotent retry

Real-world API calls fail. A network timeout on POST leaves you guessing whether the risk was created. Without idempotency, retrying blindly creates duplicates.

The fix: supply an `Idempotency-Key` header on the first call. Then retry with the same key on failure. Same key plus same body returns the risk the first call created, with `200` rather than a second `201`; same key plus different body returns 409.

Try it:

```bash
KEY=$(uuidgen)

# First attempt
curl -s -X POST https://riskregister.com/api/v1/registers/REG-0001/risks \
  -H "Authorization: Bearer $RR_PAT" \
  -H "Idempotency-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Phishing attack via spoofed vendor email",
    "categoryId": "<category-uuid>",
    "inherentLikelihood": 4,
    "inherentImpact": 5,
    "residualLikelihood": 2,
    "residualImpact": 3,
    "treatment": "mitigate",
    "status": "open"
  }' | jq '.data.riskRef'
# → "RISK-0043"

# Retry with the same key + same body (simulating a network retry)
curl -s -X POST https://riskregister.com/api/v1/registers/REG-0001/risks \
  -H "Authorization: Bearer $RR_PAT" \
  -H "Idempotency-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Phishing attack via spoofed vendor email",
    "categoryId": "<category-uuid>",
    "inherentLikelihood": 4,
    "inherentImpact": 5,
    "residualLikelihood": 2,
    "residualImpact": 3,
    "treatment": "mitigate",
    "status": "open"
  }' | jq '.data.riskRef'
# → "RISK-0043"   (same ref! the second call replayed the first)
```

You created exactly one risk. The second call returned the original outcome without creating a duplicate.

What happens if you retry with a different body? Change only `"title"` and send it again (`-i` shows the status line):

```bash
curl -s -i -X POST https://riskregister.com/api/v1/registers/REG-0001/risks \
  -H "Authorization: Bearer $RR_PAT" \
  -H "Idempotency-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Different title",
    "categoryId": "<category-uuid>",
    "inherentLikelihood": 4,
    "inherentImpact": 5,
    "residualLikelihood": 2,
    "residualImpact": 3,
    "treatment": "mitigate",
    "status": "open"
  }'
# → 409 with details.subcode = "API_V1_IDEMPOTENCY_BODY_MISMATCH"
```

This is the safety net. If your retry logic accidentally mutates the body between attempts, the server tells you instead of silently creating something you didn't expect.

## What you built

You authenticated against the API with a personal access token, listed your registers, created a risk, read it back, and proved that idempotent retries do the right thing.

## Next steps

| Topic | Read next |
| --- | --- |
| Update a risk safely under concurrent edits | [ETag and optimistic concurrency](https://riskregister.com/docs/etag-concurrency.md) |
| Receive push events when risks change | [Webhooks](https://riskregister.com/docs/webhooks.md) |
| Paginate through a large register | [Pagination](https://riskregister.com/docs/pagination.md) |
| Drive the API from an AI assistant (Claude Code, Cursor) | [MCP endpoint](https://riskregister.com/docs/mcp.md) |
| Generate a register from a description | `POST /api/v1/registers/from-context` - see [openapi.yaml](https://riskregister.com/docs/api/openapi.yaml) |
| Filter risks by status, score band, owner | `GET /api/v1/registers/{id}/risks?status=open&score_band=critical` - see [openapi.yaml](https://riskregister.com/docs/api/openapi.yaml) |
| Assess or treat a risk, with your rationale | `POST /api/v1/risks/{id}/{assess,treat}`: each is recorded as its own event, with the rationale |
| Use organisation API keys instead of PATs | [Authentication §Organisation API keys](https://riskregister.com/docs/authentication.md#organisation-api-keys) |

## Troubleshooting

**401 Unauthorized** - the token is missing, malformed, unknown or revoked, or its secret doesn't match. All five failure modes look identical from the outside. Double-check the `Authorization: Bearer ` prefix and the token's trailing characters. A message saying the token expired on a date means just that: make a new one under Personal access tokens.

**403 Forbidden saying personal access tokens are disabled** - Risk Register has switched personal access tokens off for your organisation. Only Risk Register can switch them back on, so ask your admin to contact support. (This refusal carries a message, not a subcode.)

**403 Forbidden with subcode `ORG_SUSPENDED`** - Risk Register has suspended your organisation. Contact your admin.

**429 Too Many Requests** - you've hit the rate limit. The response includes `Retry-After: <seconds>`. Honour it. See [Rate limits](https://riskregister.com/docs/rate-limits.md).

**404 Not Found** - the entity doesn't exist, doesn't belong to your org (we never leak cross-tenant existence), or has been deleted. Check the ref or UUID against the matching list endpoint first (`GET /api/v1/registers` for a register, `GET /api/v1/registers/{id}/risks` for a risk).

**409 Conflict with subcode `API_V1_IDEMPOTENCY_BODY_MISMATCH`** - you reused an `Idempotency-Key` with a different body. Generate a fresh key.

**500 Internal Server Error** - something we didn't expect. Quote the `requestId` from the error envelope when filing a ticket.

For the full error surface, see [Errors](https://riskregister.com/docs/errors.md).
