{
  "openapi": "3.0.3",
  "info": {
    "title": "Aylla Vault API",
    "version": "1.0.0",
    "description": "**Aylla Vault API v1** — for the mobile app and the website.\n\n### How to try it in 3 steps\n1. Open **Auth → POST /auth/login**, click **Try it out**, then **Execute**. Test account: `alex@aylla.test` / `Aylla#Test2026`.\n2. Copy the `accessToken` from the response. Click the green **Authorize** button (top right) and paste it. Now every request is signed in.\n3. Try any other endpoint. If you get `401 unauthenticated`, the token expired (they last **15 minutes**): call **POST /auth/refresh** with your `refreshToken` and authorize again.\n\n### Tokens in one minute\n- `accessToken` — sent on every call as `Authorization: Bearer …`. Lives 15 minutes.\n- `refreshToken` — only used on `POST /auth/refresh` to get a new pair silently, so the user is **not** logged out every 15 minutes. Lives 7 days. **Every refresh returns a NEW refresh token; always store the new one** (the old one stops working).\n\n### Errors\nEvery error looks like `{ \"status\": \"error\", \"code\": \"validation_failed\", \"message\": \"...\", \"errors\": { \"field\": [\"...\"] } }`. Use `code` in your app logic.\n\nFull written guide with code samples: **/docs/guide**. Postman collection: **/docs/postman.json**.\n"
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "This server (live test server: https://ayllaapi.immidots.com/api/v1)"
    }
  ],
  "tags": [
    {
      "name": "1. Auth",
      "description": "Sign in, tokens, PIN and the list of signed-in devices."
    },
    {
      "name": "2. Schemes & 100-point",
      "description": "Which documents exist, what each is worth under each scheme, and the score check."
    },
    {
      "name": "3. Cards",
      "description": "The user's vault: cards, their fields and scans."
    },
    {
      "name": "4. Sharing",
      "description": "Time-limited links to share selected fields. The `PUBLIC` endpoints need no login."
    },
    {
      "name": "5. Requests & institutions",
      "description": "Institutions can ask a person for specific fields (the person accepts or declines), and a person can find a registered institution and send it chosen fields on their own. Institutions work in their own portal; this is the person's side only."
    },
    {
      "name": "6. Voice",
      "description": "Ask questions about your cards by voice or text."
    },
    {
      "name": "7. Notifications",
      "description": "In-app alerts and the user's own activity log."
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Paste the `accessToken` from login (without the word Bearer)."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "error"
          },
          "code": {
            "type": "string",
            "example": "validation_failed"
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "usr_01m3pvanvpw9f4cbcqcp0ep40g"
          },
          "fullName": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "phone": {
            "type": "string",
            "nullable": true
          },
          "dob": {
            "type": "string",
            "example": "1992-06-15",
            "nullable": true
          },
          "role": {
            "type": "string",
            "enum": [
              "user"
            ]
          },
          "organisation": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "suspended"
            ]
          },
          "hasPin": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "institutions": {
            "type": "array",
            "description": "Institutions this person works for (open the institution portal).",
            "items": {
              "type": "object"
            }
          },
          "emailVerified": {
            "type": "boolean",
            "description": "False until the person enters the 6-digit code emailed at sign-up (only when the server requires verification)."
          },
          "phoneVerified": {
            "type": "boolean",
            "description": "Mobile number verified by text message. Switched off for now: always false."
          }
        }
      },
      "TokenResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "success"
          },
          "tokenType": {
            "type": "string",
            "example": "Bearer"
          },
          "accessToken": {
            "type": "string",
            "description": "Send as Authorization: Bearer. Valid 15 minutes."
          },
          "refreshToken": {
            "type": "string",
            "description": "Valid 7 days, single use — store the new one after every refresh. (Omitted in website cookie mode.)"
          },
          "expiresIn": {
            "type": "integer",
            "example": 900
          },
          "deviceId": {
            "type": "string"
          },
          "user": {
            "$ref": "#/components/schemas/User"
          }
        }
      }
    },
    "responses": {
      "Unauthenticated": {
        "description": "Missing/expired/invalid access token (`code: unauthenticated`) → refresh the token.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Your role may not do this (`code: forbidden`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Not found, or not yours (`code: not_found`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Invalid": {
        "description": "Validation failed (`code: validation_failed`); `errors` lists each field.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooMany": {
        "description": "Rate limited (`code: too_many_requests`). See the `Retry-After` header.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/auth/register": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Register",
        "description": "Creates a normal user and signs this device in. **Send the plain password** (HTTPS) — the server hashes it. Min 8 characters, letters + numbers. Rate limit: 5/minute.\n\nCreates a normal user and signs the device in. Saves tokens automatically.\n\nWhen `GET /config` says `emailVerificationRequired: true` the answer is **202** `{ status: \"verification_required\", email }` with no tokens: call `POST /auth/verify-email` with the emailed code.",
        "responses": {
          "201": {
            "description": "Signed in. Store `accessToken` and `refreshToken`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "fullName": "Alex Vance Johnson",
                "email": "alex.new@example.com",
                "phone": "+61412345678",
                "dob": "1992-06-15",
                "password": "Str0ngPassw0rd",
                "deviceInfo": {
                  "deviceName": "iPhone 15 Pro",
                  "deviceType": "ios",
                  "pushToken": "fcm_or_apns_token"
                }
              }
            }
          }
        }
      }
    },
    "/auth/login": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Login (password)",
        "description": "`authMethod` is `password` (default) or `pin`. `biometric_signature` is not enabled yet (501) — do Face ID/fingerprint on the device instead. Rate limit: 5/minute per email.\n\n5/min per email+IP. Saves tokens automatically.\n\nUnverified email (when verification is on): **403 `email_not_verified`**, and a new code is emailed.",
        "responses": {
          "200": {
            "description": "Signed in. Store `accessToken` and `refreshToken`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "email": "alex@aylla.test",
                "authMethod": "password",
                "credential": "Aylla#Test2026",
                "deviceInfo": {
                  "deviceName": "Postman",
                  "deviceType": "web"
                }
              }
            }
          }
        }
      }
    },
    "/auth/refresh": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Refresh token",
        "description": "Send `{ \"refreshToken\": \"...\" }`. Returns a NEW access token **and** a NEW refresh token — replace both. Do not run two refreshes at the same time with the same token: the second looks like theft and signs the device out.\n\nRotates: stores the NEW refresh token. Old one is dead.",
        "responses": {
          "200": {
            "description": "Signed in. Store `accessToken` and `refreshToken`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "refreshToken": "PASTE_REFRESH_TOKEN"
              }
            }
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Me",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "put": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Update profile",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "fullName": "Alex V. Johnson",
                "phone": "+61412345678"
              }
            }
          }
        }
      }
    },
    "/auth/pin": {
      "put": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Set PIN",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "pin": "482913",
                "currentPassword": "Aylla#Test2026"
              }
            }
          }
        }
      }
    },
    "/auth/password": {
      "put": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Change password",
        "description": "Signs out all OTHER devices.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "currentPassword": "Aylla#Test2026",
                "password": "N3wPassword99"
              }
            }
          }
        }
      }
    },
    "/auth/sessions": {
      "get": {
        "tags": [
          "1. Auth"
        ],
        "summary": "List device sessions",
        "description": "All devices the user is signed in on. `isCurrent` marks the one making the request.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/auth/sessions/{sessionId}": {
      "delete": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Revoke a device",
        "description": "Sign a device out remotely. Its tokens stop working immediately.",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/auth/logout": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Logout (this device)",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/auth/logout-all": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Logout everywhere",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/schemes": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Document schemas (default scheme)",
        "description": "Document types the user can add, with points under one scheme (default `GENERAL_100_TEMPLATE`). Five catalogue fields are switched off and never appear in `defaultFields` or on cards: `document_image`, `verification_method`, `verification_result`, `verified_at`, `document_status`. Aylla keeps no document images, verifies nothing, and the card's own status (`status` / `displayStatus`) replaces a separate document status, so apps must not ask for them. If an app sends them on a card they are ignored (not stored). The list is `hidden_fields` in `config/aylla.php`.\n\n`defaultFields` describes the form to render: `type`, `isRequired`, `isSensitive`, and `options` for dropdowns. Query: `schemeId`, `scope=catalogue` (all documents), `q`.\n\nAdd ?schemeId=NSW_FIREARMS_ADULT, ?scope=catalogue, ?q=passport",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/schemes/registry": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Scheme registry",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/schemes/registry/NSW_FIREARMS_ADULT": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Scheme detail",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/schemes/evaluate-score": {
      "post": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Evaluate score",
        "description": "Checks the user's cards against one scheme. Always show the `disclaimer` and `deficiencies` (what is missing). Result is `pass`, `fail` or `unsupported`.\n\nPreliminary result only; always show the disclaimer.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "schemeId": "GENERAL_100_TEMPLATE",
                "cardIds": [
                  "PASTE_CARDID"
                ]
              }
            }
          }
        }
      }
    },
    "/lookups/dropdowns": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Dropdown lists",
        "description": "",
        "parameters": [
          {
            "name": "list",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "STATE_TERRITORY,YES_NO"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/lookups/state-variants": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "State variants",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/lookups/sources": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Sources",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/cards": {
      "get": {
        "tags": [
          "3. Cards"
        ],
        "summary": "List cards",
        "description": "Query: `category`, `status`, `documentTypeId`, `q`, and `masked=1` to hide sensitive values in list screens.\n\nFilters: category, status, documentTypeId, q. masked=1 hides sensitive values.\n\nCard status: send `status` as `valid` (default) or `pending` (applied for, not received yet). Do not show `status` to people; show `displayStatus`, which the server works out from the expiry date: `current`, `expiring_soon` (60 days or less), `expired`, `not_received`. `expiryDate` is read from the card's Expiry date field (`yyyy-mm-dd`, null if none). `lastSharedWith` is `{name, at}` for the last institution or recipient the card went to, or null.\n\nEach card also returns `displayStatus` (`current`, `expiring_soon`, `expired`, `not_received`, `rejected`: show this, not `status`), `expiryDate` (yyyy-mm-dd or null) and `lastSharedWith` (`{ name, at }` or null). No points are returned on cards: points live in `GET /identity-score`.",
        "parameters": [
          {
            "name": "masked",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "post": {
        "tags": [
          "3. Cards"
        ],
        "summary": "Create card",
        "description": "`fields[]` come from `GET /schemes` (`key`, `label`, `type`). Fields such as passport/licence numbers are always stored as sensitive and encrypted.\n\nSaves cardId / fieldId.",
        "responses": {
          "201": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "title": "Australian Passport (Alex Vance)",
                "category": "Passport",
                "documentTypeId": "AU_PASSPORT",
                "status": "valid",
                "notes": "Renew in 2031",
                "fields": [
                  {
                    "key": "passport_number",
                    "label": "Passport number",
                    "value": "PA9823410",
                    "type": "text",
                    "isRequired": true
                  },
                  {
                    "key": "name_as_printed",
                    "label": "Name exactly as printed",
                    "value": "Alex Vance Johnson",
                    "type": "text"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/cards/{cardId}": {
      "get": {
        "tags": [
          "3. Cards"
        ],
        "summary": "Get card",
        "description": "",
        "parameters": [
          {
            "name": "cardId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "3. Cards"
        ],
        "summary": "Update card (fields replaced by id)",
        "description": "Partial update. If you send `fields` it must be the **complete** list: entries with an `id` are updated, entries without are created, missing ones are **deleted**.\n\nSending fields = the complete list. Omitted fields are deleted.",
        "parameters": [
          {
            "name": "cardId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "title": "Australian Passport (renewed)",
                "fields": [
                  {
                    "id": "PASTE_FIELDID",
                    "key": "passport_number",
                    "label": "Passport number",
                    "value": "PB0000001"
                  }
                ]
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "3. Cards"
        ],
        "summary": "Delete card",
        "description": "",
        "parameters": [
          {
            "name": "cardId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/cards/{cardId}/attachments": {
      "post": {
        "tags": [
          "3. Cards"
        ],
        "summary": "Upload attachment",
        "description": "Multipart form, field `file` (jpg, png, webp, pdf; max 8 MB; 10 per card). Returned card contains 10-minute signed image URLs.\n\nmultipart/form-data, field 'file' (jpg/png/webp/pdf, <=8MB).",
        "parameters": [
          {
            "name": "cardId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/cards/ocr-scan": {
      "post": {
        "tags": [
          "3. Cards"
        ],
        "summary": "OCR scan",
        "description": "Multipart form, field `file`. Reads the document with AI and returns fields to pre-fill the form — let the user confirm. Not stored. Returns 503 until the server has a Gemini key.\n\n503 until the server has a Gemini key.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/shares": {
      "post": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "Create share",
        "description": "Only the fields in `selectedFieldIds` are ever shown to the recipient. `passcode` is 4–8 digits. Share the returned `shareUrl`.\n\nSaves shareId.\n\nA link with no expiry date (`neverExpires: true`) keeps working until the owner revokes it, so it has guard rails: a `passcode` is required (`422 passcode_required`), no sensitive field may be included (`422 sensitive_fields_blocked`; sensitive = passport, licence, Medicare numbers and other Restricted fields), and `maxAccessCount` may go up to 1000 (50 for links that expire). If nobody opens it for 90 days it pauses itself (`status: paused`); the owner turns it back on with `POST /shares/{id}/resume`. The owner is reminded by email once a month while such links are on.\n\n`deliveryChannel`: `email` sends the link to `recipientContact` (must be an email address; the passcode is in the email too unless `GET /config` says `sharePasscodeInEmail` is false; at most 20 share emails per user per day: `429 share_email_limit`). `sms` answers `422 channel_unavailable` until text messages are switched on. `push` is not a share channel. Expiry: `expirationMinutes` up to 525600 (1 year), or `neverExpires: true` (see above). Errors for no-expiry links: `passcode_required`, `sensitive_fields_blocked` (422).",
        "responses": {
          "201": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "cardId": "PASTE_CARDID",
                "selectedFieldIds": [
                  "PASTE_FIELDID"
                ],
                "recipientName": "Qantas Airways Check-in",
                "recipientContact": "checkin@qantas.com",
                "deliveryChannel": "email",
                "expirationMinutes": 60,
                "maxAccessCount": 3,
                "passcode": "7821",
                "neverExpires": false
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "List my shares",
        "description": "Each link has `status` (`active`, `expired`, `revoked`, `exhausted`, `paused`), `neverExpires`, `pausedAt`, and `expiresAt` (null when `neverExpires`).",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/shares/{shareId}": {
      "get": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "Share detail + access log",
        "description": "",
        "parameters": [
          {
            "name": "shareId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/shares/{shareId}/revoke": {
      "post": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "Revoke share",
        "description": "",
        "parameters": [
          {
            "name": "shareId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/shares/public/{shareId}": {
      "get": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "PUBLIC · recipient metadata",
        "description": "**No login.** Shows who the link is for and whether a passcode is needed. Does not use up a view.\n\nNo account needed. Does not use up a view.\n\n`expiresAt` is null when the link has no expiry date. Errors: `404 share_not_found`, `410 share_revoked | share_paused | share_expired | share_exhausted`, `423 share_locked`.",
        "parameters": [
          {
            "name": "shareId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        },
        "security": []
      }
    },
    "/shares/public/{shareId}/unlock": {
      "post": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "PUBLIC · unlock",
        "description": "**No login.** Each successful call uses one view. 5 wrong passcodes lock the link (423).\n\nUses one view. 5 wrong passcodes lock the link.\n\n`expiresAt` is null when the link has no expiry date. `410 share_paused` when the owner's link was paused.",
        "parameters": [
          {
            "name": "shareId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "passcode": "7821"
              }
            }
          }
        }
      }
    },
    "/requests": {
      "get": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "List my requests",
        "description": "Requests institutions sent to the signed-in person, plus documents the person sent to institutions on their own. Each item has `initiatedBy` (`institution` or `user`) and `institutionName` = the institution name.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "pending"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/requests/{requestId}": {
      "get": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "Get request",
        "description": "One of my requests. Values I sent are shown masked.",
        "parameters": [
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/requests/{requestId}/fulfill": {
      "post": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "User: fulfil",
        "description": "The values sent to the institution are always taken from the person's vault.",
        "parameters": [
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "submittedData": [
                  {
                    "cardId": "PASTE_CARDID",
                    "fieldLabel": "Passport number"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/requests/{requestId}/decline": {
      "post": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "User: decline",
        "description": "",
        "parameters": [
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/voice/query": {
      "post": {
        "tags": [
          "6. Voice"
        ],
        "summary": "Voice query",
        "description": "Only the cards in `vaultContextCardIds` (max 5) are sent to the AI. `audioBase64` is MP3 (null if speech is unavailable → read `responseText` aloud with the phone's own voice). 503 until the server has Google keys.\n\n503 until the server has Gemini + TTS keys.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "prompt": "What is my passport expiry date?",
                "language": "en-AU",
                "accent": "Australian",
                "vaultContextCardIds": [
                  "PASTE_CARDID"
                ],
                "includeAudio": true,
                "audioFormat": "mp3"
              }
            }
          }
        }
      }
    },
    "/notifications": {
      "get": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "List notifications",
        "description": "",
        "parameters": [
          {
            "name": "unread",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "delete": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "Clear notifications",
        "description": "Delete all of my notifications.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/notifications/mark-read": {
      "patch": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "Mark read (ids)",
        "description": "",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "ids": [
                  "ntf_..."
                ]
              }
            }
          }
        }
      }
    },
    "/notifications/preferences": {
      "get": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "Get preferences",
        "description": "`{ pushEnabled, smsEnabled, emailEnabled, emailKyc, emailSharing }`. `emailKyc` (default on): email when an institution asks for documents, sends a reminder or answers one. `emailSharing` (default off): email when a link you shared is opened. Security emails (new sign-in, changed password) are always sent. Emails never contain document values.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "put": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "Update preferences",
        "description": "Send any subset of `pushEnabled`, `smsEnabled`, `emailEnabled`, `emailKyc`, `emailSharing`. Security emails cannot be switched off.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "pushEnabled": true,
                "smsEnabled": false,
                "emailEnabled": true,
                "emailKyc": true,
                "emailSharing": false
              }
            }
          }
        }
      }
    },
    "/audit-logs": {
      "get": {
        "tags": [
          "7. Notifications"
        ],
        "summary": "My audit trail",
        "description": "",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "50"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Health check",
        "security": [],
        "responses": {
          "200": {
            "description": "{ status: ok }"
          }
        }
      }
    },
    "/requests/{requestId}/withdraw": {
      "post": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "Withdraw what I sent",
        "description": "Take back documents I sent to an institution on my own (`initiatedBy: user`) while they are unreviewed. The institution no longer holds the values.",
        "parameters": [
          {
            "name": "requestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "Already reviewed or withdrawn (`request_closed`)"
          }
        }
      }
    },
    "/institutions": {
      "get": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "Find an institution",
        "description": "Registered, active institutions by name (max 20). Shows only `id`, `name` and `category`.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Search text"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                },
                "example": [
                  {
                    "id": "inst_01...",
                    "name": "Mira Insurance",
                    "category": "insurance"
                  }
                ]
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/institutions/{institutionId}/share": {
      "post": {
        "tags": [
          "5. Requests & institutions"
        ],
        "summary": "Send fields to an institution",
        "description": "Send chosen fields of my own cards straight to an institution. It appears in the institution's portal, ready to review. Rate limit 20/min.",
        "parameters": [
          {
            "name": "institutionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "message": "Documents for my policy",
                "items": [
                  {
                    "cardId": "card_01...",
                    "fieldIds": [
                      "pf_01..."
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "id": "req_01...",
                  "institution": {
                    "id": "inst_01...",
                    "name": "Mira Insurance"
                  },
                  "status": "fulfilled",
                  "fieldsShared": 1,
                  "sentAt": "2026-10-17T10:00:00+00:00"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`institution_unavailable`: it cannot receive documents right now"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/auth/verify-email": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Verify email (6-digit code)",
        "description": "Enter the code emailed at sign-up. Verifies the email and signs the device in (same response as login). `422 invalid_code` / `code_expired`.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "email": "you@example.com",
                "code": "123456",
                "deviceInfo": {
                  "deviceName": "iPhone",
                  "deviceType": "ios"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in. Store accessToken and refreshToken.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      }
    },
    "/auth/resend-verification": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Resend the verification code",
        "description": "Always answers 200 so it cannot reveal who has an account. At most one code a minute.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "email": "you@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      }
    },
    "/auth/forgot-password": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Forgot password: email a reset code",
        "description": "Always answers 200. Works for vault users and institution staff; owner-console accounts are not reset this way.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "email": "you@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      }
    },
    "/auth/reset-password": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Set a new password with the emailed code",
        "description": "Signs every device out and emails a 'password changed' alert. The person then signs in again.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "email": "you@example.com",
                "code": "123456",
                "password": "NewPassword9"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password updated"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      }
    },
    "/config": {
      "get": {
        "tags": [
          "1. Auth"
        ],
        "summary": "What this server can do now",
        "description": "`{ emailVerificationRequired, channels: { email, sms }, sharePasscodeInEmail }`. Hide options that are false.",
        "security": [],
        "responses": {
          "200": {
            "description": "Server capabilities"
          }
        }
      }
    },
    "/shares/{shareId}/resume": {
      "post": {
        "tags": [
          "4. Sharing"
        ],
        "summary": "Resume a paused link",
        "description": "Turns a PAUSED link back on. A link with no expiry date pauses itself after 90 days without a view. `410 share_revoked` if it was revoked.",
        "parameters": [
          {
            "name": "shareId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{ resumed: true, status: \"active\" }"
          },
          "404": {
            "description": "Not your link"
          },
          "410": {
            "description": "share_revoked"
          }
        }
      }
    },
    "/identity-score": {
      "get": {
        "tags": [
          "2. Schemes & 100-point"
        ],
        "summary": "Identity Score (plain-language 100-point screen)",
        "description": "The Identity Score screen: where the signed-in person stands against the general 100-point guide, in plain words, and which documents would finish it. Build one tab or screen from it; do not show points anywhere else (the vault list, card badges).\n\n```json\n{\n  \"schemeId\": \"GENERAL_100_TEMPLATE\",\n  \"guideName\": \"General 100-point guide\",\n  \"threshold\": 100,\n  \"totalPoints\": 40,\n  \"mainPoints\": 0,\n  \"supportingPoints\": 40,\n  \"pointsToGo\": 60,\n  \"complete\": false,\n  \"missing\": [\n    {\n      \"kind\": \"points\",\n      \"amount\": 60,\n      \"text\": \"60 more points\"\n    },\n    {\n      \"kind\": \"main\",\n      \"text\": \"One main ID, such as a passport or birth certificate\"\n    }\n  ],\n  \"counted\": [\n    {\n      \"cardId\": \"card_01m3…\",\n      \"title\": \"Driver Licence\",\n      \"documentTypeId\": \"AU_DRIVER_LICENCE\",\n      \"points\": 40,\n      \"group\": \"supporting\",\n      \"showsPhoto\": true,\n      \"showsAddress\": true,\n      \"expiryDate\": \"2030-05-01\",\n      \"expiringSoon\": false\n    }\n  ],\n  \"notCounted\": [\n    {\n      \"cardId\": \"card_01m4…\",\n      \"title\": \"Old passport\",\n      \"documentTypeId\": \"AU_PASSPORT\",\n      \"reason\": \"Expired. Renew it to count it again.\",\n      \"canRenew\": true\n    }\n  ],\n  \"expiringSoon\": [],\n  \"suggestions\": [\n    {\n      \"documentTypeId\": \"AU_PASSPORT\",\n      \"name\": \"Australian passport\",\n      \"points\": 70,\n      \"group\": \"main\",\n      \"showsPhoto\": true,\n      \"showsAddress\": false,\n      \"helps\": [\n        \"points\",\n        \"main\"\n      ],\n      \"finishesIt\": true\n    }\n  ],\n  \"combinations\": [],\n  \"disclaimer\": \"A guide only. The organisation you apply to makes the final identity decision.\"\n}\n```\n- `missing[]` is what is still missing, as ready-to-show sentences (`kind`: `points` · `main` · `photo` · `address`). Empty when `complete` is true.\n- `counted[]` are the documents that earn points; `group` is `main` (a main ID such as a passport or birth certificate) or `supporting` (Medicare, bank card, utility bill). `notCounted[]` explains in a sentence why a card does not count (`canRenew` = expired: link to edit that card).\n- `suggestions[]` are document types the person does not hold, best first: those with `finishesIt: true` complete the score on their own. `helps` says what each fills in. When no single document finishes it, `combinations[]` lists up to 3 pairs that do.\n- `expiringSoon[]` are counted documents that expire within 60 days: warn the person.\n- To add a suggested document, open your Add document screen with that `documentTypeId` already chosen, and return to this screen after saving so the new score is the first thing seen.\n- Expired and not-yet-received cards never count, each document type counts once. Only the general guide is used.",
        "responses": {
          "200": {
            "description": "Identity Score",
            "content": {
              "application/json": {
                "example": {
                  "schemeId": "GENERAL_100_TEMPLATE",
                  "guideName": "General 100-point guide",
                  "threshold": 100,
                  "totalPoints": 40,
                  "mainPoints": 0,
                  "supportingPoints": 40,
                  "pointsToGo": 60,
                  "complete": false,
                  "missing": [
                    {
                      "kind": "points",
                      "amount": 60,
                      "text": "60 more points"
                    },
                    {
                      "kind": "main",
                      "text": "One main ID, such as a passport or birth certificate"
                    }
                  ],
                  "counted": [
                    {
                      "cardId": "card_01m3…",
                      "title": "Driver Licence",
                      "documentTypeId": "AU_DRIVER_LICENCE",
                      "points": 40,
                      "group": "supporting",
                      "showsPhoto": true,
                      "showsAddress": true,
                      "expiryDate": "2030-05-01",
                      "expiringSoon": false
                    }
                  ],
                  "notCounted": [
                    {
                      "cardId": "card_01m4…",
                      "title": "Old passport",
                      "documentTypeId": "AU_PASSPORT",
                      "reason": "Expired. Renew it to count it again.",
                      "canRenew": true
                    }
                  ],
                  "expiringSoon": [],
                  "suggestions": [
                    {
                      "documentTypeId": "AU_PASSPORT",
                      "name": "Australian passport",
                      "points": 70,
                      "group": "main",
                      "showsPhoto": true,
                      "showsAddress": false,
                      "helps": [
                        "points",
                        "main"
                      ],
                      "finishesIt": true
                    }
                  ],
                  "combinations": [],
                  "disclaimer": "A guide only. The organisation you apply to makes the final identity decision."
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/auth/phone/send-code": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Text a 6-digit code to the account's mobile number (switched off)",
        "description": "SWITCHED OFF for now: answers 503 `sms_not_enabled` until a text-message provider is connected. Do not build this screen yet.",
        "responses": {
          "503": {
            "description": "sms_not_enabled"
          }
        }
      }
    },
    "/auth/phone/verify": {
      "post": {
        "tags": [
          "1. Auth"
        ],
        "summary": "Verify the mobile number with the texted code (switched off)",
        "description": "SWITCHED OFF for now: answers 503 `sms_not_enabled` until a text-message provider is connected. Do not build this screen yet. Body: `{ \"code\": \"123456\" }`.",
        "responses": {
          "503": {
            "description": "sms_not_enabled"
          }
        }
      }
    }
  }
}
