{
  "openapi": "3.1.0",
  "info": {
    "title": "Aiwyn API",
    "version": "1.0.0",
    "description": "The Aiwyn API gives your integration programmatic access to the clients, contacts, engagements,\nprojects, billing, payments, time, and files in your Aiwyn firm, and pushes changes to you as signed\nwebhooks.\n\n**New here?** The [Quickstart](/reference/quickstart) takes you from credentials to your first\nrequest in a few minutes.\n\n| Topic | Where |\n|-------|-------|\n| Environments, base URLs, path prefixes, and Cloudflare Access | [Base URLs & environments](/reference/base-urls) |\n| API keys and bearer tokens | [Authentication](/reference/authentication) |\n| Roles each endpoint requires | [Authorization](/reference/authorization) |\n| Paging, errors, rate limits, and versions | [Pagination](/reference/pagination), [Errors](/reference/errors), [Rate limits](/reference/rate-limits), [Versioning](/reference/versioning) |\n| Event payloads delivered to your endpoint | **Webhooks** in this reference |\n\nQuestions or credentials: [api-support@aiwyn.ai](mailto:api-support@aiwyn.ai).\n",
    "contact": {
      "name": "Aiwyn API support",
      "email": "api-support@aiwyn.ai",
      "url": "https://www.aiwyn.ai/"
    },
    "termsOfService": "https://www.aiwyn.ai/terms-of-service",
    "license": {
      "name": "Proprietary. Use is governed by your Aiwyn customer agreement.",
      "url": "https://www.aiwyn.ai/terms-of-service"
    }
  },
  "servers": [
    {
      "url": "https://api.sandbox.aiwyn.app",
      "description": "Sandbox (requires Cloudflare Access headers)"
    },
    {
      "url": "https://api.staging.aiwyn.app",
      "description": "Staging (requires Cloudflare Access headers)"
    },
    {
      "url": "https://api.aiwyn.ai",
      "description": "Production (your live firm data; no Cloudflare Access headers)"
    }
  ],
  "security": [
    {
      "BearerAuth": [],
      "CfAccessClientId": [],
      "CfAccessClientSecret": []
    },
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "Authentication endpoints for obtaining access tokens and managing API keys.\n",
      "x-displayName": "Authentication"
    },
    {
      "name": "Client",
      "description": "Manage client records, profiles, and related operations.\n",
      "x-displayName": "Client"
    },
    {
      "name": "Client Group",
      "description": "Manage client group records and associated staff assignments.\n",
      "x-displayName": "Client group"
    },
    {
      "name": "Contact",
      "description": "Manage contact information and relationships for clients.\n",
      "x-displayName": "Contact"
    },
    {
      "name": "Client Business Entity",
      "description": "Manage client business entities used for client categorization and structure.\n",
      "x-displayName": "Client business entity"
    },
    {
      "name": "Contact Client",
      "description": "Manage contact ↔ client relationship records.\n",
      "x-displayName": "Contact client"
    },
    {
      "name": "Contact Info",
      "description": "Manage contact information records (address, email, phone, etc.).\n",
      "x-displayName": "Contact info"
    },
    {
      "name": "Department",
      "description": "Manage departments and organizational units.\n",
      "x-displayName": "Department"
    },
    {
      "name": "Industry",
      "description": "Manage industry classifications.\n",
      "x-displayName": "Industry"
    },
    {
      "name": "Job",
      "description": "Manage jobs and projects.\n",
      "x-displayName": "Job"
    },
    {
      "name": "Job Template",
      "description": "Manage job templates.\n",
      "x-displayName": "Job template"
    },
    {
      "name": "Office",
      "description": "Manage office locations.\n",
      "x-displayName": "Office"
    },
    {
      "name": "Org",
      "description": "Manage organizations.\n",
      "x-displayName": "Org"
    },
    {
      "name": "Service Line",
      "description": "Manage service line classifications.\n",
      "x-displayName": "Service line"
    },
    {
      "name": "Staff",
      "description": "Manage staff accounts, roles, and permissions.\n",
      "x-displayName": "Staff"
    },
    {
      "name": "Payments",
      "description": "Handle incoming and outgoing payments.\n",
      "x-displayName": "Payments"
    },
    {
      "name": "Billing",
      "description": "Manage billing cycles, statements, and billing configurations.\n",
      "x-displayName": "Billing"
    },
    {
      "name": "Invoices",
      "description": "Create, send, and manage invoices.\n",
      "x-displayName": "Invoices"
    },
    {
      "name": "Projects",
      "description": "Handle engagements, projects, and workflow tracking.\n",
      "x-displayName": "Projects"
    },
    {
      "name": "Time Management",
      "description": "Track and manage time, expense, operational, and PTO entries, and the codes they are logged against.\n",
      "x-displayName": "Time management"
    },
    {
      "name": "Time",
      "description": "Create, update and look up time codes, the task types that time entries are logged against, and time\nentries, the hours staff work for clients.\n",
      "x-displayName": "Time"
    },
    {
      "name": "Expenses",
      "description": "Create, update and look up expense codes, which classify expense entries, and expense entries.\n",
      "x-displayName": "Expenses"
    },
    {
      "name": "Operational",
      "description": "Create, update and look up operational codes and the operational entries that log non-client time\nagainst them.\n",
      "x-displayName": "Operational"
    },
    {
      "name": "PTO",
      "description": "Create, update and look up PTO codes and the PTO entries that record paid time off against them.\n",
      "x-displayName": "PTO"
    },
    {
      "name": "Engagement",
      "description": "Create, send, and track engagements.\n",
      "x-displayName": "Engagement"
    },
    {
      "name": "Records",
      "description": "Create, update, and manage entity records across standard and custom record types.\n\nThe Records API provides:\n- **Record operations**: Create, update, and delete records for any entity type\n- **Schema discovery**: Query available entity types and their field definitions\n- **Custom record types**: Define and manage custom record type schemas\n",
      "x-displayName": "Records"
    },
    {
      "name": "Event Subscriptions",
      "description": "Create and manage webhook subscriptions for entity events.\n\nThe event subscription endpoints provide:\n- **Webhook management**: Create, update, and deactivate webhook subscriptions\n- **Event filtering**: Subscribe to specific entity types and operations (for example `CREATED`, `UPDATED`, `POSTED`)\n- **Security**: Retrieve webhook signing secrets for payload verification\n",
      "x-displayName": "Event subscriptions"
    },
    {
      "name": "File",
      "description": "Download and access files associated with records and documents.\n",
      "x-displayName": "File"
    },
    {
      "name": "Webhooks",
      "description": "The requests Aiwyn sends to your subscription's `deliveryUrl` when a subscribed event happens.\nCreate subscriptions with the event subscription endpoints.\n",
      "x-displayName": "Webhook deliveries"
    }
  ],
  "x-tagGroups": [
    {
      "name": "Getting started",
      "tags": [
        "Authentication"
      ]
    },
    {
      "name": "Clients & contacts",
      "tags": [
        "Client",
        "Client Group",
        "Client Business Entity",
        "Contact",
        "Contact Client",
        "Contact Info"
      ]
    },
    {
      "name": "Engagements & projects",
      "tags": [
        "Engagement",
        "Projects",
        "Job",
        "Job Template"
      ]
    },
    {
      "name": "Billing & payments",
      "tags": [
        "Billing",
        "Invoices",
        "Payments"
      ]
    },
    {
      "name": "Time management",
      "tags": [
        "Time Management",
        "Time",
        "Expenses",
        "Operational",
        "PTO"
      ]
    },
    {
      "name": "Firm setup",
      "tags": [
        "Staff",
        "Department",
        "Office",
        "Org",
        "Industry",
        "Service Line"
      ]
    },
    {
      "name": "Records & files",
      "tags": [
        "Records",
        "File"
      ]
    },
    {
      "name": "Webhooks",
      "tags": [
        "Event Subscriptions",
        "Webhooks"
      ]
    }
  ],
  "paths": {
    "/v1/auth/token": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Generate an API token",
        "description": "> 🔐 **Required role:** `API_ADMIN`, which every API key holds\n\nExchange a **JWT API key** for a **short-lived bearer JWT** used to access Product APIs.\n\nThis is the token-exchange endpoint itself, so no bearer token is required to call it —\nyou authenticate with your `jwtApiKey` in the request body.\n\nOn Sandbox and Staging this request must also send the `CF-Access-Client-Id` and\n`CF-Access-Client-Secret` headers, or Cloudflare rejects it before it reaches the API.\nSee [Cloudflare Access](/reference/base-urls#cloudflare-access-sandbox-and-staging).\n\nNo `Tenant` header is needed: the tenant is read from the key, and the token carries it. The token\nlasts up to an hour: the exchange can return a token issued earlier, with less time left, so request a\nnew one whenever a call answers `401`. See the [Quickstart](/reference/quickstart) for the full flow.\n",
        "operationId": "generateApiToken",
        "security": [
          {
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jwtApiKey": {
                    "type": "string",
                    "description": "JWT API key obtained from Aiwyn Support."
                  }
                },
                "required": [
                  "jwtApiKey"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "API Token generated successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "Bearer JWT for accessing Product APIs."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The request body is not valid JSON or does not match the request schema (for example `{}` without\n`jwtApiKey`). The body is the standard ART error: `message` is human-readable and\n`extensions.details.reason` is machine-readable (`INVALID_REQUEST_BODY`, `MALFORMED_JSON`,\n`JSON_MAPPING_ERROR`, `INVALID_FORMAT`).\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "message",
                    "extensions"
                  ],
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Invalid request body. Please ensure your JSON is properly formatted and contains valid values."
                    },
                    "extensions": {
                      "type": "object",
                      "required": [
                        "code"
                      ],
                      "properties": {
                        "code": {
                          "type": "integer",
                          "description": "The HTTP status code.",
                          "example": 400
                        },
                        "details": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "properties": {
                            "reason": {
                              "type": "string",
                              "example": "INVALID_REQUEST_BODY"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "The JWT API key is not valid: it is unknown, malformed, deactivated, or belongs to a\ndeactivated tenant. `error` is always `UnauthorizedException` and `code` is `UNAUTHORIZED`;\n`message` is a generic sentence that does not say which check failed.\n",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "required": [
                        "message"
                      ],
                      "properties": {
                        "message": {
                          "type": "string",
                          "description": "A generic, human-readable sentence."
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "error": "UnauthorizedException",
                  "message": "Authentication failed",
                  "code": "UNAUTHORIZED"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but no token is issued: the Product API is not enabled for the firm, or the\nprincipal the key belongs to has no active `API_ADMIN` role. The body has the same shape as the\n401 body, with `error` `ForbiddenException`, `message` \"Access denied\" and `code` `FORBIDDEN`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "required": [
                        "message"
                      ],
                      "properties": {
                        "message": {
                          "type": "string",
                          "description": "A generic, human-readable sentence."
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many new tokens were issued for the API user this key belongs to in the last 10 minutes\n(all of its keys, and `POST /v1/auth/refresh-token`, share one budget). An exchange answered with the\ntoken already cached for this key does not count. Every new token does: the first exchange with each\nkey, one each time the cached token expires, and every refresh. Requesting a token before each call\nwith one key therefore stays within the budget; issuing new tokens in a loop, or cycling through many\nkeys of one API user, does not. Wait the number of seconds in `Retry-After`, then retry, and reuse the\ntoken until a call answers `401`. The body has the same shape as the 401 body, with `error`\n`RateLimitExceeded` and `code` `TOO_MANY_REQUESTS`. A `429` without this body and without\n`Retry-After` comes from the per-address limit at the network edge: back off and retry later.\n",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before requesting a new token.",
                "schema": {
                  "type": "integer",
                  "example": 120
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "required": [
                        "message"
                      ],
                      "properties": {
                        "message": {
                          "type": "string",
                          "description": "A generic, human-readable sentence."
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "error": "RateLimitExceeded",
                  "message": "Too many tokens issued for this API user; retry after the Retry-After delay",
                  "code": "TOO_MANY_REQUESTS"
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/draft_invoice_histories": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "List draft invoice histories",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Draft invoice history](/reference/data-dictionary/draft-invoice-history)\n\n**Retrieve draft invoice histories with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nProvides paginated access to draft invoice history records.\n",
        "operationId": "getDraftInvoiceHistoriesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved draft invoice histories",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DraftInvoiceHistoryListResponse"
                },
                "examples": {
                  "successful_response": {
                    "summary": "Draft invoice histories with client and draft invoice details",
                    "value": {
                      "draftInvoices": [
                        {
                          "clientId": 7720,
                          "invoiceId": 125890,
                          "jobId": 2514,
                          "client": {
                            "active": true,
                            "clientRef": "TF-2024-789",
                            "name": "TechFlow Enterprises",
                            "pmsRef": "240815"
                          },
                          "draftInvoice": {
                            "approvedAt": "2024-03-15T14:32:18+00:00",
                            "arTranId": 125890,
                            "approverStaffId": 301,
                            "approvedByStaffId": 301,
                            "invoiceId": 125890,
                            "isActive": true,
                            "pms_invoice_number": "INV-2024-4850",
                            "status": "APPROVED",
                            "attachTimeEntries": false,
                            "automaticallyBillOn": null,
                            "billAddressContactInfoId": 4410,
                            "billerStaffId": 301,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "createdByStaffId": 301,
                            "currentAssignedStaffId": 301,
                            "deliveryMethod": "EMAIL",
                            "emailRecipients": "ap@techflow.example",
                            "expenseLineItemStrategy": "HIDE",
                            "invoiceDate": null,
                            "lineItemStrategy": "JOB",
                            "postOn": null,
                            "reversalReason": null,
                            "reversedAt": null,
                            "reversedByStaffId": null,
                            "reviewedAt": "2024-03-14T10:05:00+00:00",
                            "reviewedByStaffId": 301,
                            "reviewerStaffId": 301,
                            "scheduledByStaffId": null,
                            "senderStaffId": 301,
                            "timeEntryGrouping": null,
                            "timeEntryPageOrientation": null,
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00",
                            "wipUnbilledAsOf": null
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 94
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/draft_invoice_histories/search": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "Search draft invoice histories",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Draft invoice history](/reference/data-dictionary/draft-invoice-history)\n\n**Advanced draft invoice history filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports client, invoice, job filtering and draftInvoice approvedAt date range.\n",
        "operationId": "filterDraftInvoiceHistoriesDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "clientId": {
                            "_in": [
                              1001,
                              1002
                            ]
                          }
                        },
                        {
                          "jobId": {
                            "_in": [
                              2001,
                              2002
                            ]
                          }
                        }
                      ]
                    },
                    {
                      "client": {
                        "active": {
                          "_eq": true
                        }
                      }
                    },
                    {
                      "createdAt": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "activityType": {
                        "_in": [
                          "DRAFT_INVOICE_CREATED",
                          "DRAFT_INVOICE_RECONCILED"
                        ]
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "clientId": "asc"
                  },
                  {
                    "createdAt": "desc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "clientId": {
                                "_in": [
                                  1001,
                                  1002
                                ]
                              }
                            },
                            {
                              "jobId": {
                                "_in": [
                                  2001,
                                  2002
                                ]
                              }
                            }
                          ]
                        },
                        {
                          "client": {
                            "active": {
                              "_eq": true
                            }
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "activityType": {
                            "_in": [
                              "DRAFT_INVOICE_CREATED",
                              "DRAFT_INVOICE_RECONCILED"
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications",
                    "example": [
                      {
                        "clientId": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered draft invoice histories",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DraftInvoiceHistoryListResponse"
                },
                "examples": {
                  "successful_response": {
                    "summary": "Filtered draft invoice histories",
                    "value": {
                      "draftInvoices": [
                        {
                          "clientId": 7720,
                          "invoiceId": 125890,
                          "jobId": 2514,
                          "client": {
                            "active": true,
                            "clientRef": "TF-2024-789",
                            "name": "TechFlow Enterprises",
                            "pmsRef": "240815"
                          },
                          "draftInvoice": {
                            "approvedAt": "2024-03-15T14:32:18+00:00",
                            "arTranId": 125890,
                            "approverStaffId": 301,
                            "approvedByStaffId": 301,
                            "invoiceId": 125890,
                            "isActive": true,
                            "pms_invoice_number": "INV-2024-4850",
                            "status": "APPROVED",
                            "attachTimeEntries": false,
                            "automaticallyBillOn": null,
                            "billAddressContactInfoId": 4410,
                            "billerStaffId": 301,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "createdByStaffId": 301,
                            "currentAssignedStaffId": 301,
                            "deliveryMethod": "EMAIL",
                            "emailRecipients": "ap@techflow.example",
                            "expenseLineItemStrategy": "HIDE",
                            "invoiceDate": null,
                            "lineItemStrategy": "JOB",
                            "postOn": null,
                            "reversalReason": null,
                            "reversedAt": null,
                            "reversedByStaffId": null,
                            "reviewedAt": "2024-03-14T10:05:00+00:00",
                            "reviewedByStaffId": 301,
                            "reviewerStaffId": 301,
                            "scheduledByStaffId": null,
                            "senderStaffId": 301,
                            "timeEntryGrouping": null,
                            "timeEntryPageOrientation": null,
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00",
                            "wipUnbilledAsOf": null
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 12
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/draft_invoice_history/{id}": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "Get draft invoice history by invoice ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Draft invoice history](/reference/data-dictionary/draft-invoice-history)\n\n**Retrieve the draft invoice history record of a posted invoice**\n\nThe `id` path parameter is an **invoice id** (the `invoiceId` of a draft\ninvoice history record, equal to the invoice's AR transaction id), not a\ndraft invoice id or a history record id. The endpoint returns the first\ndraft invoice history record whose `invoiceId` equals `id`.\n\nThe body is wrapped in a `draft_invoice_history` array containing at most one\nrecord. An id that matches no record returns 200 with an empty array; the\nendpoint never returns 404 for an unknown id.\n\n**Response Example:**\n```json\n{\n  \"draft_invoice_history\": [\n    {\n      \"clientId\": 7720,\n      \"invoiceId\": 125890,\n      \"jobId\": 2514,\n      \"client\": {\n        \"active\": true,\n        \"clientRef\": \"TF-2024-789\",\n        \"name\": \"TechFlow Enterprises\",\n        \"pmsRef\": \"240815\"\n      },\n      \"draftInvoice\": {\n        \"approvedAt\": \"2024-03-15T14:32:18+00:00\",\n        \"arTranId\": 125880,\n        \"approverStaffId\": 301,\n        \"approvedByStaffId\": 301,\n        \"invoiceId\": 125890,\n        \"isActive\": true,\n        \"pms_invoice_number\": null,\n        \"status\": \"APPROVED\"\n      }\n    }\n  ]\n}\n```\n",
        "operationId": "getDraftInvoiceHistoryByInvoiceId",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Invoice id (`invoiceId`) whose draft invoice history record is returned",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 125890
          }
        ],
        "responses": {
          "200": {
            "description": "Draft invoice history lookup completed. `draft_invoice_history` holds the\nmatching record, or is empty when no record has this `invoiceId`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "draft_invoice_history"
                  ],
                  "properties": {
                    "draft_invoice_history": {
                      "type": "array",
                      "description": "At most one draft invoice history record (empty if the invoice id has none)",
                      "maxItems": 1,
                      "items": {
                        "$ref": "#/components/schemas/DraftInvoiceHistory"
                      }
                    }
                  }
                },
                "examples": {
                  "found": {
                    "summary": "Record found",
                    "value": {
                      "draft_invoice_history": [
                        {
                          "clientId": 7720,
                          "invoiceId": 125890,
                          "jobId": 2514,
                          "client": {
                            "active": true,
                            "clientRef": "TF-2024-789",
                            "name": "TechFlow Enterprises",
                            "pmsRef": "240815"
                          },
                          "draftInvoice": {
                            "approvedAt": "2024-03-15T14:32:18+00:00",
                            "arTranId": 125880,
                            "approverStaffId": 301,
                            "approvedByStaffId": 301,
                            "invoiceId": 125890,
                            "isActive": true,
                            "pms_invoice_number": null,
                            "status": "APPROVED",
                            "attachTimeEntries": false,
                            "automaticallyBillOn": null,
                            "billAddressContactInfoId": 4410,
                            "billerStaffId": 301,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "createdByStaffId": 301,
                            "currentAssignedStaffId": 301,
                            "deliveryMethod": "EMAIL",
                            "emailRecipients": "ap@techflow.example",
                            "expenseLineItemStrategy": "HIDE",
                            "invoiceDate": null,
                            "lineItemStrategy": "JOB",
                            "postOn": null,
                            "reversalReason": null,
                            "reversedAt": null,
                            "reversedByStaffId": null,
                            "reviewedAt": "2024-03-14T10:05:00+00:00",
                            "reviewedByStaffId": 301,
                            "reviewerStaffId": 301,
                            "scheduledByStaffId": null,
                            "senderStaffId": 301,
                            "timeEntryGrouping": null,
                            "timeEntryPageOrientation": null,
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00",
                            "wipUnbilledAsOf": null
                          }
                        }
                      ]
                    }
                  },
                  "not_found": {
                    "summary": "No record for this invoice id",
                    "value": {
                      "draft_invoice_history": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "example": "invalid input syntax for type bigint: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "example": "data-exception"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access draft invoice histories"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/client_groups": {
      "post": {
        "tags": [
          "Client Group"
        ],
        "summary": "List client groups",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client group](/reference/data-dictionary/client-group)\n\n**Retrieve all client groups with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis endpoint returns a paginated list of all client groups in the tenant,\nincluding assigned partner/manager staff and office information. `partnerStaff`,\n`managerStaff` and `office` are `null` when the group has no such assignment.\n\n**Key Features:**\n- Basic pagination with configurable page sizes (default: 50 records)\n- Default sorting by client group name (ascending) then creation date (descending)\n- Total count aggregation for pagination metadata\n",
        "operationId": "getClientGroups",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count).",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved client group list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "clientGroups",
                    "total"
                  ],
                  "properties": {
                    "clientGroups": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ClientGroup"
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of client groups in the tenant",
                              "example": 142
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Typical response with client group data",
                    "value": {
                      "clientGroups": [
                        {
                          "id": 10,
                          "name": "Acme Corp Group",
                          "pmsRef": "GRP-001",
                          "active": true,
                          "isManagedByAiwyn": false,
                          "parentClientId": null,
                          "primaryContactId": 201,
                          "billingContactId": 202,
                          "partnerStaffId": 101,
                          "managerStaffId": 102,
                          "officeId": 5,
                          "createdAt": "2024-01-15T10:00:00.000000+00:00",
                          "updatedAt": "2024-06-20T14:30:00.000000+00:00",
                          "version": 3,
                          "customFieldValues": {
                            "region": "West"
                          },
                          "partnerStaff": {
                            "id": 101,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "m.chen@company.com"
                          },
                          "managerStaff": {
                            "id": 102,
                            "firstName": "Lisa",
                            "lastName": "Rodriguez",
                            "email": "l.rodriguez@company.com"
                          },
                          "office": {
                            "id": 5,
                            "pmsRef": "OFF-5",
                            "name": "San Francisco"
                          }
                        },
                        {
                          "id": 11,
                          "name": "Beta Industries Group",
                          "pmsRef": "GRP-002",
                          "active": true,
                          "isManagedByAiwyn": true,
                          "parentClientId": null,
                          "primaryContactId": null,
                          "billingContactId": null,
                          "partnerStaffId": 103,
                          "managerStaffId": null,
                          "officeId": null,
                          "createdAt": "2024-02-10T08:00:00.000000+00:00",
                          "updatedAt": "2024-02-10T08:00:00.000000+00:00",
                          "version": 1,
                          "customFieldValues": null,
                          "partnerStaff": {
                            "id": 103,
                            "firstName": "Jennifer",
                            "lastName": "Park",
                            "email": "j.park@company.com"
                          },
                          "managerStaff": null,
                          "office": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 142
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "Empty result set",
                    "value": {
                      "clientGroups": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/clients": {
      "post": {
        "tags": [
          "Client"
        ],
        "summary": "List clients",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client](/reference/data-dictionary/client)\n\n**Retrieve all clients with limit/offset pagination**\n\nThis endpoint lists all clients. It does not apply filters. Use\n`POST /gql/v1/clients/search` when you need a where clause.\n\nUses standard limit/offset pagination via `pageSize` and `page` — see\n[Pagination](/reference/pagination). Use `total.aggregate.count`\nfrom the response to know when you have reached the end.\n\n**Other behavior:**\n- Default sort is client name ascending, then `createdAt` descending\n- Each client carries its department, office, industry, client type, business entity and\n  staff assignments; relationships and optional foreign keys are `null` when unset\n- The response includes the total count\n- Default `pageSize` is 50; maximum is 1000\n",
        "operationId": "getClients",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count).",
                    "example": 1000
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next 1,000 rows after the first 1,000, send\n`pageSize: 1000` and `page: 1000`. An offset at or beyond\n`total.aggregate.count` returns an empty `clients` array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "first_page": {
                  "summary": "First 1,000 clients (skip 0)",
                  "value": {
                    "pageSize": 1000,
                    "page": 0
                  }
                },
                "next_chunk": {
                  "summary": "Next 1,000 clients after the first 1,000",
                  "value": {
                    "pageSize": 1000,
                    "page": 1000
                  }
                },
                "last_partial_chunk": {
                  "summary": "Remaining clients after skipping 25,000",
                  "value": {
                    "pageSize": 1000,
                    "page": 25000
                  }
                },
                "beyond_last_record": {
                  "summary": "Offset at or beyond the total count (empty result)",
                  "value": {
                    "pageSize": 1000,
                    "page": 25156
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved client list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "clients",
                    "total"
                  ],
                  "properties": {
                    "clients": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Client"
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of clients in the system",
                              "example": 13697
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Typical response with client data",
                    "value": {
                      "clients": [
                        {
                          "id": 122,
                          "pmsRef": "1155",
                          "clientRef": "41664",
                          "name": "Acme Bread Co.",
                          "active": true,
                          "ebilling": true,
                          "emailStatement": true,
                          "chargeAdminFee": false,
                          "clientContactInfoId": 9957,
                          "excludeFromCollections": false,
                          "default_billing_day": null,
                          "prefContactId": 601,
                          "billingContactId": null,
                          "billingClientId": null,
                          "departmentId": 3,
                          "officeId": 1,
                          "industryId": null,
                          "clientGroupId": null,
                          "partnerStaffId": 53,
                          "managerStaffId": null,
                          "staffBillingManagerId": null,
                          "clientTypeId": 7,
                          "clientBusinessEntityId": null,
                          "fiscalYearEndMonth": 12,
                          "fiscalYearEndDay": 31,
                          "createdAt": "2023-05-12T22:43:55.488054+00:00",
                          "updatedAt": "2023-06-09T21:34:28.817274+00:00",
                          "customFieldValues": {
                            "industry_niche": "Manufacturing",
                            "naics_code": "333120"
                          },
                          "orgId": null,
                          "clientKey": null,
                          "updateByStaffId": 53,
                          "exclusionStatusUpdatedAt": "2023-05-12T22:43:55.488054+00:00",
                          "isManagedByAiwyn": false,
                          "isCreatedByAiwyn": false,
                          "originatingPartnerStaffId": null,
                          "billingNotes": null,
                          "description": null,
                          "notes": null,
                          "noticePeriod": null,
                          "secondaryContactId": null,
                          "fein": null,
                          "status": "ACTIVE",
                          "invoiceDeliveryMethod": "EMAIL",
                          "mergedInto": null,
                          "inactivateMergedRecord": false,
                          "department": {
                            "id": 3,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "office": {
                            "id": 1,
                            "pmsRef": "OFF-1",
                            "name": "Charlotte",
                            "city": "Charlotte",
                            "stateProvince": "NC",
                            "country": "US"
                          },
                          "industry": null,
                          "clientType": {
                            "id": 7,
                            "name": "Business",
                            "pmsRef": "BUS"
                          },
                          "clientBusinessEntity": null,
                          "entityType": null,
                          "partnerStaff": {
                            "id": 53,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "m.chen@company.com"
                          },
                          "managerStaff": null,
                          "billManager": null,
                          "relationshipOwner": {
                            "id": 53,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "m.chen@company.com"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 13697
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "Empty result set (no clients, or offset at/beyond total)",
                    "value": {
                      "clients": [],
                      "total": {
                        "aggregate": {
                          "count": 25156
                        }
                      }
                    }
                  },
                  "no_clients": {
                    "summary": "Empty tenant (zero clients)",
                    "value": {
                      "clients": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_page_size": {
                    "summary": "Invalid pageSize parameter",
                    "value": {
                      "error": "pageSize must be an integer from 1 to 1000"
                    }
                  },
                  "negative_page": {
                    "summary": "Negative page",
                    "value": {
                      "error": "page must be an integer of 0 or more"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_token": {
                    "summary": "No Authorization header",
                    "value": {
                      "error": "missing Authorization header"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/clients/search": {
      "post": {
        "tags": [
          "Client"
        ],
        "summary": "Search clients",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client](/reference/data-dictionary/client)\n\n**Advanced client filtering with flexible `where` clauses and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see\n[Pagination](/reference/pagination).\n\nThis query provides maximum flexibility for client data retrieval through\ncustom `where` clause construction and dynamic ordering specifications.\nIt's designed for complex business requirements that need sophisticated filtering logic.\n\n**Key Features:**\n- Custom `where` clause construction for unlimited filtering combinations\n- Dynamic `order_by` specifications supporting multi-field sorting with custom directions\n- Advanced boolean logic combining multiple filter conditions with `_and`, `_or`, `_not`\n- Relationship-based filtering across connected entities (contacts, staff assignments)\n- Enterprise-grade filtering supporting complex business logic requirements\n- Support for nested queries and conditional logic patterns\n\n**Advanced Filtering Capabilities:**\n- **Boolean Logic**: _and, _or, _not operators for complex condition combinations\n- **Text Operations**: _like, _ilike, _regex for pattern matching and search\n- **Comparison Operators**: _gt, _gte, _lt, _lte, _eq, _neq for numerical/date comparisons  \n- **Array Operations**: _in, _nin for multi-value filtering and inclusion/exclusion\n- **Null Handling**: _is_null for empty value detection and filtering\n- **Relationship Traversal**: Filter on connected entities like contacts and staff\n- **Date Ranges**: Precision timestamp filtering for time-based analysis\n- **Case Sensitivity**: Both case-sensitive and case-insensitive text matching\n\n**Dynamic Ordering Options:**\n- **Multi-field Sorting**: Order by multiple columns with individual sort directions\n- **Relationship Sorting**: Sort by connected entity fields (staff names, contact info)\n- **Custom Directions**: Mix ascending and descending order across different fields\n- **Priority Ordering**: Define primary, secondary, tertiary sort criteria\n- **Date-based Sorting**: createdAt, updatedAt for chronological ordering\n- **Text Sorting**: Alphabetical ordering with locale-aware collation\n",
        "operationId": "filterClientsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`. Defaults to 50 when omitted.",
                    "example": 1
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nSame contract as `POST /gql/v1/clients`. When `page` is at or\nbeyond `total.aggregate.count`, `clients` is an empty array.\n",
                    "example": 0
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible where clause for complex filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "name": {
                                "_ilike": "%tech%"
                              }
                            },
                            {
                              "clientRef": {
                                "_ilike": "%45%"
                              }
                            }
                          ]
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "partnerStaffId": {
                            "_in": [
                              5,
                              6,
                              7,
                              8
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "description": "Dynamic ordering specifications with multiple fields",
                    "items": {
                      "type": "object"
                    },
                    "example": [
                      {
                        "name": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              },
              "examples": {
                "default_search": {
                  "summary": "Default search with filtering",
                  "value": {
                    "pageSize": 1,
                    "page": 0,
                    "where": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "name": {
                                "_ilike": "%tech%"
                              }
                            },
                            {
                              "clientRef": {
                                "_ilike": "%45%"
                              }
                            }
                          ]
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "partnerStaffId": {
                            "_in": [
                              5,
                              6,
                              7,
                              8
                            ]
                          }
                        }
                      ]
                    },
                    "orderBy": [
                      {
                        "name": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered clients with dynamic ordering",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "clients",
                    "total"
                  ],
                  "properties": {
                    "clients": {
                      "type": "array",
                      "description": "Same client shape as `POST /gql/v1/clients`",
                      "items": {
                        "$ref": "#/components/schemas/Client"
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of clients matching filter criteria",
                              "example": 59
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Filtered clients with dynamic ordering and relationships",
                    "value": {
                      "clients": [
                        {
                          "id": 122,
                          "pmsRef": "1155",
                          "clientRef": "41664",
                          "name": "Acme Bread Co.",
                          "active": true,
                          "ebilling": true,
                          "emailStatement": true,
                          "chargeAdminFee": false,
                          "clientContactInfoId": 9957,
                          "excludeFromCollections": false,
                          "default_billing_day": null,
                          "prefContactId": 601,
                          "billingContactId": null,
                          "billingClientId": null,
                          "departmentId": 3,
                          "officeId": 1,
                          "industryId": null,
                          "clientGroupId": null,
                          "partnerStaffId": 53,
                          "managerStaffId": null,
                          "staffBillingManagerId": null,
                          "clientTypeId": 7,
                          "clientBusinessEntityId": null,
                          "fiscalYearEndMonth": 12,
                          "fiscalYearEndDay": 31,
                          "createdAt": "2023-05-12T22:43:55.488054+00:00",
                          "updatedAt": "2023-06-09T21:34:28.817274+00:00",
                          "customFieldValues": {
                            "industry_niche": "Manufacturing",
                            "naics_code": "333120"
                          },
                          "orgId": null,
                          "clientKey": null,
                          "updateByStaffId": 53,
                          "exclusionStatusUpdatedAt": "2023-05-12T22:43:55.488054+00:00",
                          "isManagedByAiwyn": false,
                          "isCreatedByAiwyn": false,
                          "originatingPartnerStaffId": null,
                          "billingNotes": null,
                          "description": null,
                          "notes": null,
                          "noticePeriod": null,
                          "secondaryContactId": null,
                          "fein": null,
                          "status": "ACTIVE",
                          "invoiceDeliveryMethod": "EMAIL",
                          "mergedInto": null,
                          "inactivateMergedRecord": false,
                          "department": {
                            "id": 3,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "office": {
                            "id": 1,
                            "pmsRef": "OFF-1",
                            "name": "Charlotte",
                            "city": "Charlotte",
                            "stateProvince": "NC",
                            "country": "US"
                          },
                          "industry": null,
                          "clientType": {
                            "id": 7,
                            "name": "Business",
                            "pmsRef": "BUS"
                          },
                          "clientBusinessEntity": null,
                          "entityType": null,
                          "partnerStaff": {
                            "id": 53,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "m.chen@company.com"
                          },
                          "managerStaff": null,
                          "billManager": null,
                          "relationshipOwner": {
                            "id": 53,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "m.chen@company.com"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 59
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No clients match filter criteria",
                    "value": {
                      "clients": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid filter parameters or malformed where clause",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "invalid_where_clause": {
                    "summary": "Malformed where clause",
                    "value": {
                      "error": "Invalid where clause structure: missing operator in condition",
                      "code": "INVALID_WHERE_CLAUSE"
                    }
                  },
                  "invalid_order_by": {
                    "summary": "Invalid ordering specification",
                    "value": {
                      "error": "Invalid orderBy field or direction specified",
                      "code": "INVALID_ORDER_BY"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid admin secret",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_auth": {
                    "summary": "Missing authentication token",
                    "value": {
                      "error": "Missing or invalid authentication token",
                      "code": "UNAUTHORIZED"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/client/{id}": {
      "get": {
        "tags": [
          "Client"
        ],
        "summary": "Get client by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client](/reference/data-dictionary/client)\n\n**Retrieve a specific client by its unique identifier**\n\nReturns the client wrapped in a `client` key, with its department, office, industry,\nclient type, business entity, contact info and staff assignments. Relationships and\noptional foreign keys are `null` when unset.\n\n**Not found:** an `id` that matches no client returns **200** with `{\"client\": null}`\n(not 404). A non-numeric `id` returns **400**.\n",
        "operationId": "getClientById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the client",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 122
          }
        ],
        "responses": {
          "200": {
            "description": "Client found (`client` is the record) or not found (`client` is `null`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "client"
                  ],
                  "properties": {
                    "client": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/ClientDetail"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "examples": {
                  "found": {
                    "summary": "Client found",
                    "value": {
                      "client": {
                        "id": 122,
                        "pmsRef": "1155",
                        "clientRef": "41664",
                        "name": "Acme Bread Co.",
                        "active": true,
                        "ebilling": true,
                        "emailStatement": true,
                        "chargeAdminFee": false,
                        "clientContactInfoId": 9957,
                        "excludeFromCollections": false,
                        "default_billing_day": null,
                        "prefContactId": 601,
                        "billingContactId": null,
                        "billingClientId": null,
                        "departmentId": 3,
                        "officeId": 1,
                        "industryId": null,
                        "clientGroupId": null,
                        "partnerStaffId": 53,
                        "managerStaffId": null,
                        "staffBillingManagerId": null,
                        "clientTypeId": 7,
                        "clientBusinessEntityId": null,
                        "fiscalYearEndMonth": 12,
                        "fiscalYearEndDay": 31,
                        "createdAt": "2023-05-12T22:43:55.488054+00:00",
                        "updatedAt": "2023-06-09T21:34:28.817274+00:00",
                        "customFieldValues": {
                          "industry_niche": "Manufacturing",
                          "naics_code": "333120"
                        },
                        "orgId": null,
                        "clientKey": null,
                        "updateByStaffId": 53,
                        "exclusionStatusUpdatedAt": "2023-05-12T22:43:55.488054+00:00",
                        "isManagedByAiwyn": false,
                        "isCreatedByAiwyn": false,
                        "originatingPartnerStaffId": null,
                        "billingNotes": null,
                        "description": null,
                        "notes": null,
                        "noticePeriod": null,
                        "secondaryContactId": null,
                        "fein": null,
                        "status": "ACTIVE",
                        "invoiceDeliveryMethod": "EMAIL",
                        "mergedInto": null,
                        "inactivateMergedRecord": false,
                        "department": {
                          "id": 3,
                          "pmsRef": "TAX",
                          "name": "Tax"
                        },
                        "office": {
                          "id": 1,
                          "pmsRef": "OFF-1",
                          "name": "Charlotte",
                          "city": "Charlotte",
                          "stateProvince": "NC",
                          "country": "US"
                        },
                        "industry": null,
                        "clientType": {
                          "id": 7,
                          "name": "Business",
                          "pmsRef": "BUS"
                        },
                        "clientBusinessEntity": null,
                        "entityType": null,
                        "partnerStaff": {
                          "id": 53,
                          "firstName": "Michael",
                          "lastName": "Chen",
                          "email": "m.chen@company.com"
                        },
                        "managerStaff": null,
                        "billManager": null,
                        "relationshipOwner": {
                          "id": 53,
                          "firstName": "Michael",
                          "lastName": "Chen",
                          "email": "m.chen@company.com"
                        },
                        "clientContactInfo": {
                          "id": 9957,
                          "firstName": "Sarah",
                          "lastName": "Johnson",
                          "email": "sarah.johnson@acme.com",
                          "phone": "555-0123"
                        }
                      }
                    }
                  },
                  "not_found": {
                    "summary": "No client with this id",
                    "value": {
                      "client": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this client"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/clients/v1/onboard": {
      "post": {
        "tags": [
          "Client"
        ],
        "summary": "Onboard a client",
        "description": "> 🔐 **Required role:** `CLIENT_C`\n>\n> 📖 **Data dictionary:** [Client](/reference/data-dictionary/client)\n\n**Onboard a new client with inline contact creation**\n\nCreates a new client record and simultaneously resolves or creates up to three\nassociated contacts (preferred, billing, and secondary). Each contact field accepts\neither an existing contact ID or a full inline payload to create a brand-new contact.\n\n**Required fields:**\n- `name` — client display name\n- `pmsRef` — practice management system reference\n- `clientRef` — unique client reference identifier\n- `officeId` — ID of the office this client belongs to\n\nA client `pmsRef` that already exists is rejected with **400** and nothing is created;\nonboarding never updates an existing client.\n\n**Contact fields** (`prefContact`, `billingContact`, `secondaryContact`):\nEach contact field is optional but, when provided, must include **either** an existing\n`id` **or** a `contactInfo` object — not both.\n- When supplying `contactInfo`, `pmsRef` on the contact payload is required.\n- At least one of `prefix`, `firstName`, or `lastName` must be provided inside\n  `contactInfo` to form a valid full name.\n\n**Classification & billing fields** (all optional):\n- `clientTypeId`, `clientBusinessEntityId` (entity type), and `staffBillingManagerId`\n  each reference an existing record; an unknown ID is rejected with **400**.\n- `fiscalYearEndMonth` (1–12) and `fiscalYearEndDay` (1–31) capture the client's fiscal\n  year end.\n\n**Custom fields** (`customFieldValuesJson`): a JSON object, encoded as a string, mapping\ncustom field keys to values. Keys not defined in the tenant's `CLIENT` custom-field schema,\nand keys of read-only or hidden fields, are dropped rather than failing the request, and are\nechoed back in `data.ignoredCustomFields` (and appended to `meta.message`). The onboard\nstill returns **201**.\n\n**Tax regions** (`taxRegionIds`): a list of existing tax region IDs to link to the new\nclient. Duplicate IDs are de-duplicated; an unknown ID is rejected with **400**. The\nassigned IDs are returned in `data.taxRegionIds`.\n\n**Addresses** (`address`, `billingAddress`), both optional and stored the same way the\nFirm Portal \"Create New Client\" dialog stores them:\n- `address` is the client's own address. It is saved as the client's contact info record\n  and shows in the portal's *Address* section; its ID is returned in\n  `data.clientContactInfoId`.\n- `billingAddress` is saved as a client address of type *Billing* and shows in the\n  portal's *Billing Address* section; its ID is returned in `data.billingAddressId`.\n- `country` must be an ISO 3166-1 alpha-2 code (e.g. `US`, `CA`, `GB`); it is accepted\n  case-insensitively and stored upper-case.\n- When `country` is `US`, `state` must be a US state name or abbreviation and is stored\n  as the abbreviation (e.g. `North Carolina` → `NC`). For other countries `state` is\n  stored as given.\n- `pmsRef` is optional on both; when omitted an Aiwyn reference (`AIWYN_<uuid>`) is\n  generated. A `pmsRef` that already exists is rejected with **400**.\n- An address object must carry at least one address field; an invalid country, state or\n  duplicate `pmsRef` rejects the whole request with **400** and no client is created.\n",
        "operationId": "onboardNewClient",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "pmsRef",
                  "clientRef",
                  "officeId"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Client display name",
                    "example": "Acme Corporation"
                  },
                  "pmsRef": {
                    "type": "string",
                    "description": "Practice management system reference identifier",
                    "example": "ACME-001"
                  },
                  "clientRef": {
                    "type": "string",
                    "description": "Unique client reference identifier",
                    "example": "ACME-001"
                  },
                  "officeId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "ID of the office this client belongs to",
                    "example": 1
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Optional client description",
                    "example": "A multinational technology company"
                  },
                  "sortName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Alternate name used for alphabetical sorting",
                    "example": "Acme"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Internal notes about the client",
                    "example": "Preferred billing on the 1st of the month"
                  },
                  "departmentId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the department associated with this client",
                    "example": 10
                  },
                  "orgId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the organization associated with this client",
                    "example": 5
                  },
                  "industryId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the industry classification for this client",
                    "example": 3
                  },
                  "partnerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the partner staff member assigned to this client",
                    "example": 53
                  },
                  "managerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the manager staff member assigned to this client",
                    "example": 15
                  },
                  "clientTypeId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the client type classification",
                    "example": 7
                  },
                  "clientBusinessEntityId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the client business entity (entity type)",
                    "example": 4
                  },
                  "staffBillingManagerId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the staff member acting as billing manager for this client",
                    "example": 22
                  },
                  "fiscalYearEndMonth": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int32",
                    "minimum": 1,
                    "maximum": 12,
                    "description": "Month (1-12) the client's fiscal year ends",
                    "example": 12
                  },
                  "fiscalYearEndDay": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int32",
                    "minimum": 1,
                    "maximum": 31,
                    "description": "Day of month (1-31) the client's fiscal year ends",
                    "example": 31
                  },
                  "customFieldValuesJson": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "JSON object, encoded as a string, mapping custom field keys to values. Keys not defined in the tenant's CLIENT custom-field schema, and keys of read-only or hidden fields, are ignored and reported back in `data.ignoredCustomFields`.\n",
                    "example": "{\"industry_niche\":\"Manufacturing\",\"naics_code\":\"333120\"}"
                  },
                  "taxRegionIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "IDs of existing tax regions to assign to the new client. Duplicates are de-duplicated; an unknown ID returns 400.\n",
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "example": [
                      3,
                      7
                    ]
                  },
                  "ebilling": {
                    "type": "boolean",
                    "default": false,
                    "description": "Whether this client is enrolled in electronic billing",
                    "example": true
                  },
                  "invoiceDeliveryMethod": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "How invoices are delivered to the client. Defaults to EMAIL when `ebilling` is true, otherwise DOWNLOAD.\n",
                    "enum": [
                      "EMAIL",
                      "DOWNLOAD",
                      "EMAIL_AND_DOWNLOAD",
                      "POST_ONLY",
                      null
                    ],
                    "example": "EMAIL"
                  },
                  "emailStatement": {
                    "type": "boolean",
                    "default": false,
                    "description": "Whether statements are emailed to the client",
                    "example": false
                  },
                  "chargeAdminFee": {
                    "type": "boolean",
                    "default": false,
                    "description": "Whether an administrative fee is charged to this client",
                    "example": false
                  },
                  "active": {
                    "type": "boolean",
                    "default": true,
                    "description": "Whether the client is active",
                    "example": true
                  },
                  "address": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "The client's own address, stored as the client's contact info record (the portal's \"Address\" section). At least one address field is required; `pmsRef` is optional and generated as `AIWYN_<uuid>` when omitted.\n",
                    "properties": {
                      "pmsRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "PMS reference for the address record. Must not already exist.",
                        "example": "ACME-001-ADDRESS"
                      },
                      "address": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "123 Main St"
                      },
                      "address2": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "Suite 400"
                      },
                      "city": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "Charlotte"
                      },
                      "state": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "For `country: US` a US state name or abbreviation, stored as the abbreviation. Free text for other countries.\n",
                        "example": "NC"
                      },
                      "country": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "ISO 3166-1 alpha-2 country code; stored upper-case.",
                        "example": "US"
                      },
                      "zipCode": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "28202"
                      }
                    }
                  },
                  "billingAddress": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Billing address, stored as a client address of type Billing (the portal's \"Billing Address\" section). Same shape and rules as `address`.\n",
                    "properties": {
                      "pmsRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "PMS reference for the billing address record. Must not already exist.",
                        "example": "ACME-001-BILLING"
                      },
                      "address": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "PO Box 999"
                      },
                      "address2": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": null
                      },
                      "city": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "Raleigh"
                      },
                      "state": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "NC"
                      },
                      "country": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "US"
                      },
                      "zipCode": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "27601"
                      }
                    }
                  },
                  "prefContact": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Preferred contact. Provide either `id` (existing contact) or `contactInfo` (create new) — not both. `pmsRef` is required when creating a new contact.\n",
                    "properties": {
                      "id": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "description": "ID of an existing contact to link",
                        "example": 501
                      },
                      "username": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "email",
                        "description": "Email address used as the contact's login username",
                        "example": "jane.smith@acme.com"
                      },
                      "pmsRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "PMS reference for the contact. Required when creating a new contact.",
                        "example": "CONT-001"
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "Contact type classification",
                        "example": "PRIMARY"
                      },
                      "staffId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "description": "ID of the staff member associated with this contact",
                        "example": 53
                      },
                      "officeId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "description": "ID of the office associated with this contact",
                        "example": 1
                      },
                      "contactInfo": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "description": "Full contact details for creating a new contact record",
                        "required": [
                          "pmsRef"
                        ],
                        "properties": {
                          "pmsRef": {
                            "type": "string",
                            "description": "PMS reference for the contact info record",
                            "example": "CONT-001"
                          },
                          "shortName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Jane S."
                          },
                          "firstName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Jane"
                          },
                          "lastName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Smith"
                          },
                          "jobTitle": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "CFO"
                          },
                          "prefix": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Ms."
                          },
                          "salutation": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Dear Jane"
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "+1-555-0123"
                          },
                          "email": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "email",
                            "example": "jane.smith@acme.com"
                          },
                          "address": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "123 Main St"
                          },
                          "address2": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Suite 400"
                          },
                          "city": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "New York"
                          },
                          "state": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "NY"
                          },
                          "country": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "US"
                          },
                          "zipCode": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "10001"
                          }
                        }
                      }
                    }
                  },
                  "billingContact": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Billing contact. Same shape as `prefContact` — provide either `id` or `contactInfo`.\n",
                    "properties": {
                      "id": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": 502
                      },
                      "username": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "email",
                        "example": "billing@acme.com"
                      },
                      "pmsRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "CONT-002"
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": "BILLING"
                      },
                      "staffId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": null
                      },
                      "officeId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": 1
                      },
                      "contactInfo": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "required": [
                          "pmsRef"
                        ],
                        "properties": {
                          "pmsRef": {
                            "type": "string",
                            "example": "CONT-002"
                          },
                          "shortName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "firstName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Bob"
                          },
                          "lastName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Finance"
                          },
                          "jobTitle": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Accounts Payable"
                          },
                          "prefix": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "salutation": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "+1-555-0124"
                          },
                          "email": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "email",
                            "example": "billing@acme.com"
                          },
                          "address": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "address2": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "city": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "state": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "country": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "zipCode": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          }
                        }
                      }
                    }
                  },
                  "secondaryContact": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Secondary contact. Same shape as `prefContact` — provide either `id` or `contactInfo`.\n",
                    "properties": {
                      "id": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": 503
                      },
                      "username": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "email",
                        "example": null
                      },
                      "pmsRef": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": null
                      },
                      "type": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "example": null
                      },
                      "staffId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": null
                      },
                      "officeId": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "format": "int64",
                        "example": null
                      },
                      "contactInfo": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "required": [
                          "pmsRef"
                        ],
                        "properties": {
                          "pmsRef": {
                            "type": "string",
                            "example": "CONT-003"
                          },
                          "firstName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Carol"
                          },
                          "lastName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": "Secondary"
                          },
                          "email": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "email",
                            "example": "carol@acme.com"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "new_contact_inline": {
                  "summary": "New client with inline preferred contact and client address",
                  "value": {
                    "name": "Acme Corporation",
                    "pmsRef": "ACME-001",
                    "clientRef": "ACME-001",
                    "officeId": 1,
                    "prefContact": {
                      "pmsRef": "CONT-001",
                      "contactInfo": {
                        "pmsRef": "CONT-001",
                        "firstName": "Jane",
                        "lastName": "Smith",
                        "email": "jane.smith@acme.com"
                      }
                    },
                    "address": {
                      "address": "123 Main St",
                      "address2": "Suite 400",
                      "city": "Charlotte",
                      "state": "NC",
                      "country": "US",
                      "zipCode": "28202"
                    }
                  }
                },
                "existing_contact": {
                  "summary": "New client linking to existing contacts",
                  "value": {
                    "name": "Beta Industries",
                    "pmsRef": "BETA-002",
                    "clientRef": "BETA-002",
                    "officeId": 1,
                    "prefContact": {
                      "id": 501
                    },
                    "billingContact": {
                      "id": 502
                    }
                  }
                },
                "minimal": {
                  "summary": "Minimal required fields only",
                  "value": {
                    "name": "Gamma LLC",
                    "pmsRef": "GAMMA-003",
                    "clientRef": "GAMMA-003",
                    "officeId": 1
                  }
                },
                "crm_integration_fields": {
                  "summary": "Client with classification, fiscal year end, custom fields, and tax regions",
                  "value": {
                    "name": "Redw Client",
                    "pmsRef": "REDW-100",
                    "clientRef": "REDW-100",
                    "officeId": 1,
                    "clientTypeId": 7,
                    "clientBusinessEntityId": 4,
                    "staffBillingManagerId": 22,
                    "fiscalYearEndMonth": 12,
                    "fiscalYearEndDay": 31,
                    "customFieldValuesJson": "{\"industry_niche\":\"Manufacturing\",\"naics_code\":\"333120\"}",
                    "taxRegionIds": [
                      3,
                      7
                    ]
                  }
                },
                "with_addresses": {
                  "summary": "Client with its own address and a separate billing address",
                  "value": {
                    "name": "Delta Partners",
                    "pmsRef": "DELTA-004",
                    "clientRef": "DELTA-004",
                    "officeId": 1,
                    "address": {
                      "address": "123 Main St",
                      "address2": "Suite 400",
                      "city": "Charlotte",
                      "state": "North Carolina",
                      "country": "us",
                      "zipCode": "28202"
                    },
                    "billingAddress": {
                      "pmsRef": "DELTA-004-BILLING",
                      "address": "PO Box 999",
                      "city": "Raleigh",
                      "state": "NC",
                      "country": "US",
                      "zipCode": "27601"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Client onboarded successfully. The body is the standard ART envelope: the result is in `data` and the success flag and message are in `meta` (there is no top-level `success` or `message`). Unknown custom field keys are dropped and reported in `data.ignoredCustomFields` — the write still succeeds.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "client"
                      ],
                      "properties": {
                        "client": {
                          "type": "object",
                          "description": "The newly created client record",
                          "properties": {
                            "id": {
                              "type": "integer",
                              "format": "int64",
                              "description": "Unique identifier of the created client",
                              "example": 1001
                            },
                            "pmsRef": {
                              "type": "string",
                              "example": "ACME-001"
                            },
                            "clientRef": {
                              "type": "string",
                              "example": "ACME-001"
                            },
                            "name": {
                              "type": "string",
                              "example": "Acme Corporation"
                            },
                            "description": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "example": null
                            },
                            "sortName": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "example": null
                            },
                            "officeId": {
                              "type": "integer",
                              "format": "int64",
                              "example": 1
                            },
                            "departmentId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": null
                            },
                            "orgId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": null
                            },
                            "industryId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": null
                            },
                            "partnerStaffId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": 53
                            },
                            "managerStaffId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": 15
                            },
                            "clientTypeId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": 7
                            },
                            "clientBusinessEntityId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": 4
                            },
                            "staffBillingManagerId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "example": 22
                            },
                            "fiscalYearEndMonth": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int32",
                              "example": 12
                            },
                            "fiscalYearEndDay": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int32",
                              "example": 31
                            },
                            "customFieldValuesJson": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "JSON object, encoded as a string, of persisted custom field values",
                              "example": "{\"industry_niche\":\"Manufacturing\"}"
                            },
                            "active": {
                              "type": "boolean",
                              "example": true
                            },
                            "status": {
                              "type": "string",
                              "example": "ACTIVE"
                            },
                            "version": {
                              "type": "integer",
                              "format": "int64",
                              "example": 1
                            },
                            "createdAt": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "format": "date-time",
                              "example": "2024-03-15T10:00:00Z"
                            },
                            "updatedAt": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "format": "date-time",
                              "example": "2024-03-15T10:00:00Z"
                            }
                          }
                        },
                        "prefContactId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "ID of the resolved preferred contact",
                          "example": 601
                        },
                        "billingContactId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "ID of the resolved billing contact",
                          "example": null
                        },
                        "secondaryContactId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "ID of the resolved secondary contact",
                          "example": null
                        },
                        "clientContactInfoId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "ID of the contact info record created from `address`; null when no `address` was supplied\n",
                          "example": 44489
                        },
                        "billingAddressId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "ID of the Billing client address created from `billingAddress`; null when no `billingAddress` was supplied\n",
                          "example": 211
                        },
                        "taxRegionIds": {
                          "type": "array",
                          "description": "IDs of the tax regions assigned to the client during onboarding",
                          "items": {
                            "type": "integer",
                            "format": "int64"
                          },
                          "example": [
                            3,
                            7
                          ]
                        },
                        "ignoredCustomFields": {
                          "type": "array",
                          "description": "Custom field keys that were provided but ignored because they are not defined in the tenant's CLIENT custom-field schema\n",
                          "items": {
                            "type": "string"
                          },
                          "example": []
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "required": [
                        "success",
                        "message",
                        "timestamp"
                      ],
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "description": "Success message. When custom field keys are dropped, this is suffixed with \"; ignored unknown or protected custom fields: `{keys}`\".\n",
                          "example": "Client onboarded successfully"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time",
                          "example": "2024-03-15T10:00:00.123Z"
                        },
                        "version": {
                          "type": "string",
                          "example": "v1"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Client onboarded with a new preferred contact and client address",
                    "value": {
                      "data": {
                        "client": {
                          "id": 1001,
                          "pmsRef": "ACME-001",
                          "clientRef": "ACME-001",
                          "name": "Acme Corporation",
                          "officeId": 1,
                          "active": true,
                          "status": "ACTIVE",
                          "version": 1,
                          "createdAt": "2024-03-15T10:00:00Z",
                          "updatedAt": "2024-03-15T10:00:00Z"
                        },
                        "prefContactId": 601,
                        "billingContactId": null,
                        "secondaryContactId": null,
                        "clientContactInfoId": 44489,
                        "billingAddressId": null,
                        "taxRegionIds": [],
                        "ignoredCustomFields": []
                      },
                      "meta": {
                        "success": true,
                        "message": "Client onboarded successfully",
                        "timestamp": "2024-03-15T10:00:00.123Z",
                        "version": "v1"
                      }
                    }
                  },
                  "success_with_addresses": {
                    "summary": "Onboarded with a client address and a billing address",
                    "value": {
                      "data": {
                        "client": {
                          "id": 1003,
                          "pmsRef": "DELTA-004",
                          "clientRef": "DELTA-004",
                          "name": "Delta Partners",
                          "officeId": 1,
                          "active": true,
                          "status": "ACTIVE",
                          "version": 1,
                          "createdAt": "2024-03-15T10:00:00Z",
                          "updatedAt": "2024-03-15T10:00:00Z"
                        },
                        "prefContactId": null,
                        "billingContactId": null,
                        "secondaryContactId": null,
                        "clientContactInfoId": 44489,
                        "billingAddressId": 211,
                        "taxRegionIds": [],
                        "ignoredCustomFields": []
                      },
                      "meta": {
                        "success": true,
                        "message": "Client onboarded successfully",
                        "timestamp": "2024-03-15T10:00:00.123Z",
                        "version": "v1"
                      }
                    }
                  },
                  "success_with_ignored_custom_fields": {
                    "summary": "Onboarded with tax regions; an unknown custom field key was dropped",
                    "value": {
                      "data": {
                        "client": {
                          "id": 1002,
                          "pmsRef": "REDW-100",
                          "clientRef": "REDW-100",
                          "name": "Redw Client",
                          "officeId": 1,
                          "clientTypeId": 7,
                          "clientBusinessEntityId": 4,
                          "staffBillingManagerId": 22,
                          "fiscalYearEndMonth": 12,
                          "fiscalYearEndDay": 31,
                          "customFieldValuesJson": "{\"industry_niche\":\"Manufacturing\"}",
                          "active": true,
                          "status": "ACTIVE",
                          "version": 1,
                          "createdAt": "2024-03-15T10:00:00Z",
                          "updatedAt": "2024-03-15T10:00:00Z"
                        },
                        "prefContactId": null,
                        "billingContactId": null,
                        "secondaryContactId": null,
                        "clientContactInfoId": null,
                        "billingAddressId": null,
                        "taxRegionIds": [
                          3,
                          7
                        ],
                        "ignoredCustomFields": [
                          "naics_cod"
                        ]
                      },
                      "meta": {
                        "success": true,
                        "message": "Client onboarded successfully; ignored unknown or protected custom fields: naics_cod",
                        "timestamp": "2024-03-15T10:00:00.123Z",
                        "version": "v1"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data — for example, a client with the same `pmsRef` already exists, both `id` and `contactInfo` were supplied on a contact field, a required field is missing, or an address has an unknown country/US state or a `pmsRef` that already exists. A body that fails request validation (missing or malformed fields) returns the global ART error shape `{ message, extensions: { code, details } }`; a request rejected by the onboarding rules (duplicate client `pmsRef`, unknown reference IDs, invalid address) returns the envelope `{ error: { code, message }, meta: { success: false } }`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "type": "object",
                      "description": "Global ART error",
                      "required": [
                        "message",
                        "extensions"
                      ],
                      "properties": {
                        "message": {
                          "type": "string"
                        },
                        "extensions": {
                          "type": "object",
                          "properties": {
                            "code": {
                              "type": "integer"
                            },
                            "details": {
                              "type": "object"
                            }
                          }
                        }
                      }
                    },
                    {
                      "type": "object",
                      "description": "Onboarding rule rejected the request",
                      "required": [
                        "error",
                        "meta"
                      ],
                      "properties": {
                        "error": {
                          "type": "object",
                          "required": [
                            "code",
                            "message"
                          ],
                          "properties": {
                            "code": {
                              "type": "string",
                              "example": "ERROR"
                            },
                            "message": {
                              "type": "string"
                            }
                          }
                        },
                        "meta": {
                          "type": "object",
                          "required": [
                            "success"
                          ],
                          "properties": {
                            "success": {
                              "type": "boolean",
                              "example": false
                            },
                            "timestamp": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "version": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "duplicate_client_pms_ref": {
                    "summary": "A client with this pmsRef already exists",
                    "value": {
                      "error": {
                        "code": "ERROR",
                        "message": "Invalid onboarding data: A client with the provided PMS reference already exists"
                      },
                      "meta": {
                        "success": false,
                        "timestamp": "2024-03-15T10:00:00.123Z"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires ROLE_CLIENT_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/client_business_entities": {
      "post": {
        "tags": [
          "Client Business Entity"
        ],
        "summary": "List client business entities",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client business entity](/reference/data-dictionary/client-business-entity)\n\n**Retrieve all client business entities with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint. It is useful after creating records via `/api/v1/records`.\n",
        "operationId": "getClientBusinessEntitiesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved client business entities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "clientBusinessEntities",
                    "total"
                  ],
                  "properties": {
                    "clientBusinessEntities": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "Every listed property is always present; optional columns are null when unset",
                        "required": [
                          "id",
                          "name",
                          "active",
                          "clientBusinessEntityType",
                          "ref",
                          "sysRefs",
                          "createdAt",
                          "updatedAt",
                          "version",
                          "pmsRefs",
                          "customFieldValues"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "clientBusinessEntityType": {
                            "type": "string"
                          },
                          "ref": {
                            "type": "string"
                          },
                          "sysRefs": {
                            "description": "Source-system references (JSON); null when unset"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "pmsRefs": {
                            "type": "string",
                            "description": "Identifier of the business entity in the practice management system"
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields for the business entity, keyed by custom field code"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "clientBusinessEntities": [
                        {
                          "id": 101,
                          "name": "Tax",
                          "active": true,
                          "clientBusinessEntityType": "TAX",
                          "ref": "TAX",
                          "sysRefs": {},
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "pmsRefs": "TAX",
                          "customFieldValues": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/client_types": {
      "post": {
        "tags": [
          "Client"
        ],
        "summary": "List client types",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Client type](/reference/data-dictionary/client-type)\n\n**Retrieve all client types with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint. Use it to resolve the\n`clientTypeId` values accepted by the Client Onboarding endpoint\n(`POST /api/v1/clients/v1/onboard`).\n",
        "operationId": "getClientTypesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved client types",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "clientTypes",
                    "total"
                  ],
                  "properties": {
                    "clientTypes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "Every listed property is always present; optional columns are null when unset",
                        "required": [
                          "id",
                          "name",
                          "active",
                          "is_business",
                          "pms_ref",
                          "created_at",
                          "updated_at",
                          "created_by_staff_id",
                          "last_updated_by_staff_id"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "is_business": {
                            "type": [
                              "boolean",
                              "null"
                            ]
                          },
                          "pms_ref": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time"
                          },
                          "created_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the client type"
                          },
                          "last_updated_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the client type"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "clientTypes": [
                        {
                          "id": 2,
                          "name": "Corporation",
                          "active": true,
                          "is_business": true,
                          "pms_ref": "CORP",
                          "created_at": "2025-01-02T03:04:05Z",
                          "updated_at": "2025-01-02T03:04:05Z",
                          "created_by_staff_id": 12,
                          "last_updated_by_staff_id": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contact_clients": {
      "post": {
        "tags": [
          "Contact Client"
        ],
        "summary": "List contact-client relationships",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact-client relationship](/reference/data-dictionary/contact-client)\n\n**Retrieve all contact-client relationships with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getContactClientsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved contact-client relationships",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "contactClients",
                    "total"
                  ],
                  "properties": {
                    "contactClients": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "Every listed property is always present; optional columns are null when unset",
                        "required": [
                          "id",
                          "pms_ref",
                          "active",
                          "client_id",
                          "contact_id",
                          "relationship",
                          "receives_invoice",
                          "receives_statement",
                          "receives_payment_confirmation",
                          "sys_refs",
                          "created_at",
                          "updated_at",
                          "version",
                          "inactivated_at",
                          "is_managed_by_aiwyn",
                          "is_created_by_aiwyn",
                          "custom_field_values"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pms_ref": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "client_id": {
                            "type": "integer"
                          },
                          "contact_id": {
                            "type": "integer"
                          },
                          "relationship": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "receives_invoice": {
                            "type": [
                              "boolean",
                              "null"
                            ]
                          },
                          "receives_statement": {
                            "type": [
                              "boolean",
                              "null"
                            ]
                          },
                          "receives_payment_confirmation": {
                            "type": [
                              "boolean",
                              "null"
                            ]
                          },
                          "sys_refs": {
                            "description": "Source-system references (JSON); null when unset"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "inactivated_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the link between the contact and the client was inactivated (no time zone offset)"
                          },
                          "is_managed_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether Aiwyn manages the record's lifecycle"
                          },
                          "is_created_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether the record was created in Aiwyn"
                          },
                          "custom_field_values": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields for the contact-client link, keyed by custom field code"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "contactClients": [
                        {
                          "id": 9001,
                          "pms_ref": "CC-10001",
                          "active": true,
                          "client_id": 1001,
                          "contact_id": 2001,
                          "relationship": "OWNER",
                          "receives_invoice": true,
                          "receives_statement": true,
                          "receives_payment_confirmation": false,
                          "sys_refs": {},
                          "created_at": "2025-01-02T03:04:05Z",
                          "updated_at": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "inactivated_at": null,
                          "is_managed_by_aiwyn": false,
                          "is_created_by_aiwyn": false,
                          "custom_field_values": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contact_infos": {
      "post": {
        "tags": [
          "Contact Info"
        ],
        "summary": "List contact infos",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact info](/reference/data-dictionary/contact-info)\n\n**Retrieve all contact info records with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getContactInfosPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved contact infos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "contactInfos",
                    "total"
                  ],
                  "properties": {
                    "contactInfos": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "Every listed property is always present; optional columns are null when unset",
                        "required": [
                          "id",
                          "pms_ref",
                          "active",
                          "salutation",
                          "firstName",
                          "lastName",
                          "email",
                          "phone",
                          "address",
                          "address2",
                          "city",
                          "state",
                          "country",
                          "zip_code",
                          "created_at",
                          "updated_at",
                          "version",
                          "full_name",
                          "short_name",
                          "is_managed_by_aiwyn",
                          "is_created_by_aiwyn",
                          "job_title",
                          "prefix",
                          "custom_field_values"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pms_ref": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "salutation": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "firstName": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "lastName": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "email": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "address": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "address2": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "city": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "state": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "country": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "zip_code": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "full_name": {
                            "type": "string",
                            "description": "Full name"
                          },
                          "short_name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Short or informal name"
                          },
                          "is_managed_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether Aiwyn manages the record's lifecycle"
                          },
                          "is_created_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether the record was created in Aiwyn"
                          },
                          "job_title": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Job title"
                          },
                          "prefix": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Name prefix"
                          },
                          "custom_field_values": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields for the contact info, keyed by custom field code"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "contactInfos": [
                        {
                          "id": 3001,
                          "pms_ref": "CI-3001",
                          "active": true,
                          "salutation": "Ms.",
                          "firstName": "Asha",
                          "lastName": "Patel",
                          "email": "asha.patel@example.com",
                          "phone": "555-0101",
                          "address": "123 Main St",
                          "address2": "Suite 400",
                          "city": "Austin",
                          "state": "TX",
                          "country": "US",
                          "zip_code": "78701",
                          "created_at": "2025-01-02T03:04:05Z",
                          "updated_at": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "full_name": "Asha Patel",
                          "short_name": "Asha",
                          "is_managed_by_aiwyn": false,
                          "is_created_by_aiwyn": false,
                          "job_title": "Controller",
                          "prefix": null,
                          "custom_field_values": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/departments": {
      "post": {
        "tags": [
          "Department"
        ],
        "summary": "List departments",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Department](/reference/data-dictionary/department)\n\n**Retrieve all departments with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getDepartmentsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved departments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "departments",
                    "total"
                  ],
                  "properties": {
                    "departments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "pmsRef",
                          "name",
                          "active",
                          "isCreatedByAiwyn",
                          "isManagedByAiwyn",
                          "createdAt",
                          "updatedAt",
                          "version",
                          "createdByStaffId",
                          "lastUpdatedByStaffId",
                          "customFieldValues"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pmsRef": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean"
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean"
                          },
                          "createdAt": {
                            "type": "string"
                          },
                          "updatedAt": {
                            "type": "string"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever created the record."
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever last updated the record."
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields."
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "departments": [
                        {
                          "id": 7,
                          "pmsRef": "DEPT-7",
                          "name": "Tax",
                          "active": true,
                          "isCreatedByAiwyn": true,
                          "isManagedByAiwyn": true,
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "createdByStaffId": null,
                          "lastUpdatedByStaffId": 53,
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/industries": {
      "post": {
        "tags": [
          "Industry"
        ],
        "summary": "List industries",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Industry](/reference/data-dictionary/industry)\n\n**Retrieve all industries with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getIndustriesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved industries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "industries",
                    "total"
                  ],
                  "properties": {
                    "industries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "name",
                          "active",
                          "industryType",
                          "ref",
                          "sysRefs",
                          "createdAt",
                          "updatedAt",
                          "version",
                          "pmsRefs",
                          "customFieldValues"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "industryType": {
                            "type": "string"
                          },
                          "ref": {
                            "type": "string"
                          },
                          "sysRefs": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true
                          },
                          "createdAt": {
                            "type": "string"
                          },
                          "updatedAt": {
                            "type": "string"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "pmsRefs": {
                            "type": "string",
                            "description": "Identifier in the external practice management system."
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields."
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "industries": [
                        {
                          "id": 55,
                          "name": "Healthcare",
                          "active": true,
                          "industryType": "NAICS",
                          "ref": "HC",
                          "sysRefs": {},
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "pmsRefs": "HC",
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/jobs": {
      "post": {
        "tags": [
          "Job"
        ],
        "summary": "List jobs",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Job](/reference/data-dictionary/job)\n\n**Retrieve all jobs with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getJobsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved jobs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/JobRecord"
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "jobs": [
                        {
                          "id": 5012,
                          "pmsRef": "JOB-5012",
                          "jobRef": "J-0005012",
                          "name": "Q1 Financial Review 2025",
                          "status": "ACTIVE",
                          "isActive": true,
                          "clientId": 1001,
                          "deptId": 7,
                          "officeId": 2,
                          "jobTemplateId": 300,
                          "managerStaffId": 102,
                          "partnerStaffId": 101,
                          "startDate": "2025-01-01T00:00:00Z",
                          "endDate": "2025-03-31T23:59:59Z",
                          "dueDate": "2025-03-31T23:59:59Z",
                          "targetStartDate": "2025-01-01T00:00:00Z",
                          "targetedStartDate": "2025-01-01T00:00:00Z",
                          "targetEndDate": "2025-03-31T23:59:59Z",
                          "targetedEndDate": "2025-03-31T23:59:59Z",
                          "feeStructureId": 42,
                          "feeStructureV4": {
                            "id": 42,
                            "type": "FIXED",
                            "amount": 5000,
                            "active": true
                          },
                          "sysRefs": {},
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-03T10:11:12Z",
                          "customFieldValues": {
                            "industry_niche": "Manufacturing",
                            "naics_code": "333120"
                          },
                          "version": 3
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/job/{id}": {
      "get": {
        "tags": [
          "Job"
        ],
        "summary": "Get job by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Job](/reference/data-dictionary/job)\n\n**Retrieve a specific job by its unique identifier**\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getJobById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the job",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 5012
          }
        ],
        "responses": {
          "200": {
            "description": "Job details retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "job"
                  ],
                  "properties": {
                    "job": {
                      "type": "array",
                      "maxItems": 1,
                      "description": "The job, or an empty array when the id matches no job",
                      "items": {
                        "$ref": "#/components/schemas/JobRecord"
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "job": [
                        {
                          "id": 5012,
                          "pmsRef": "JOB-5012",
                          "jobRef": "J-0005012",
                          "name": "Q1 Financial Review 2025",
                          "status": "ACTIVE",
                          "isActive": true,
                          "clientId": 1001,
                          "deptId": 7,
                          "officeId": 2,
                          "jobTemplateId": 300,
                          "managerStaffId": 102,
                          "partnerStaffId": 101,
                          "startDate": "2025-01-01T00:00:00Z",
                          "endDate": "2025-03-31T23:59:59Z",
                          "dueDate": "2025-03-31T23:59:59Z",
                          "targetStartDate": "2025-01-01T00:00:00Z",
                          "targetedStartDate": "2025-01-01T00:00:00Z",
                          "targetEndDate": "2025-03-31T23:59:59Z",
                          "targetedEndDate": "2025-03-31T23:59:59Z",
                          "feeStructureId": 42,
                          "feeStructureV4": {
                            "id": 42,
                            "type": "FIXED",
                            "amount": 5000,
                            "active": true
                          },
                          "sysRefs": {},
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-03T10:11:12Z",
                          "customFieldValues": {
                            "industry_niche": "Manufacturing",
                            "naics_code": "333120"
                          },
                          "version": 3
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/job_templates": {
      "post": {
        "tags": [
          "Job Template"
        ],
        "summary": "List job templates",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Job template](/reference/data-dictionary/job-template)\n\n**Retrieve all job templates with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getJobTemplatesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved job templates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobTemplates": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "Unique job template identifier.",
                            "example": 300
                          },
                          "pmsRef": {
                            "type": "string",
                            "description": "Identifier in the external practice management system.",
                            "example": "JT-300"
                          },
                          "ref": {
                            "type": "string",
                            "description": "Reference identifier for the template.",
                            "example": "1040"
                          },
                          "name": {
                            "type": "string",
                            "description": "Name of the template.",
                            "example": "Individual Tax Return"
                          },
                          "active": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the template is active.",
                            "example": true
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Service line of the template (service line id).",
                            "example": 10
                          },
                          "isCreatedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the record was created in Aiwyn.",
                            "example": true
                          },
                          "isManagedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether Aiwyn manages the record's lifecycle.",
                            "example": true
                          },
                          "sysRefs": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "References of the template in connected systems, keyed by system.",
                            "example": {}
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the record was created.",
                            "example": "2025-01-02T03:04:05Z"
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the record was last updated.",
                            "example": "2025-01-02T03:04:05Z"
                          },
                          "version": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Record version for optimistic concurrency.",
                            "example": 1
                          },
                          "jobNameTemplate": {
                            "type": "string",
                            "description": "Pattern used to generate the name of projects created from the template.",
                            "example": "{{client.name}} 1040 {{year}}"
                          },
                          "jobDescriptionTemplate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Pattern used to generate the description of projects created from the template.",
                            "example": null
                          },
                          "longServiceDescriptionTemplate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Extended service description applied to projects created from the template.",
                            "example": null
                          },
                          "modifiedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff member who last modified the template (staff id).",
                            "example": null
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff member who created the template (staff id).",
                            "example": 102
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff member who last updated the template (staff id).",
                            "example": 102
                          },
                          "startOffset": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Offset applied to the start date of projects created from the template.",
                            "example": 0
                          },
                          "startOffsetType": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Unit of the start offset, `DAYS`, `WEEKS` or `MONTHS`.",
                            "example": "DAYS"
                          },
                          "startAfterType": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Reference point the start offset is calculated from, `PROJECT_CREATION` or `ENGAGEMENT_SIGNED`.",
                            "example": "PROJECT_CREATION"
                          },
                          "dueOffset": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Offset applied to the due date of projects created from the template.",
                            "example": 30
                          },
                          "dueOffsetType": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Unit of the due offset, `DAYS`, `WEEKS` or `MONTHS`.",
                            "example": "DAYS"
                          },
                          "estimationEnabled": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether hour estimation is enabled for projects created from the template.",
                            "example": false
                          },
                          "estimationHours": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Estimated hours for projects created from the template.",
                            "example": null
                          },
                          "primaryDeliverableTemplateId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Primary deliverable template of the template (deliverable template id).",
                            "example": null
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields of the template, keyed by custom field code.",
                            "example": {}
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "jobTemplates": [
                        {
                          "id": 300,
                          "pmsRef": "JT-300",
                          "ref": "1040",
                          "name": "Individual Tax Return",
                          "active": true,
                          "serviceLineId": 10,
                          "isCreatedByAiwyn": true,
                          "isManagedByAiwyn": true,
                          "sysRefs": {},
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/offices": {
      "post": {
        "tags": [
          "Office"
        ],
        "summary": "List offices",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Office](/reference/data-dictionary/office)\n\n**Retrieve all offices with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getOfficesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved offices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "offices",
                    "total"
                  ],
                  "properties": {
                    "offices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "pmsRef",
                          "name",
                          "active",
                          "city",
                          "stateProvince",
                          "country",
                          "zip",
                          "isCreatedByAiwyn",
                          "isManagedByAiwyn",
                          "createdAt",
                          "updatedAt",
                          "version",
                          "address",
                          "addressLine1",
                          "addressLine2",
                          "phone",
                          "fax",
                          "email",
                          "timezone",
                          "createdByStaffId",
                          "lastUpdatedByStaffId",
                          "customFieldValues"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pmsRef": {
                            "type": "string"
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "city": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "stateProvince": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "country": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "zip": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean"
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean"
                          },
                          "createdAt": {
                            "type": "string"
                          },
                          "updatedAt": {
                            "type": "string"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "address": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Full address of the office."
                          },
                          "addressLine1": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Address line 1."
                          },
                          "addressLine2": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Address line 2."
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Phone number."
                          },
                          "fax": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Fax number."
                          },
                          "email": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Email address."
                          },
                          "timezone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Time zone of the office."
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever created the record."
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever last updated the record."
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields."
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "offices": [
                        {
                          "id": 2,
                          "pmsRef": "OFF-2",
                          "name": "Austin - Downtown",
                          "active": true,
                          "city": "Austin",
                          "stateProvince": "TX",
                          "country": "US",
                          "zip": "78701",
                          "isCreatedByAiwyn": true,
                          "isManagedByAiwyn": true,
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "address": "100 Congress Ave, Suite 200, Austin, TX 78701",
                          "addressLine1": "100 Congress Ave",
                          "addressLine2": "Suite 200",
                          "phone": "+1 512 555 0100",
                          "fax": null,
                          "email": "austin@example.com",
                          "timezone": "America/Chicago",
                          "createdByStaffId": null,
                          "lastUpdatedByStaffId": 53,
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/orgs": {
      "post": {
        "tags": [
          "Org"
        ],
        "summary": "List orgs",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Organization](/reference/data-dictionary/organization)\n\n**Retrieve all orgs with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint.\n",
        "operationId": "getOrgsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved orgs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "orgs",
                    "total"
                  ],
                  "properties": {
                    "orgs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "pmsRef",
                          "name",
                          "active",
                          "defaultBillingDay",
                          "isDefault",
                          "isCreatedByAiwyn",
                          "isManagedByAiwyn",
                          "createdAt",
                          "updatedAt",
                          "version",
                          "createdByStaffId",
                          "lastUpdatedByStaffId",
                          "customFieldValues"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pmsRef": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "defaultBillingDay": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "isDefault": {
                            "type": "boolean"
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean"
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean"
                          },
                          "createdAt": {
                            "type": "string"
                          },
                          "updatedAt": {
                            "type": "string"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever created the record."
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever last updated the record."
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields."
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "orgs": [
                        {
                          "id": 1,
                          "pmsRef": "ORG-1",
                          "name": "Acme Accounting",
                          "active": true,
                          "defaultBillingDay": 15,
                          "isDefault": true,
                          "isCreatedByAiwyn": true,
                          "isManagedByAiwyn": true,
                          "createdAt": "2025-01-02T03:04:05Z",
                          "updatedAt": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "createdByStaffId": null,
                          "lastUpdatedByStaffId": 53,
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/service_lines": {
      "post": {
        "tags": [
          "Service Line"
        ],
        "summary": "List service lines",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Service line](/reference/data-dictionary/service-line)\n\n**Retrieve all service lines with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint backed by Hasura.\n\nUnlike the other lookups, item keys are snake_case (`created_at`, `updated_at`, …).\n",
        "operationId": "getServiceLinesPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved service lines",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "serviceLines",
                    "total"
                  ],
                  "properties": {
                    "serviceLines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "pms_ref",
                          "name",
                          "active",
                          "charge_admin_fee",
                          "created_at",
                          "updated_at",
                          "version",
                          "is_created_by_aiwyn",
                          "is_managed_by_aiwyn",
                          "created_by_staff_id",
                          "last_updated_by_staff_id",
                          "business_entity_id",
                          "custom_field_values"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "pms_ref": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "charge_admin_fee": {
                            "type": "boolean"
                          },
                          "created_at": {
                            "type": "string"
                          },
                          "updated_at": {
                            "type": "string"
                          },
                          "version": {
                            "type": "integer"
                          },
                          "is_created_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether the record was created in Aiwyn."
                          },
                          "is_managed_by_aiwyn": {
                            "type": "boolean",
                            "description": "Whether Aiwyn manages the record's lifecycle."
                          },
                          "created_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever created the record."
                          },
                          "last_updated_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff id of whoever last updated the record."
                          },
                          "business_entity_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Business entity id that owns the service line; null when it falls back to the firm default."
                          },
                          "custom_field_values": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields."
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "serviceLines": [
                        {
                          "id": 10,
                          "pms_ref": "SL-10",
                          "name": "Tax",
                          "active": true,
                          "charge_admin_fee": false,
                          "created_at": "2025-01-02T03:04:05Z",
                          "updated_at": "2025-01-02T03:04:05Z",
                          "version": 1,
                          "is_created_by_aiwyn": false,
                          "is_managed_by_aiwyn": false,
                          "created_by_staff_id": null,
                          "last_updated_by_staff_id": 53,
                          "business_entity_id": null,
                          "custom_field_values": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/tax_regions": {
      "post": {
        "tags": [
          "Client"
        ],
        "summary": "List tax regions",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Tax region](/reference/data-dictionary/tax-region)\n\n**Retrieve all tax regions with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis is a read-only lookup endpoint. Use it to resolve the\n`taxRegionIds` values accepted by the Client Onboarding endpoint\n(`POST /api/v1/clients/v1/onboard`).\n\nUnlike the other lookups, item keys are snake_case (`tax_percentage`, `created_at`, …).\n",
        "operationId": "getTaxRegionsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved tax regions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "taxRegions",
                    "total"
                  ],
                  "properties": {
                    "taxRegions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "name",
                          "active",
                          "description",
                          "tax_percentage",
                          "type",
                          "created_at",
                          "updated_at",
                          "created_by_staff_id",
                          "last_updated_by_staff_id",
                          "pms_ref"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "active": {
                            "type": "boolean"
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "tax_percentage": {
                            "type": "number"
                          },
                          "type": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_at": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "updated_at": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the tax region"
                          },
                          "last_updated_by_staff_id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the tax region"
                          },
                          "pms_ref": {
                            "type": "string",
                            "description": "Identifier of the tax region in the practice management system"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Sample response",
                    "value": {
                      "taxRegions": [
                        {
                          "id": 10,
                          "name": "California",
                          "active": true,
                          "description": "California state sales tax",
                          "tax_percentage": 7.25,
                          "type": "STATE",
                          "created_at": "2025-01-02T03:04:05Z",
                          "updated_at": "2025-01-02T03:04:05Z",
                          "created_by_staff_id": 12,
                          "last_updated_by_staff_id": null,
                          "pms_ref": "CA"
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contacts": {
      "post": {
        "tags": [
          "Contact"
        ],
        "summary": "List contacts",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact](/reference/data-dictionary/contact)\n\n**Retrieve all contacts with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nReturns a paginated list of contacts. Default sort prioritizes last/first name.\n",
        "operationId": "getContactsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved contacts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactListResponse"
                },
                "examples": {
                  "successful_response": {
                    "summary": "One page of contacts",
                    "value": {
                      "contacts": [
                        {
                          "id": 1001,
                          "pms_ref": "C-4451",
                          "active": true,
                          "contact_info_id": 7001,
                          "office_id": 3,
                          "staff_id": null,
                          "type": null,
                          "fwd_email_confirmation": false,
                          "inactivated_at": null,
                          "created_at": "2024-03-01T15:20:11.104223+00:00",
                          "updated_at": "2024-09-14T08:02:47.551092+00:00",
                          "is_managed_by_aiwyn": false,
                          "is_created_by_aiwyn": false,
                          "username": null,
                          "custom_field_values": null,
                          "contact_info": {
                            "id": 7001,
                            "pms_ref": "C-4451",
                            "salutation": null,
                            "firstName": "Jane",
                            "lastName": "Smith",
                            "email": "jane.smith@acme.com",
                            "phone": null,
                            "address": "123 Main St",
                            "address2": null,
                            "city": "Charlotte",
                            "state": "NC",
                            "country": "US",
                            "zip_code": "28202",
                            "active": true
                          },
                          "contact_clients": [
                            {
                              "client_id": 122,
                              "contact_id": 1001,
                              "pms_ref": "LL-9981",
                              "active": true
                            }
                          ]
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 959
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No contacts (or offset at/beyond the total)",
                    "value": {
                      "contacts": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contacts/search": {
      "post": {
        "tags": [
          "Contact"
        ],
        "summary": "Search contacts",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact](/reference/data-dictionary/contact)\n\n**Advanced contact filtering with flexible `where` clauses and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nFilter contacts using boolean logic and relationship-aware fields from `contact_info`.\n",
        "operationId": "filterContactsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "contact_info": {
                            "firstName": {
                              "_ilike": "%john%"
                            }
                          }
                        },
                        {
                          "contact_info": {
                            "lastName": {
                              "_ilike": "%doe%"
                            }
                          }
                        }
                      ]
                    },
                    {
                      "active": {
                        "_eq": true
                      }
                    },
                    {
                      "createdAt": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "contact_info": {
                        "email": {
                          "_ilike": "%@company.com%"
                        }
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "contact_info": {
                      "lastName": "asc"
                    }
                  },
                  {
                    "createdAt": "desc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`. Defaults to 50 when omitted."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex contact filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "contact_info": {
                                "firstName": {
                                  "_ilike": "%john%"
                                }
                              }
                            },
                            {
                              "contact_info": {
                                "lastName": {
                                  "_ilike": "%doe%"
                                }
                              }
                            }
                          ]
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "contact_info": {
                            "email": {
                              "_ilike": "%@company.com%"
                            }
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering with nested relationship fields",
                    "example": [
                      {
                        "contact_info": {
                          "lastName": "asc"
                        }
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered contacts; `total` counts the contacts matching `where`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactListResponse"
                },
                "examples": {
                  "successful_response": {
                    "summary": "One page of contacts",
                    "value": {
                      "contacts": [
                        {
                          "id": 1001,
                          "pms_ref": "C-4451",
                          "active": true,
                          "contact_info_id": 7001,
                          "office_id": 3,
                          "staff_id": null,
                          "type": null,
                          "fwd_email_confirmation": false,
                          "inactivated_at": null,
                          "created_at": "2024-03-01T15:20:11.104223+00:00",
                          "updated_at": "2024-09-14T08:02:47.551092+00:00",
                          "is_managed_by_aiwyn": false,
                          "is_created_by_aiwyn": false,
                          "username": null,
                          "custom_field_values": null,
                          "contact_info": {
                            "id": 7001,
                            "pms_ref": "C-4451",
                            "salutation": null,
                            "firstName": "Jane",
                            "lastName": "Smith",
                            "email": "jane.smith@acme.com",
                            "phone": null,
                            "address": "123 Main St",
                            "address2": null,
                            "city": "Charlotte",
                            "state": "NC",
                            "country": "US",
                            "zip_code": "28202",
                            "active": true
                          },
                          "contact_clients": [
                            {
                              "client_id": 122,
                              "contact_id": 1001,
                              "pms_ref": "LL-9981",
                              "active": true
                            }
                          ]
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 12
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No contacts (or offset at/beyond the total)",
                    "value": {
                      "contacts": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contact/{id}": {
      "get": {
        "tags": [
          "Contact"
        ],
        "summary": "Get contact by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact](/reference/data-dictionary/contact)\n\n**Retrieve a specific contact by its unique identifier**\n\nReturns the contact wrapped in a `contact` key, with its contact info (name, email,\nphone, address) and its client links. Field names are snake_case except\n`contact_info.firstName` / `contact_info.lastName`. Optional columns are `null` when unset.\n\n**Not found:** an `id` that matches no contact returns **200** with `{\"contact\": null}`\n(not 404). A non-numeric `id` returns **400**.\n",
        "operationId": "getContactById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the contact",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1001
          }
        ],
        "responses": {
          "200": {
            "description": "Contact found (`contact` is the record) or not found (`contact` is `null`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "contact"
                  ],
                  "properties": {
                    "contact": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Contact"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "examples": {
                  "found": {
                    "summary": "Contact found",
                    "value": {
                      "contact": {
                        "id": 1001,
                        "pms_ref": "C-4451",
                        "active": true,
                        "contact_info_id": 7001,
                        "office_id": 3,
                        "staff_id": null,
                        "type": null,
                        "fwd_email_confirmation": false,
                        "inactivated_at": null,
                        "created_at": "2024-03-01T15:20:11.104223+00:00",
                        "updated_at": "2024-09-14T08:02:47.551092+00:00",
                        "is_managed_by_aiwyn": false,
                        "is_created_by_aiwyn": false,
                        "username": null,
                        "custom_field_values": null,
                        "contact_info": {
                          "id": 7001,
                          "pms_ref": "C-4451",
                          "salutation": null,
                          "firstName": "Jane",
                          "lastName": "Smith",
                          "email": "jane.smith@acme.com",
                          "phone": null,
                          "address": "123 Main St",
                          "address2": null,
                          "city": "Charlotte",
                          "state": "NC",
                          "country": "US",
                          "zip_code": "28202",
                          "active": true
                        },
                        "contact_clients": [
                          {
                            "client_id": 122,
                            "contact_id": 1001,
                            "pms_ref": "LL-9981",
                            "active": true
                          }
                        ]
                      }
                    }
                  },
                  "not_found": {
                    "summary": "No contact with this id",
                    "value": {
                      "contact": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this contact"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/contacts/by_client/{clientId}": {
      "get": {
        "tags": [
          "Contact"
        ],
        "summary": "Get contacts by client ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Contact](/reference/data-dictionary/contact)\n\n**Retrieve active contacts associated with a specific client**\n\nReturns all contacts linked to the given client via the contact-client relationship,\nwhere the contact, contact-client link, and contact info are all active.\n\nResults are ordered by last name then first name.\n",
        "operationId": "getContactsByClientId",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "clientId",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the client",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 789
          }
        ],
        "responses": {
          "200": {
            "description": "Active contacts for the client retrieved successfully. Only active links whose contact\nand contact info are active are returned, ordered by last name then first name. A\n`clientId` that matches no client returns **200** with `{\"contacts\": []}`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "contacts"
                  ],
                  "properties": {
                    "contacts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "contact_id",
                          "client_id",
                          "active",
                          "relationship",
                          "receives_invoice",
                          "receives_statement",
                          "receives_payment_confirmation",
                          "contact"
                        ],
                        "properties": {
                          "contact_id": {
                            "type": "integer",
                            "description": "Unique contact identifier",
                            "example": 23456
                          },
                          "client_id": {
                            "type": "integer",
                            "description": "Associated client identifier",
                            "example": 789
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Whether this contact-client relationship is active",
                            "example": true
                          },
                          "relationship": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Relationship type between the contact and client; null when unset",
                            "example": "PRIMARY"
                          },
                          "receives_invoice": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether this contact receives invoices; null when never set",
                            "example": true
                          },
                          "receives_statement": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether this contact receives statements; null when never set",
                            "example": false
                          },
                          "receives_payment_confirmation": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether this contact receives payment confirmations; null when never set",
                            "example": true
                          },
                          "contact": {
                            "type": "object",
                            "required": [
                              "id",
                              "pms_ref",
                              "active",
                              "type",
                              "fwd_email_confirmation",
                              "inactivated_at",
                              "created_at",
                              "updated_at",
                              "is_managed_by_aiwyn",
                              "is_created_by_aiwyn",
                              "username",
                              "custom_field_values",
                              "contact_info"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 23456
                              },
                              "pms_ref": {
                                "type": "string",
                                "description": "PMS reference identifier",
                                "example": "PMS-001"
                              },
                              "active": {
                                "type": "boolean",
                                "example": true
                              },
                              "type": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Contact type; null when unset",
                                "example": "CLIENT_CONTACT"
                              },
                              "fwd_email_confirmation": {
                                "type": "boolean",
                                "description": "Whether to forward email confirmations to this contact",
                                "example": true
                              },
                              "inactivated_at": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "format": "date-time",
                                "description": "When the contact was inactivated (no time zone offset); null while active",
                                "example": null
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the record was created",
                                "example": "2024-03-01T15:20:11.104223+00:00"
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the record was last updated",
                                "example": "2024-09-14T08:02:47.551092+00:00"
                              },
                              "is_managed_by_aiwyn": {
                                "type": "boolean",
                                "description": "Whether Aiwyn manages the record's lifecycle",
                                "example": false
                              },
                              "is_created_by_aiwyn": {
                                "type": "boolean",
                                "description": "Whether the record was created in Aiwyn",
                                "example": false
                              },
                              "username": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Client portal username of the contact; null when the contact has no portal account",
                                "example": "jane.smith@acme.com"
                              },
                              "custom_field_values": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": true,
                                "description": "Firm-defined custom fields for the contact, keyed by custom field code",
                                "example": null
                              },
                              "contact_info": {
                                "type": "object",
                                "required": [
                                  "id",
                                  "salutation",
                                  "firstName",
                                  "lastName",
                                  "email",
                                  "phone",
                                  "address",
                                  "address2",
                                  "city",
                                  "state",
                                  "country",
                                  "zip_code",
                                  "active"
                                ],
                                "properties": {
                                  "id": {
                                    "type": "integer",
                                    "example": 5678
                                  },
                                  "salutation": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "Mr."
                                  },
                                  "firstName": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "John"
                                  },
                                  "lastName": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "Smith"
                                  },
                                  "email": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "john.smith@acme.com"
                                  },
                                  "phone": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "+1-555-0123"
                                  },
                                  "address": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "123 Business Ave"
                                  },
                                  "address2": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "Suite 400"
                                  },
                                  "city": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "New York"
                                  },
                                  "state": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "NY"
                                  },
                                  "country": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "USA"
                                  },
                                  "zip_code": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "example": "10001"
                                  },
                                  "active": {
                                    "type": "boolean",
                                    "example": true
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Two active contacts for client 789",
                    "value": {
                      "contacts": [
                        {
                          "contact_id": 23456,
                          "client_id": 789,
                          "active": true,
                          "relationship": "PRIMARY",
                          "receives_invoice": true,
                          "receives_statement": false,
                          "receives_payment_confirmation": true,
                          "contact": {
                            "id": 23456,
                            "pms_ref": "PMS-001",
                            "active": true,
                            "type": "CLIENT_CONTACT",
                            "fwd_email_confirmation": true,
                            "inactivated_at": null,
                            "created_at": "2024-03-01T15:20:11.104223+00:00",
                            "updated_at": "2024-09-14T08:02:47.551092+00:00",
                            "is_managed_by_aiwyn": false,
                            "is_created_by_aiwyn": false,
                            "username": null,
                            "custom_field_values": null,
                            "contact_info": {
                              "id": 5678,
                              "salutation": "Mr.",
                              "firstName": "John",
                              "lastName": "Smith",
                              "email": "john.smith@acme.com",
                              "phone": "+1-555-0123",
                              "address": "123 Business Ave",
                              "address2": "Suite 400",
                              "city": "New York",
                              "state": "NY",
                              "country": "USA",
                              "zip_code": "10001",
                              "active": true
                            }
                          }
                        },
                        {
                          "contact_id": 23457,
                          "client_id": 789,
                          "active": true,
                          "relationship": "BILLING",
                          "receives_invoice": true,
                          "receives_statement": true,
                          "receives_payment_confirmation": false,
                          "contact": {
                            "id": 23457,
                            "pms_ref": "PMS-002",
                            "active": true,
                            "type": "CLIENT_CONTACT",
                            "fwd_email_confirmation": false,
                            "inactivated_at": null,
                            "created_at": "2024-03-01T15:20:11.104223+00:00",
                            "updated_at": "2024-09-14T08:02:47.551092+00:00",
                            "is_managed_by_aiwyn": false,
                            "is_created_by_aiwyn": false,
                            "username": null,
                            "custom_field_values": null,
                            "contact_info": {
                              "id": 5679,
                              "salutation": "Ms.",
                              "firstName": "Jane",
                              "lastName": "Taylor",
                              "email": "jane.taylor@acme.com",
                              "phone": "+1-555-0456",
                              "address": "123 Business Ave",
                              "address2": null,
                              "city": "New York",
                              "state": "NY",
                              "country": "USA",
                              "zip_code": "10001",
                              "active": true
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the clientId is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric clientId",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/contacts/upsert": {
      "post": {
        "tags": [
          "Contact"
        ],
        "summary": "Upsert contacts",
        "description": "\n> 🔐 **Required role:** `RECD_C`\n>\n> 📖 **Data dictionary:** [Contact](/reference/data-dictionary/contact)\n\n**Upsert up to 100 contacts, each linked to one or more existing clients, in one request**\n\nSend a `contacts` array (1–100). Each entry upserts a contact (contact_info + contact) and\nits links to existing clients, all by external reference — no Aiwyn internal ids required.\n\n**Partial success.** Each contact is processed independently in its own transaction, so one\nfailing contact does not roll back the others. The response splits contacts into `succeeded`\nand `failed` (each keyed by request-order `index`); the HTTP status is 200 whenever the\nrequest itself is valid — inspect the lists for individual outcomes.\n\nPer contact:\n- Matched by `pmsRef` (contact) and the (contact, client) pair (links); re-sending updates, never duplicates.\n- `pmsRef` optional: omit to create a native contact (mints `AIWYN_<uuid>`, not idempotent).\n- `clients` optional: omit or `[]` upserts only the contact; unlink via `active: false` (never by absence).\n- `clientRef` resolves by the client's `pmsRef` / `clientRef` / `sysRefs`; refs must not contain `:`.\n- All-or-nothing for that one contact: any unresolved client or stage failure persists nothing for it.\n\nFacade over `POST /api/v1/records`.\n\n**Business Applications:**\n- Bulk contact synchronization\n- Link contacts to existing clients\n\n**Partial success — one contact's client cannot be resolved:**\n```json\n{\n  \"contacts\": [\n    { \"pmsRef\": \"CONTACT-001\", \"contactInfo\": { \"firstName\": \"Jane\", \"lastName\": \"Smith\" }, \"clients\": [ { \"clientRef\": \"CLIENT-12345\" } ] },\n    { \"pmsRef\": \"CONTACT-BAD\", \"contactInfo\": { \"firstName\": \"Ghost\", \"lastName\": \"User\" }, \"clients\": [ { \"clientRef\": \"DOES-NOT-EXIST\" } ] }\n  ]\n}\n```\n\n**Create native — omit pmsRef to create a new Aiwyn contact (server mints AIWYN\\_\\<uuid\\>):**\n```json\n{\n  \"contacts\": [\n    { \"contactInfo\": { \"firstName\": \"Jane\", \"lastName\": \"Smith\", \"email\": \"jane.smith@example.com\" } }\n  ]\n}\n```\n",
        "operationId": "upsertContact",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "contacts": [
                  {
                    "pmsRef": "CONTACT-001",
                    "contactInfo": {
                      "firstName": "Jane",
                      "lastName": "Smith",
                      "email": "jane.smith@example.com"
                    },
                    "clients": [
                      {
                        "clientRef": "CLIENT-12345",
                        "relationship": "Primary Contact",
                        "receivesInvoice": true
                      }
                    ]
                  },
                  {
                    "pmsRef": "CONTACT-002",
                    "contactInfo": {
                      "firstName": "John",
                      "lastName": "Doe"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "contacts"
                ],
                "properties": {
                  "contacts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "pmsRef": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Pmsref"
                        },
                        "contactInfo": {
                          "type": "object",
                          "description": "Contactinfo"
                        },
                        "username": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Username"
                        },
                        "type": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Type"
                        },
                        "fwdEmailConfirmation": {
                          "type": [
                            "boolean",
                            "null"
                          ],
                          "description": "Fwdemailconfirmation"
                        },
                        "fwdEmailConfirmationAddresses": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Fwdemailconfirmationaddresses"
                        },
                        "active": {
                          "type": [
                            "boolean",
                            "null"
                          ],
                          "description": "Active"
                        },
                        "clients": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "clientRef": {
                                "type": "string",
                                "description": "Clientref"
                              },
                              "relationship": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Relationship"
                              },
                              "receivesInvoice": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Receivesinvoice"
                              },
                              "receivesStatement": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Receivesstatement"
                              },
                              "receivesPaymentConfirmation": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Receivespaymentconfirmation"
                              },
                              "active": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Active"
                              }
                            }
                          },
                          "description": "Clients"
                        }
                      }
                    },
                    "description": "Contacts"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch processed; see the succeeded / failed lists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "total",
                        "succeeded",
                        "failed"
                      ],
                      "properties": {
                        "total": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Total"
                        },
                        "succeeded": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "index",
                              "contact",
                              "contactInfo",
                              "clients"
                            ],
                            "properties": {
                              "index": {
                                "type": "integer",
                                "format": "int32",
                                "description": "Index"
                              },
                              "contact": {
                                "type": "object",
                                "description": "Contact"
                              },
                              "contactInfo": {
                                "type": "object",
                                "description": "Contactinfo"
                              },
                              "clients": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Clients"
                              }
                            }
                          },
                          "description": "Succeeded"
                        },
                        "failed": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "index",
                              "error"
                            ],
                            "properties": {
                              "index": {
                                "type": "integer",
                                "format": "int32",
                                "description": "Index"
                              },
                              "pmsRef": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Pmsref"
                              },
                              "error": {
                                "type": "string",
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Failed"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request (empty or more than 100 contacts, or malformed body)"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires RECD_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/engagements": {
      "post": {
        "tags": [
          "Engagement"
        ],
        "summary": "List engagements",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Project engagement tracking with comprehensive workflow management**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis endpoint delivers complete project engagement management including:\n- Client engagement tracking with date-based filtering\n- Multi-level staff assignment management (partner and manager roles)\n- Project status workflow tracking and reporting\n- Template-driven engagement naming and standardization\n- Date range analysis for project timeline management\n\n**Project Management Capabilities:**\n- Start and end date tracking for project lifecycles\n- Status-based workflow management (DRAFT, SENT, EXECUTED, etc.)\n- Staff assignment tracking at partner and manager levels\n- Client relationship management for engagement context\n\n**Workflow Features:**\n- Template-based engagement creation for consistency\n- Status progression tracking for project milestones\n- Staff allocation and responsibility assignment\n- Client-specific engagement history and analysis\n\n**Business Intelligence:**\n- Engagement duration analysis and reporting\n- Staff utilization and assignment tracking\n- Client engagement patterns and history\n- Project status distribution and workflow analysis\n\n**Filtering:** this operation accepts only `pageSize` and `page`, and any other body\nproperty is rejected with 400. To filter or sort, use `POST /gql/v1/engagements/search`.\n\nRows are ordered by `name` ascending, then `createdAt` descending. The response holds the\nrows in `engagements` and the total number of engagements in `total.aggregate.count`.\n",
        "operationId": "getEngagements",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved engagement records",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EngagementListResponse"
                },
                "examples": {
                  "successful_response": {
                    "summary": "One engagement row",
                    "value": {
                      "engagements": [
                        {
                          "id": 85,
                          "name": "2026 Test 999408",
                          "status": "EXECUTED",
                          "isActive": true,
                          "endDt": null,
                          "startDt": null,
                          "fiscalYear": 2026,
                          "engagementNameTemplate": "2026 Test 999408",
                          "createdAt": "2026-06-08T16:40:09.096612+00:00",
                          "sentAt": "2026-06-08T16:45:00.414069+00:00",
                          "executedAt": "2026-06-08T16:46:48.196882+00:00",
                          "isStartOnAcceptance": true,
                          "updatedAt": "2026-06-08T16:46:48.199113+00:00",
                          "paymentInfoType": "OPTIONAL",
                          "canceledAt": null,
                          "mode": "AUTOMATIC",
                          "addressContactInfoId": null,
                          "originatingEngagementId": null,
                          "clientId": 92,
                          "jobs": [
                            {
                              "id": 1,
                              "jobId": 829,
                              "jobServiceTermId": null,
                              "engagementCustomJobServiceTermId": null,
                              "isActive": true,
                              "job": {
                                "id": 829,
                                "name": "Expatriate Tax Services",
                                "status": "OPEN",
                                "clientId": 92,
                                "pmsRef": "AIWYN_829",
                                "jobRef": null,
                                "sysRefs": {}
                              }
                            }
                          ],
                          "partnerStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "managerStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "createdByStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "lastUpdatedByStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "executedByStaff": null,
                          "renewedAt": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 158
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "Offset beyond the last engagement",
                    "value": {
                      "engagements": [],
                      "total": {
                        "aggregate": {
                          "count": 158
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request. Hasura rejects a body property the operation does not declare\n(for example a filter; use the search operation instead).\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "Unexpected variable clientId"
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "bad-request"
                    }
                  }
                },
                "examples": {
                  "unexpected_variable": {
                    "summary": "Filter sent to the list operation",
                    "value": {
                      "code": "bad-request",
                      "error": "Unexpected variable clientId"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid authentication token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_auth": {
                    "summary": "Missing authentication header",
                    "value": {
                      "error": "Authorization header is required",
                      "code": "MISSING_AUTH_HEADER"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/engagements/search": {
      "post": {
        "tags": [
          "Engagement"
        ],
        "summary": "Search engagements",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Search Engagements with Dynamic Filters**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis endpoint allows you to search engagements using dynamic filters, enabling flexible querying based on various criteria.\n\nThe response holds the matching rows in `engagements` (the same row shape as the list\noperation) and the number of engagements matching `where` in `total.aggregate.count`.\n\n**Features:**\n- Supports multiple filter conditions\n- Pagination for large result sets\n- Sorting options for results\n",
        "operationId": "searchEngagementsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 1
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "name": {
                                "_ilike": "%review%"
                              }
                            },
                            {
                              "engagementNameTemplate": {
                                "_ilike": "%tax%"
                              }
                            }
                          ]
                        },
                        {
                          "status": {
                            "_in": [
                              "SENT",
                              "EXECUTED"
                            ]
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "partnerStaffId": {
                            "_in": [
                              5,
                              6,
                              7,
                              8
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications",
                    "example": [
                      {
                        "name": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              },
              "examples": {
                "default_search": {
                  "summary": "Default search with filtering",
                  "value": {
                    "pageSize": 1,
                    "where": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "name": {
                                "_ilike": "%review%"
                              }
                            },
                            {
                              "engagementNameTemplate": {
                                "_ilike": "%tax%"
                              }
                            }
                          ]
                        },
                        {
                          "status": {
                            "_in": [
                              "SENT",
                              "EXECUTED"
                            ]
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "partnerStaffId": {
                            "_in": [
                              5,
                              6,
                              7,
                              8
                            ]
                          }
                        }
                      ]
                    },
                    "orderBy": [
                      {
                        "name": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Engagements retrieved successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EngagementListResponse"
                },
                "examples": {
                  "matching_engagements": {
                    "summary": "Engagements matching the filter, with the filtered total",
                    "value": {
                      "engagements": [
                        {
                          "id": 85,
                          "name": "2026 Test 999408",
                          "status": "EXECUTED",
                          "isActive": true,
                          "endDt": null,
                          "startDt": null,
                          "fiscalYear": 2026,
                          "engagementNameTemplate": "2026 Test 999408",
                          "createdAt": "2026-06-08T16:40:09.096612+00:00",
                          "sentAt": "2026-06-08T16:45:00.414069+00:00",
                          "executedAt": "2026-06-08T16:46:48.196882+00:00",
                          "isStartOnAcceptance": true,
                          "updatedAt": "2026-06-08T16:46:48.199113+00:00",
                          "paymentInfoType": "OPTIONAL",
                          "canceledAt": null,
                          "mode": "AUTOMATIC",
                          "addressContactInfoId": null,
                          "originatingEngagementId": null,
                          "clientId": 92,
                          "jobs": [],
                          "partnerStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "managerStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "createdByStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "lastUpdatedByStaff": {
                            "id": 18,
                            "firstName": "Robert",
                            "lastName": "Johnson",
                            "fullName": "Robert Johnson",
                            "pmsRef": "AIWYN_18",
                            "email": "r.johnson@company.com",
                            "createdAt": "2026-06-08T16:26:36.875604+00:00"
                          },
                          "executedByStaff": null,
                          "renewedAt": null
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Invalid input parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error - An unexpected error occurred.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/engagement/{id}": {
      "get": {
        "tags": [
          "Engagement"
        ],
        "summary": "Get engagement by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Retrieve a specific engagement by its unique identifier**\n\nThe engagement is returned in an `engagement` array that holds at most one row, with the\nsame row shape as the engagement list and search operations: engagement dates and\nstatuses, the linked projects (`jobs`) and the partner, manager, creator, last updater\nand executor staff.\n\nAn id that matches no active engagement returns 200 with `\"engagement\": []`; this\noperation never returns 404. A non-numeric id returns 400.\n\n**Response Example:**\n```json\n{\n  \"engagement\": [\n    {\n      \"id\": 85,\n      \"name\": \"2026 Test 999408\",\n      \"status\": \"EXECUTED\",\n      \"isActive\": true,\n      \"endDt\": null,\n      \"startDt\": null,\n      \"fiscalYear\": 2026,\n      \"engagementNameTemplate\": \"2026 Test 999408\",\n      \"createdAt\": \"2026-06-08T16:40:09.096612+00:00\",\n      \"sentAt\": \"2026-06-08T16:45:00.414069+00:00\",\n      \"executedAt\": \"2026-06-08T16:46:48.196882+00:00\",\n      \"isStartOnAcceptance\": true,\n      \"updatedAt\": \"2026-06-08T16:46:48.199113+00:00\",\n      \"paymentInfoType\": \"OPTIONAL\",\n      \"canceledAt\": null,\n      \"mode\": \"AUTOMATIC\",\n      \"addressContactInfoId\": null,\n      \"originatingEngagementId\": null,\n      \"clientId\": 92,\n      \"jobs\": [\n        {\n          \"id\": 1,\n          \"jobId\": 829,\n          \"jobServiceTermId\": null,\n          \"engagementCustomJobServiceTermId\": null,\n          \"isActive\": true,\n          \"job\": {\n            \"id\": 829,\n            \"name\": \"Expatriate Tax Services\",\n            \"status\": \"OPEN\",\n            \"clientId\": 92,\n            \"pmsRef\": \"AIWYN_829\",\n            \"jobRef\": null,\n            \"sysRefs\": {}\n          }\n        }\n      ],\n      \"partnerStaff\": {\n        \"id\": 18,\n        \"firstName\": \"Robert\",\n        \"lastName\": \"Johnson\",\n        \"fullName\": \"Robert Johnson\",\n        \"pmsRef\": \"AIWYN_18\",\n        \"email\": \"r.johnson@company.com\",\n        \"createdAt\": \"2026-06-08T16:26:36.875604+00:00\"\n      },\n      \"managerStaff\": { \"id\": 18, \"firstName\": \"Robert\", \"lastName\": \"Johnson\", \"fullName\": \"Robert Johnson\", \"pmsRef\": \"AIWYN_18\", \"email\": \"r.johnson@company.com\", \"createdAt\": \"2026-06-08T16:26:36.875604+00:00\" },\n      \"createdByStaff\": { \"id\": 18, \"firstName\": \"Robert\", \"lastName\": \"Johnson\", \"fullName\": \"Robert Johnson\", \"pmsRef\": \"AIWYN_18\", \"email\": \"r.johnson@company.com\", \"createdAt\": \"2026-06-08T16:26:36.875604+00:00\" },\n      \"lastUpdatedByStaff\": { \"id\": 18, \"firstName\": \"Robert\", \"lastName\": \"Johnson\", \"fullName\": \"Robert Johnson\", \"pmsRef\": \"AIWYN_18\", \"email\": \"r.johnson@company.com\", \"createdAt\": \"2026-06-08T16:26:36.875604+00:00\" },\n      \"executedByStaff\": null,\n      \"renewedAt\": null\n    }\n  ]\n}\n```\n",
        "operationId": "getEngagementById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the engagement",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 85
          }
        ],
        "responses": {
          "200": {
            "description": "Engagement lookup completed. `engagement` holds the engagement, or is empty when no\nactive engagement has this id.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "engagement"
                  ],
                  "properties": {
                    "engagement": {
                      "type": "array",
                      "maxItems": 1,
                      "description": "The engagement, or an empty array when the id matches no active engagement",
                      "items": {
                        "$ref": "#/components/schemas/Engagement"
                      }
                    }
                  }
                },
                "examples": {
                  "not_found": {
                    "summary": "No engagement with this id",
                    "value": {
                      "engagement": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "code"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "invalid input syntax for type integer: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "data-exception"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this engagement"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/engagements/{engagementId}": {
      "patch": {
        "tags": [
          "Engagement"
        ],
        "summary": "Update an existing engagement",
        "description": "> 🔐 **Required role:** `ENG_C`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Update an existing engagement by ID**\n\nPartially updates an engagement. Only the fields included in the request body\nare modified — omitted fields are left unchanged. At least one field must be\nprovided.\n\n**Updatable Fields:**\n- Core engagement data (client, fiscal year, partner/manager staff, contacts,\n  start/end dates, billing contact, CC staff, name template)\n- Engagement letter template and document template\n- Additional clients assigned to the engagement (full replace when provided)\n- Linked jobs/projects (full replace when provided)\n\n**Validation:**\n- The engagement must exist (404 if not found)\n- The engagement must be in `DRAFT` or `UNDER_REVISION` status (400 otherwise)\n- All provided IDs (additional client IDs, job IDs, etc.) must reference valid records\n- At least one field must be provided (400 if request body is empty)\n\n**Replace behavior:** When `additionalClientIds` or `jobIds` is provided, it fully replaces\nthe existing associations — it is not additive. When `jobIds` is provided without\n`additionalClientIds`, the existing additional clients are preserved.\n\n**Note:** Nullable fields (e.g. `secondaryContactId`, `endDate`) cannot be\nexplicitly cleared to null via this endpoint — omitting them leaves the\nexisting value unchanged.\n\n**Response Example:**\n```json\n{\n  \"id\": 12345\n}\n```\n",
        "operationId": "updateEngagement",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "engagementId",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the engagement to update",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "example": 12345
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "fiscalYear": 2025,
                "partnerStaffId": 456,
                "additionalClientIds": [
                  789,
                  790
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "clientId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the primary client for this engagement",
                    "example": 789
                  },
                  "fiscalYear": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int32",
                    "description": "Fiscal year of the engagement",
                    "example": 2025
                  },
                  "partnerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the partner staff member assigned to the engagement",
                    "example": 456
                  },
                  "managerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the manager staff member assigned to the engagement",
                    "example": 457
                  },
                  "primaryContactId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the primary contact for this engagement",
                    "example": 101
                  },
                  "secondaryContactId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the secondary contact for this engagement",
                    "example": 102
                  },
                  "startDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Engagement start date (YYYY-MM-DD)",
                    "example": "2025-01-01"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Engagement end date (YYYY-MM-DD)",
                    "example": "2025-12-31"
                  },
                  "billingContactId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the billing contact for this engagement",
                    "example": 103
                  },
                  "ccStaffIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "description": "IDs of staff members to CC on engagement communications",
                    "example": [
                      458,
                      459
                    ]
                  },
                  "engagementLetterTemplateId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the engagement letter template to use",
                    "example": 55
                  },
                  "documentTemplateId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the document template to use",
                    "example": 66
                  },
                  "engagementNameTemplate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Template string used to generate the engagement name",
                    "example": "{clientName} {fiscalYear} Audit"
                  },
                  "additionalClientIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "description": "IDs of additional clients to associate with this engagement.\nWhen provided, **replaces** all existing additional client associations.\n",
                    "example": [
                      790,
                      791
                    ]
                  },
                  "jobIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "description": "IDs of jobs (projects) to link to this engagement.\nWhen provided, **replaces** all existing job links.\nIf `additionalClientIds` is omitted when `jobIds` is provided, existing additional\nclients are preserved.\n",
                    "example": [
                      101,
                      102
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Engagement updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int64",
                      "description": "ID of the updated engagement",
                      "example": 12345
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — no update fields provided, one or more IDs are invalid, or the engagement's status does not allow updates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "message",
                    "extensions"
                  ],
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "Invalid additional client IDs: 999999, 999998"
                    },
                    "extensions": {
                      "type": "object",
                      "required": [
                        "code",
                        "details"
                      ],
                      "properties": {
                        "code": {
                          "type": "integer",
                          "description": "HTTP status code",
                          "example": 400
                        },
                        "details": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Additional error context. Null for these errors."
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "no_fields": {
                    "summary": "No update fields provided",
                    "value": {
                      "message": "No update fields provided",
                      "extensions": {
                        "code": 400,
                        "details": null
                      }
                    }
                  },
                  "invalid_clients": {
                    "summary": "Unknown additional client",
                    "value": {
                      "message": "Invalid additional client IDs: 999999, 999998",
                      "extensions": {
                        "code": 400,
                        "details": null
                      }
                    }
                  },
                  "invalid_jobs": {
                    "summary": "Unknown job",
                    "value": {
                      "message": "Invalid job IDs: 999999",
                      "extensions": {
                        "code": 400,
                        "details": null
                      }
                    }
                  },
                  "status_locked": {
                    "summary": "Engagement status does not allow updates",
                    "value": {
                      "message": "Engagement cannot be updated in status: EXECUTED",
                      "extensions": {
                        "code": 400,
                        "details": null
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized — invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden — insufficient permissions (requires ROLE_ENG_C)"
          },
          "404": {
            "description": "Engagement not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "message",
                    "extensions"
                  ],
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "Engagement not found: 12345"
                    },
                    "extensions": {
                      "type": "object",
                      "required": [
                        "code",
                        "details"
                      ],
                      "properties": {
                        "code": {
                          "type": "integer",
                          "description": "HTTP status code",
                          "example": 404
                        },
                        "details": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Additional error context. Null for these errors."
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "not_found": {
                    "summary": "No engagement with this id",
                    "value": {
                      "message": "Engagement not found: 12345",
                      "extensions": {
                        "code": 404,
                        "details": null
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/engagements/create": {
      "post": {
        "tags": [
          "Engagement"
        ],
        "summary": "Create a single engagement",
        "description": "> 🔐 **Required role:** `ENG_C`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Create a single engagement letter**\n\nCreates an engagement letter for a specific client. The engagement letter\nwill be associated with the specified client, fiscal year, and assigned staff.\n\n**Required fields:**\n- `clientId` — the client for whom the engagement is being created\n- `fiscalYear` — the fiscal year of the engagement\n- `partnerStaffId` — the partner staff member assigned to the engagement\n- `managerStaffId` — the manager staff member assigned to the engagement\n- `primaryContactId` — the primary client contact\n- `engagementLetterTemplateId` or `documentTemplateId` — the template to use. At least one\n  of the two must be provided; a request with neither is rejected.\n\n**Optional fields:**\n- `engagementNameTemplate` — override the firm's default naming template\n- `startDate` / `endDate` — engagement date range\n- `billingContactId` — contact responsible for billing\n- `secondaryContactId` — secondary client contact\n- `ccStaffIds` — additional staff members to CC on the engagement\n- `additionalClientIds` — additional clients to associate with the engagement\n- `jobIds` — jobs/projects to link to the engagement\n- `additionalDocuments` — extra documents to attach to the engagement, each requiring a `documentTemplateId` and a `documentType` (`CONSENT` or `ADD_ON`)\n",
        "operationId": "createEngagementLetter",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "clientId",
                  "fiscalYear",
                  "partnerStaffId",
                  "managerStaffId",
                  "primaryContactId"
                ],
                "anyOf": [
                  {
                    "required": [
                      "engagementLetterTemplateId"
                    ]
                  },
                  {
                    "required": [
                      "documentTemplateId"
                    ]
                  }
                ],
                "properties": {
                  "clientId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Unique identifier of the client for this engagement",
                    "example": 420
                  },
                  "fiscalYear": {
                    "type": "integer",
                    "description": "Fiscal year of the engagement",
                    "example": 2024
                  },
                  "partnerStaffId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Unique identifier of the partner staff member",
                    "example": 53
                  },
                  "managerStaffId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Unique identifier of the manager staff member",
                    "example": 15
                  },
                  "primaryContactId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Unique identifier of the primary client contact",
                    "example": 101
                  },
                  "secondaryContactId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Unique identifier of the secondary client contact",
                    "example": 102
                  },
                  "billingContactId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Unique identifier of the billing contact",
                    "example": 103
                  },
                  "engagementLetterTemplateId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Unique identifier of the engagement letter template to use. Required unless\n`documentTemplateId` is provided.\n",
                    "example": 5
                  },
                  "documentTemplateId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Unique identifier of the document template to use. Required unless\n`engagementLetterTemplateId` is provided.\n",
                    "example": 7
                  },
                  "engagementNameTemplate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Template string used to generate the engagement name. Overrides the firm's default naming template.\n",
                    "example": "{{fiscal_year.year}} {{letter_template.name}} {{client.number}}"
                  },
                  "startDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Engagement start date (YYYY-MM-DD)",
                    "example": "2024-01-01"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Engagement end date (YYYY-MM-DD)",
                    "example": "2024-12-31"
                  },
                  "ccStaffIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "List of staff member IDs to CC on the engagement",
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "example": [
                      20,
                      21
                    ]
                  },
                  "additionalClientIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "IDs of additional clients to associate with the engagement",
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "example": [
                      790,
                      791
                    ]
                  },
                  "jobIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "IDs of jobs (projects) to link to this engagement",
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "example": [
                      101,
                      102
                    ]
                  },
                  "additionalDocuments": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "description": "Extra documents to attach to the engagement",
                    "items": {
                      "type": "object",
                      "required": [
                        "documentTemplateId",
                        "documentType"
                      ],
                      "properties": {
                        "documentTemplateId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Unique identifier of the document template",
                          "example": 12
                        },
                        "documentType": {
                          "type": "string",
                          "enum": [
                            "CONSENT",
                            "ADD_ON"
                          ],
                          "description": "Type of the document. Any other value is rejected with 400\n`Invalid document type '<value>'. Valid values: CONSENT, ADD_ON`.\n",
                          "example": "CONSENT"
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "minimal": {
                  "summary": "Minimal required fields",
                  "value": {
                    "clientId": 420,
                    "fiscalYear": 2024,
                    "partnerStaffId": 53,
                    "managerStaffId": 15,
                    "primaryContactId": 101,
                    "engagementLetterTemplateId": 5
                  }
                },
                "full": {
                  "summary": "All fields provided",
                  "value": {
                    "clientId": 420,
                    "fiscalYear": 2024,
                    "partnerStaffId": 53,
                    "managerStaffId": 15,
                    "primaryContactId": 101,
                    "secondaryContactId": 102,
                    "billingContactId": 103,
                    "engagementLetterTemplateId": 5,
                    "documentTemplateId": 7,
                    "engagementNameTemplate": "{{fiscal_year.year}} {{letter_template.name}} {{client.number}}",
                    "startDate": "2024-01-01",
                    "endDate": "2024-12-31",
                    "ccStaffIds": [
                      20,
                      21
                    ],
                    "additionalClientIds": [
                      790,
                      791
                    ],
                    "jobIds": [
                      101,
                      102
                    ],
                    "additionalDocuments": [
                      {
                        "documentTemplateId": 12,
                        "documentType": "CONSENT"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Engagement letter created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Unique identifier of the newly created engagement",
                      "example": 34567
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Engagement created",
                    "value": {
                      "id": 34567
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data. A missing required field (`clientId`, `fiscalYear`, `partnerStaffId`,\n`managerStaffId`, `primaryContactId`, or `documentTemplateId` on an additional document)\nreturns `{\"message\": \"Validation failed\", \"extensions\": {\"code\": 400, \"details\": {\"reason\":\n\"VALIDATION_FAILED\", \"fieldErrors\": [{\"field\": \"clientId\", \"message\": \"clientId is required\"}]}}}`.\n\nAlso returned when the request names neither a document template nor an engagement letter\ntemplate: `{\"message\": \"Sorry, Engagement letter must have a Document Template or Engagement\nLetter Template specified.\", \"extensions\": {\"code\": 400, \"details\": null}}`.\n"
          },
          "401": {
            "description": "Unauthorized - invalid or missing authentication token."
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires ROLE_ENG_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/engagements/batch/create": {
      "post": {
        "tags": [
          "Engagement"
        ],
        "summary": "Create a batch of engagements",
        "description": "> 🔐 **Required role:** `ENG_C`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Create a batch of engagement letters asynchronously**\n\nSubmits a batch of engagement letter creation requests. The batch is processed\nasynchronously — use the returned batch ID with the\n`GET /api/v1/engagements/batch/{batchId}/status` endpoint to poll for completion\nand retrieve the IDs of the created engagements.\n\n**Batch-level options:**\n- `name` — optional label for the batch\n- `projectTemplateId` — apply a single project template to every engagement in the batch\n- `includeAdditionalClients` — include additional clients when creating engagements\n- `batchEngagements` — array of individual engagement records (required)\n\n**Constraint:** You may provide either `projectTemplateId` (top-level) **or** `projectIds`\non individual engagements — not both.\n",
        "operationId": "createBatchEngagementLetters",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "batchEngagements"
                ],
                "properties": {
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Optional label for the batch",
                    "example": "2024 Annual Batch"
                  },
                  "projectTemplateId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Project template ID to apply to every engagement in the batch. Cannot be combined with per-engagement `projectIds`.\n",
                    "example": 10
                  },
                  "includeAdditionalClients": {
                    "type": "boolean",
                    "default": false,
                    "description": "Whether to include additional clients when creating engagements",
                    "example": false
                  },
                  "batchEngagements": {
                    "type": "array",
                    "description": "List of engagement records to create",
                    "items": {
                      "type": "object",
                      "required": [
                        "clientId",
                        "fiscalYear",
                        "primaryContactId"
                      ],
                      "properties": {
                        "clientId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Unique identifier of the client",
                          "example": 420
                        },
                        "fiscalYear": {
                          "type": "integer",
                          "description": "Fiscal year of the engagement",
                          "example": 2024
                        },
                        "primaryContactId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Unique identifier of the primary client contact",
                          "example": 101
                        },
                        "partnerStaffId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the partner staff member",
                          "example": 53
                        },
                        "managerStaffId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the manager staff member",
                          "example": 15
                        },
                        "secondaryContactId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the secondary client contact",
                          "example": 102
                        },
                        "billingContactId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the billing contact",
                          "example": 103
                        },
                        "engagementLetterTemplateId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the engagement letter template to use",
                          "example": 5
                        },
                        "documentTemplateId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Unique identifier of the document template to use",
                          "example": 7
                        },
                        "engagementNameTemplate": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Template string used to generate the engagement name. Overrides the firm's default naming template.\n",
                          "example": "{{fiscal_year.year}} {{letter_template.name}} {{client.number}}"
                        },
                        "startDate": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date",
                          "description": "Engagement start date (YYYY-MM-DD)",
                          "example": "2024-01-01"
                        },
                        "endDate": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date",
                          "description": "Engagement end date (YYYY-MM-DD)",
                          "example": "2024-12-31"
                        },
                        "ccStaffIds": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "description": "List of staff member IDs to CC on the engagement",
                          "items": {
                            "type": "integer",
                            "format": "int64"
                          },
                          "example": [
                            20,
                            21
                          ]
                        },
                        "projectIds": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "description": "List of project IDs to associate with this engagement. Cannot be used when a top-level `projectTemplateId` is provided.\n",
                          "items": {
                            "type": "integer",
                            "format": "int64"
                          },
                          "example": [
                            301,
                            302
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "minimal": {
                  "summary": "Two engagements, minimal fields",
                  "value": {
                    "batchEngagements": [
                      {
                        "clientId": 420,
                        "fiscalYear": 2024,
                        "partnerStaffId": 53,
                        "managerStaffId": 15,
                        "primaryContactId": 101
                      },
                      {
                        "clientId": 421,
                        "fiscalYear": 2024,
                        "partnerStaffId": 53,
                        "managerStaffId": 15,
                        "primaryContactId": 201
                      }
                    ]
                  }
                },
                "with_project_template": {
                  "summary": "Batch with a shared project template",
                  "value": {
                    "name": "2024 Annual Batch",
                    "projectTemplateId": 10,
                    "batchEngagements": [
                      {
                        "clientId": 420,
                        "fiscalYear": 2024,
                        "partnerStaffId": 53,
                        "managerStaffId": 15,
                        "primaryContactId": 101
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch created successfully — process is asynchronous",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Unique identifier of the created engagement batch",
                      "example": 9001
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Batch accepted",
                    "value": {
                      "id": 9001
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data, for example:\n- both `projectTemplateId` and per-engagement `projectIds` were provided\n- an entry is missing `clientId`, `fiscalYear` or `primaryContactId` (`\"reason\": \"VALIDATION_FAILED\"`\n  with `fieldErrors` such as `batchEngagements[0].clientId`)\n- entries name clients that do not exist: `{\"message\": \"Invalid client IDs: 999999\",\n  \"extensions\": {\"code\": 400, \"details\": null}}`, listing every unknown id\n- an entry omits `partnerStaffId` or `managerStaffId` and the client has no default partner or\n  manager: `{\"message\": \"Client 1001 has no default partner. Set partnerStaffId on the batch record.\",\n  \"extensions\": {\"code\": 400, \"details\": null}}` (or the manager equivalent)\n"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires ROLE_ENG_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/engagements/batch/{batchId}/status": {
      "get": {
        "tags": [
          "Engagement"
        ],
        "summary": "Get engagement batch status",
        "description": "> 🔐 **Required role:** `ENG_C`\n>\n> 📖 **Data dictionary:** [Engagement](/reference/data-dictionary/engagement)\n\n**Retrieve the status of an engagement batch**\n\nReturns the current processing status of a previously submitted engagement batch,\nalong with the IDs of any engagements that have been created so far.\n\nUse this endpoint to poll for completion after calling\n`POST /api/v1/engagements/batch/create`.\n\n**Batch statuses:**\n- `DRAFT` — batch has been recorded but processing has not started\n- `CREATING` — engagements are actively being created\n- `CREATED` — all engagements in the batch have been created successfully\n- `CANCELED` — the batch was canceled before completion\n",
        "operationId": "getEngagementBatchStatus",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "batchId",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the engagement batch",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "example": 9001
          }
        ],
        "responses": {
          "200": {
            "description": "Batch status retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batchId": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Unique identifier of the engagement batch",
                      "example": 9001
                    },
                    "status": {
                      "type": "string",
                      "description": "Current processing status of the batch",
                      "enum": [
                        "DRAFT",
                        "CREATING",
                        "CREATED",
                        "CANCELED"
                      ],
                      "example": "CREATED"
                    },
                    "engagementIds": {
                      "type": "array",
                      "description": "IDs of engagements created by this batch",
                      "items": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "example": [
                        34567,
                        34568
                      ]
                    }
                  }
                },
                "examples": {
                  "in_progress": {
                    "summary": "Batch still creating",
                    "value": {
                      "batchId": 9001,
                      "status": "CREATING",
                      "engagementIds": [
                        34567
                      ]
                    }
                  },
                  "completed": {
                    "summary": "Batch fully created",
                    "value": {
                      "batchId": 9001,
                      "status": "CREATED",
                      "engagementIds": [
                        34567,
                        34568
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires ROLE_ENG_C)"
          },
          "404": {
            "description": "Batch not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/engagement_documents/by_engagement/{engagementId}": {
      "get": {
        "tags": [
          "Engagement"
        ],
        "summary": "Get engagement documents by engagement ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Engagement document](/reference/data-dictionary/engagement-document)\n\n**Retrieve documents associated with a specific engagement**\n\nReturns all engagement documents linked to the given engagement ID, including\nthe document type name for each record.\n",
        "operationId": "getEngagementDocumentsByEngagementId",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "engagementId",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the engagement",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 34567
          }
        ],
        "responses": {
          "200": {
            "description": "Engagement documents retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "engagementDocuments"
                  ],
                  "properties": {
                    "engagementDocuments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "fileId",
                          "engagementId",
                          "engagementDocumentTypeId",
                          "is_active",
                          "clientFacing",
                          "blocksExecution",
                          "signatureRequirementType",
                          "createdAt",
                          "updatedAt",
                          "affirmativeStatus",
                          "documentType"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "Unique engagement document identifier",
                            "example": 101
                          },
                          "fileId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated file identifier. Null when no file is attached.",
                            "example": 5001
                          },
                          "engagementId": {
                            "type": "integer",
                            "description": "Associated engagement identifier",
                            "example": 34567
                          },
                          "engagementDocumentTypeId": {
                            "type": "integer",
                            "description": "Document type identifier: 1 Engagement Letter, 2 Supplemental Document, 3 Combined Document,\n4 Consent Document, 5 Agreement Document, 6 Add-On Document\n",
                            "example": 4
                          },
                          "is_active": {
                            "type": "boolean",
                            "description": "Whether this document record is active",
                            "example": true
                          },
                          "clientFacing": {
                            "type": "boolean",
                            "description": "Whether the document is visible to the client",
                            "example": true
                          },
                          "blocksExecution": {
                            "type": "boolean",
                            "description": "Whether this document must be signed before the engagement executes",
                            "example": true
                          },
                          "signatureRequirementType": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Signature requirement mode",
                            "enum": [
                              "ALL_SIGNATURES_REQUIRED",
                              "ONE_SIGNATURE_REQUIRED",
                              null
                            ],
                            "example": "ALL_SIGNATURES_REQUIRED"
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Record creation timestamp",
                            "example": "2024-01-15T10:00:00Z"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Record last updated timestamp",
                            "example": "2024-03-20T14:30:00Z"
                          },
                          "affirmativeStatus": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Consent acceptance status of a consent or add-on document.\nNEGATIVE = one or more negative responses.\nAFFIRMATIVE = all signers responded positively.\nINDETERMINATE = at least one positive response but not all signers have responded yet.\nEMPTY = signers are assigned but none has responded yet.\nNull for other document types (for example the engagement letter) and for a\nconsent or add-on document with no signers assigned.\nThese rules don't change with signatureRequirementType: for a ONE_SIGNATURE_REQUIRED\ndocument, any decline makes it NEGATIVE and an agreement while other signers haven't\nanswered makes it INDETERMINATE. Use the Engagement CONSENT_RECORDED webhook for the\noutcome of a one-signature consent.\n",
                            "enum": [
                              "NEGATIVE",
                              "AFFIRMATIVE",
                              "INDETERMINATE",
                              "EMPTY",
                              null
                            ],
                            "example": "AFFIRMATIVE"
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff member who created the document (staff id).",
                            "example": 102
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Staff member who last updated the document (staff id).",
                            "example": 102
                          },
                          "manuallyUploadedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the document was uploaded by hand rather than generated from a template.\nNull for generated documents.\n",
                            "example": null
                          },
                          "pages": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Number of pages in the document.",
                            "example": 4
                          },
                          "totalExpectedInitials": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "How many initials the document expects in total, across all signatories.",
                            "example": 2
                          },
                          "totalExpectedSignatures": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "How many signatures the document expects in total.",
                            "example": 1
                          },
                          "hasAppendedCertificateOfCompletion": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether a certificate of completion has been appended to the document.",
                            "example": false
                          },
                          "documentType": {
                            "type": "object",
                            "description": "The document type associated with this record",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "description": "Document type identifier",
                                "example": 4
                              },
                              "name": {
                                "type": "string",
                                "description": "Document type name",
                                "example": "Consent Document"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Two engagement documents for engagement 34567",
                    "value": {
                      "engagementDocuments": [
                        {
                          "id": 101,
                          "fileId": 5001,
                          "engagementId": 34567,
                          "engagementDocumentTypeId": 4,
                          "is_active": true,
                          "clientFacing": true,
                          "blocksExecution": true,
                          "signatureRequirementType": "ALL_SIGNATURES_REQUIRED",
                          "createdAt": "2024-01-15T10:00:00Z",
                          "updatedAt": "2024-03-20T14:30:00Z",
                          "affirmativeStatus": "AFFIRMATIVE",
                          "documentType": {
                            "id": 4,
                            "name": "Consent Document"
                          }
                        },
                        {
                          "id": 102,
                          "fileId": 5002,
                          "engagementId": 34567,
                          "engagementDocumentTypeId": 6,
                          "is_active": true,
                          "clientFacing": true,
                          "blocksExecution": false,
                          "signatureRequirementType": "ONE_SIGNATURE_REQUIRED",
                          "createdAt": "2024-02-01T09:00:00Z",
                          "updatedAt": "2024-02-01T09:00:00Z",
                          "affirmativeStatus": "EMPTY",
                          "documentType": {
                            "id": 6,
                            "name": "Add-On Document"
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/staff": {
      "post": {
        "tags": [
          "Staff"
        ],
        "summary": "List staff",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Staff directory and human resource management with organizational structure**\n\n**Pagination (v1 — limit/offset, see [Pagination](/reference/pagination)):** `pageSize` is a limit (records to return).\n`page` is an offset (records to skip), not a page index. Hasura maps these as\n`limit: $pageSize` and `offset: $page`. When `page` is at or beyond\n`total.aggregate.count`, the result array is empty.\n\nThis endpoint returns the staff directory, ordered by last name, first name, then id\ndescending. It accepts only `pageSize` and `page`; any other body property is rejected\nwith 400 `Unexpected variable <name>`.\n\n**To filter or sort** (by active status, department, name, role, …), use\n`POST /gql/v1/staff/search` with a `where` clause and `orderBy`.\n\n**Business Applications:**\n- Employee directory and contact management\n- HR reporting and organizational analysis\n- Department staff allocation and planning\n- Employee onboarding and management workflows\n- Integration with external HR and payroll systems\n\n**Directory Features:**\n- Complete contact information management\n- Department, service line, role, permission, and supervisor relationship tracking\n- Staff reference system for external integration\n- Employee status and lifecycle management\n",
        "operationId": "getStaff",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 50
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 50,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved staff records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "staff",
                    "total"
                  ],
                  "properties": {
                    "staff": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/StaffDirectoryRecord"
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of staff records matching criteria",
                              "example": 138
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Staff directory with department and type information",
                    "value": {
                      "staff": [
                        {
                          "id": 202,
                          "pmsRef": "2254",
                          "staffRef": "HAB",
                          "firstName": "Holley",
                          "lastName": "Abbott",
                          "email": "ena.toy@hotmail.com",
                          "active": true,
                          "deptId": 8,
                          "jobTitle": null,
                          "jobTitleId": null,
                          "type": null,
                          "officeId": 2,
                          "department": {
                            "id": 8,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "office": {
                            "id": 2,
                            "pmsRef": "NYC",
                            "name": "New York",
                            "city": "New York",
                            "stateProvince": "NY",
                            "country": "US"
                          },
                          "serviceLine": {
                            "id": 4,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "subServiceLine": {
                            "id": 12,
                            "pmsRef": "TAX-COMP",
                            "name": "Tax Compliance"
                          },
                          "wageType": {
                            "id": 1,
                            "pmsRef": "SAL",
                            "name": "Salary"
                          },
                          "employeeType": {
                            "id": 2,
                            "pmsRef": "FT",
                            "name": "Full Time"
                          },
                          "role": {
                            "id": 11,
                            "pmsRef": "MANAGER",
                            "display": "Manager",
                            "description": "Manager"
                          },
                          "permissionSet": {
                            "id": 3,
                            "name": "Standard Manager"
                          },
                          "staffSupervisor": {
                            "id": 53,
                            "pmsRef": "A53",
                            "staffRef": "AH",
                            "firstName": "Allen",
                            "lastName": "Hermiston",
                            "email": "allen.hermiston@company.com"
                          },
                          "rateCardBillingRates": [],
                          "staffManagerId": 53,
                          "updatedAt": "2026-09-21T18:30:00Z",
                          "createdAt": "2024-05-12T22:42:02.719873+00:00",
                          "fullName": "Holley Abbott",
                          "prefix": null,
                          "startDt": "2024-01-08T00:00:00",
                          "endDt": null,
                          "staffPartnerId": 53,
                          "staffPaId": null,
                          "orgId": 1,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "lastUpdatedByStaffId": 53,
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 138
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No staff found",
                    "value": {
                      "staff": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request. An out-of-range `pageSize` or a negative `page` is rejected before the\nquery runs, with only `error` (see [Errors](/reference/errors)). A body property other\nthan `pageSize`/`page` is rejected by the query with `code`, `error` and `path`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "invalid_page_size": {
                    "summary": "Invalid pageSize parameter",
                    "value": {
                      "error": "pageSize must be an integer from 1 to 1000"
                    }
                  },
                  "negative_page": {
                    "summary": "Negative page",
                    "value": {
                      "error": "page must be an integer of 0 or more"
                    }
                  },
                  "unexpected_variable": {
                    "summary": "Unsupported filter property",
                    "value": {
                      "code": "bad-request",
                      "error": "Unexpected variable isActive",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - insufficient permissions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "insufficient_permissions": {
                    "summary": "User lacks required role",
                    "value": {
                      "error": "Access denied. Missing Roles",
                      "code": "INSUFFICIENT_PERMISSIONS"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/staff/search": {
      "post": {
        "tags": [
          "Staff"
        ],
        "summary": "Search staff",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Advanced staff filtering with flexible `where` clauses and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nProvides flexible, enterprise-grade filtering for staff directory queries with boolean logic,\nrelationship traversal, and multi-field ordering.\n\nEach result includes service and sub-service lines, wage and employee types, `role`\n(formerly `staffType`), permission set, supervisor, and the record's `updatedAt` timestamp.\n\nKey capabilities include boolean operators (`_and`, `_or`, `_not`), text matching (`_ilike`),\ncomparison operators (`_gt`, `_gte`, `_lt`, `_lte`, `_eq`, `_neq`), array operators (`_in`, `_nin`),\nand nested/related filtering (e.g., by office or manager).\n",
        "operationId": "filterStaffDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "firstName": {
                            "_ilike": "%john%"
                          }
                        },
                        {
                          "lastName": {
                            "_ilike": "%doe%"
                          }
                        }
                      ]
                    },
                    {
                      "active": {
                        "_eq": true
                      }
                    },
                    {
                      "createdAt": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "deptId": {
                        "_in": [
                          1,
                          2,
                          3
                        ]
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "lastName": "asc"
                  },
                  {
                    "firstName": "asc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 50
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex staff filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "firstName": {
                                "_ilike": "%john%"
                              }
                            },
                            {
                              "lastName": {
                                "_ilike": "%doe%"
                              }
                            }
                          ]
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "deptId": {
                            "_in": [
                              1,
                              2,
                              3
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "description": "Dynamic ordering specifications with multiple fields",
                    "items": {
                      "type": "object"
                    },
                    "example": [
                      {
                        "lastName": "asc"
                      },
                      {
                        "firstName": "asc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered staff with dynamic ordering",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "staff",
                    "total"
                  ],
                  "properties": {
                    "staff": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/StaffDirectoryRecord"
                      }
                    },
                    "total": {
                      "type": "object",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of staff records matching criteria",
                              "example": 1
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "filtered_response": {
                    "summary": "Filtered staff with dynamic ordering",
                    "value": {
                      "staff": [
                        {
                          "id": 202,
                          "pmsRef": "2254",
                          "staffRef": "HAB",
                          "firstName": "Holley",
                          "lastName": "Abbott",
                          "email": "ena.toy@hotmail.com",
                          "active": true,
                          "deptId": 8,
                          "jobTitle": null,
                          "jobTitleId": null,
                          "type": null,
                          "officeId": 2,
                          "department": {
                            "id": 8,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "office": {
                            "id": 2,
                            "pmsRef": "NYC",
                            "name": "New York",
                            "city": "New York",
                            "stateProvince": "NY",
                            "country": "US"
                          },
                          "serviceLine": {
                            "id": 4,
                            "pmsRef": "TAX",
                            "name": "Tax"
                          },
                          "subServiceLine": {
                            "id": 12,
                            "pmsRef": "TAX-COMP",
                            "name": "Tax Compliance"
                          },
                          "wageType": {
                            "id": 1,
                            "pmsRef": "SAL",
                            "name": "Salary"
                          },
                          "employeeType": {
                            "id": 2,
                            "pmsRef": "FT",
                            "name": "Full Time"
                          },
                          "role": {
                            "id": 11,
                            "pmsRef": "MANAGER",
                            "display": "Manager",
                            "description": "Manager"
                          },
                          "permissionSet": {
                            "id": 3,
                            "name": "Standard Manager"
                          },
                          "staffSupervisor": {
                            "id": 53,
                            "pmsRef": "A53",
                            "staffRef": "AH",
                            "firstName": "Allen",
                            "lastName": "Hermiston",
                            "email": "allen.hermiston@company.com"
                          },
                          "rateCardBillingRates": [],
                          "staffManagerId": 53,
                          "updatedAt": "2026-09-21T18:30:00Z",
                          "createdAt": "2024-05-12T22:42:02.719873+00:00",
                          "fullName": "Holley Abbott",
                          "prefix": null,
                          "startDt": "2024-01-08T00:00:00",
                          "endDt": null,
                          "staffPartnerId": 53,
                          "staffPaId": null,
                          "orgId": 1,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "lastUpdatedByStaffId": 53,
                          "customFieldValues": {}
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 1
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No staff found matching criteria",
                    "value": {
                      "staff": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/staff/{id}": {
      "get": {
        "tags": [
          "Staff"
        ],
        "summary": "Get staff member by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n\nReturns a staff member's full profile:\n- Staff member ID and PMS reference\n- Personal information (first name, last name, email)\n- Active status indicator\n- Department and office assignments\n- Job title and role (when available)\n- Service line and sub-service line\n- Wage type and employee type\n- Permission set, manager, and supervisor assignments\n- Last-updated timestamp\n\n**Business Applications:**\n- Staff member lookup and verification\n- Organizational structure queries\n- Basic staff information retrieval\n- Department and office staff management\n\n**Response:** the record is wrapped in a `staff` key. An id that does not exist\nreturns 200 with `{\"staff\": null}` (not 404). A non-numeric id returns 400.\n\n**Response Example:**\n```json\n{\n  \"staff\": {\n    \"id\": 202,\n    \"pmsRef\": \"2254\",\n    \"firstName\": \"Holley\",\n    \"lastName\": \"Abbott\",\n    \"email\": \"ena.toy@hotmail.com\",\n    \"active\": true,\n    \"deptId\": 8,\n    \"jobTitle\": null,\n    \"type\": null,\n    \"officeId\": 2,\n    \"serviceLine\": { \"id\": 4, \"pmsRef\": \"TAX\", \"name\": \"Tax\" },\n    \"subServiceLine\": { \"id\": 12, \"pmsRef\": \"TAX-COMP\", \"name\": \"Tax Compliance\" },\n    \"wageType\": { \"id\": 1, \"pmsRef\": \"SAL\", \"name\": \"Salary\" },\n    \"employeeType\": { \"id\": 2, \"pmsRef\": \"FT\", \"name\": \"Full Time\" },\n    \"role\": {\n      \"id\": 11,\n      \"pmsRef\": \"MANAGER\",\n      \"display\": \"Manager\",\n      \"description\": \"Manager\"\n    },\n    \"permissionSet\": { \"id\": 3, \"name\": \"Standard Manager\" },\n    \"staffSupervisor\": {\n      \"id\": 53,\n      \"pmsRef\": \"A53\",\n      \"staffRef\": \"AH\",\n      \"firstName\": \"Allen\",\n      \"lastName\": \"Hermiston\",\n      \"email\": \"allen.hermiston@company.com\"\n    },\n    \"staffManagerId\": 53,\n    \"updatedAt\": \"2026-09-21T18:30:00Z\"\n  }\n}\n```\n",
        "operationId": "getStaffById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the staff member",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 123
          }
        ],
        "responses": {
          "200": {
            "description": "Staff member lookup result. `staff` is the directory record, or `null` when no\nstaff member has that id.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "staff"
                  ],
                  "properties": {
                    "staff": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/StaffDirectoryRecord"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "examples": {
                  "found": {
                    "summary": "Staff member found",
                    "value": {
                      "staff": {
                        "id": 202,
                        "pmsRef": "2254",
                        "staffRef": "HAB",
                        "firstName": "Holley",
                        "lastName": "Abbott",
                        "email": "ena.toy@hotmail.com",
                        "active": true,
                        "deptId": 8,
                        "jobTitle": null,
                        "jobTitleId": null,
                        "type": null,
                        "officeId": 2,
                        "department": {
                          "id": 8,
                          "pmsRef": "TAX",
                          "name": "Tax"
                        },
                        "office": {
                          "id": 2,
                          "pmsRef": "NYC",
                          "name": "New York",
                          "city": "New York",
                          "stateProvince": "NY",
                          "country": "US"
                        },
                        "serviceLine": {
                          "id": 4,
                          "pmsRef": "TAX",
                          "name": "Tax"
                        },
                        "subServiceLine": {
                          "id": 12,
                          "pmsRef": "TAX-COMP",
                          "name": "Tax Compliance"
                        },
                        "wageType": {
                          "id": 1,
                          "pmsRef": "SAL",
                          "name": "Salary"
                        },
                        "employeeType": {
                          "id": 2,
                          "pmsRef": "FT",
                          "name": "Full Time"
                        },
                        "role": {
                          "id": 11,
                          "pmsRef": "MANAGER",
                          "display": "Manager",
                          "description": "Manager"
                        },
                        "rateCardBillingRates": [],
                        "permissionSet": {
                          "id": 3,
                          "name": "Standard Manager"
                        },
                        "staffSupervisor": null,
                        "staffManagerId": 53,
                        "updatedAt": "2026-09-21T18:30:00Z",
                        "createdAt": "2024-05-12T22:42:02.719873+00:00",
                        "fullName": "Holley Abbott",
                        "prefix": null,
                        "startDt": "2024-01-08T00:00:00",
                        "endDt": null,
                        "staffPartnerId": 53,
                        "staffPaId": null,
                        "orgId": 1,
                        "isCreatedByAiwyn": false,
                        "isManagedByAiwyn": false,
                        "lastUpdatedByStaffId": 53,
                        "customFieldValues": {}
                      }
                    }
                  },
                  "not_found": {
                    "summary": "No staff member with this id",
                    "value": {
                      "staff": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "path": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this staff member"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/staff": {
      "post": {
        "tags": [
          "Staff"
        ],
        "summary": "Onboard a new staff member",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Create a new staff member, optionally assigning them to a rate card**\n\nCreates a staff record and, when `rateCardAssignment` is provided, atomically\ncreates the corresponding billing rate and average cost records in the same\ntransaction.\n\n**Required fields:**\n- `firstName` — staff member's first name\n- `lastName` — staff member's last name\n- `pmsRef` — practice management system reference\n- `ref` — unique staff reference code\n\n**Rate card assignment** (`rateCardAssignment`):\nWhen provided, the rate card must already exist. Each entry in `billingRates`\nrequires a valid `rateTypeId`. All three records (staff, billing rates, average\ncost) are created atomically — if any write fails the entire request is rolled back.\n- `rateCardId` — ID of an existing rate card (validated before any writes)\n- `billingRates` — one record per rate type; each requires a `rateTypeId`\n- `averageCost` — single average hourly cost for this staff member (optional)\n",
        "operationId": "onboardStaff",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "firstName",
                  "lastName",
                  "pmsRef",
                  "ref"
                ],
                "properties": {
                  "firstName": {
                    "type": "string",
                    "description": "Staff member's first name",
                    "example": "Jane"
                  },
                  "lastName": {
                    "type": "string",
                    "description": "Staff member's last name",
                    "example": "Doe"
                  },
                  "pmsRef": {
                    "type": "string",
                    "description": "Practice management system reference identifier",
                    "example": "EMP-1042"
                  },
                  "ref": {
                    "type": "string",
                    "description": "Unique staff reference code",
                    "example": "doe-j"
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "email",
                    "description": "Primary email address",
                    "example": "jane.doe@firm.com"
                  },
                  "jobTitle": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Job title (free-text)",
                    "example": "Senior Associate"
                  },
                  "jobTitleId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of a job title lookup record",
                    "example": 7
                  },
                  "departmentId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the department this staff member belongs to",
                    "example": 3
                  },
                  "officeId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the office this staff member is based in",
                    "example": 2
                  },
                  "orgId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the organization",
                    "example": 1
                  },
                  "serviceLineId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the service line",
                    "example": 4
                  },
                  "staffTypeId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the staff type (e.g. Partner, Manager, Associate)",
                    "example": 2
                  },
                  "partnerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the partner staff member assigned to this person",
                    "example": 50
                  },
                  "managerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the manager staff member",
                    "example": 30
                  },
                  "supervisorStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "ID of the supervisor staff member",
                    "example": null
                  },
                  "prefix": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Name prefix (e.g. Dr., Ms.)",
                    "example": "Ms."
                  },
                  "startDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Employment start date",
                    "example": "2024-01-15T00:00:00"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Employment end date",
                    "example": null
                  },
                  "active": {
                    "type": "boolean",
                    "default": true,
                    "description": "Whether the staff member is active",
                    "example": true
                  },
                  "rateCardAssignment": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Optional rate card assignment. When provided, billing rate and average\ncost records are created atomically with the staff record.\n`rateCardId` and all `rateTypeId` values must reference existing records\nor the entire request is rejected with HTTP 400.\n",
                    "required": [
                      "rateCardId",
                      "billingRates"
                    ],
                    "properties": {
                      "rateCardId": {
                        "type": "integer",
                        "format": "int64",
                        "description": "ID of an existing rate card to assign this staff member to",
                        "example": 5
                      },
                      "billingRates": {
                        "type": "array",
                        "description": "One billing rate record per rate type. Can be an empty array if only an average cost is being set.\n",
                        "items": {
                          "type": "object",
                          "required": [
                            "rateTypeId"
                          ],
                          "properties": {
                            "rateTypeId": {
                              "type": "integer",
                              "format": "int64",
                              "description": "ID of an existing rate type",
                              "example": 12
                            },
                            "hourlyBillingRate": {
                              "type": [
                                "number",
                                "null"
                              ],
                              "format": "decimal",
                              "description": "Hourly billing rate in the firm's currency. Defaults to 0 when omitted.",
                              "example": 150
                            }
                          }
                        }
                      },
                      "averageCost": {
                        "type": [
                          "number",
                          "null"
                        ],
                        "format": "decimal",
                        "description": "Average hourly cost for this staff member. One record per rate card assignment.",
                        "example": 75
                      }
                    }
                  }
                }
              },
              "examples": {
                "minimal": {
                  "summary": "Minimal required fields only",
                  "value": {
                    "firstName": "Jane",
                    "lastName": "Doe",
                    "pmsRef": "EMP-1042",
                    "ref": "doe-j"
                  }
                },
                "with_rate_card": {
                  "summary": "Staff with full rate card assignment",
                  "value": {
                    "firstName": "Jane",
                    "lastName": "Doe",
                    "pmsRef": "EMP-1042",
                    "ref": "doe-j",
                    "email": "jane.doe@firm.com",
                    "jobTitle": "Senior Associate",
                    "active": true,
                    "rateCardAssignment": {
                      "rateCardId": 5,
                      "billingRates": [
                        {
                          "rateTypeId": 12,
                          "hourlyBillingRate": 150
                        },
                        {
                          "rateTypeId": 13,
                          "hourlyBillingRate": 175
                        }
                      ],
                      "averageCost": 75
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Staff member created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Unique identifier of the created staff member",
                          "example": 312
                        },
                        "pmsRef": {
                          "type": "string",
                          "example": "EMP-1042"
                        },
                        "ref": {
                          "type": "string",
                          "example": "doe-j"
                        },
                        "firstName": {
                          "type": "string",
                          "example": "Jane"
                        },
                        "lastName": {
                          "type": "string",
                          "example": "Doe"
                        },
                        "fullName": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "example": "Jane Doe"
                        },
                        "email": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "email",
                          "example": "jane.doe@firm.com"
                        },
                        "jobTitle": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "example": "Senior Associate"
                        },
                        "departmentId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "example": null
                        },
                        "officeId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "example": null
                        },
                        "active": {
                          "type": "boolean",
                          "example": true
                        },
                        "version": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Record version. A newly onboarded staff member has version 0; updates through this API do not change it.",
                          "example": 0
                        },
                        "createdAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "example": "2024-03-15T10:00:00Z"
                        },
                        "updatedAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "example": "2024-03-15T10:00:00Z"
                        },
                        "rateCardAssignment": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Present only when a rate card assignment was provided in the request",
                          "properties": {
                            "rateCardId": {
                              "type": "integer",
                              "format": "int64",
                              "description": "ID of the rate card the staff member was assigned to",
                              "example": 5
                            },
                            "billingRateIds": {
                              "type": "array",
                              "description": "IDs of the created rate_card_staff_billing_rate records",
                              "items": {
                                "type": "integer",
                                "format": "int64"
                              },
                              "example": [
                                101,
                                102
                              ]
                            },
                            "averageCostId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "description": "ID of the created rate_card_staff_average_cost record, or null if averageCost was not provided",
                              "example": 201
                            }
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "example": "Staff member created successfully"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time",
                          "example": "2024-03-15T10:00:00Z"
                        },
                        "version": {
                          "type": "string",
                          "example": "v1"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "staff_only": {
                    "summary": "Staff created without rate card assignment",
                    "value": {
                      "data": {
                        "id": 312,
                        "pmsRef": "EMP-1042",
                        "ref": "doe-j",
                        "firstName": "Jane",
                        "lastName": "Doe",
                        "fullName": "Jane Doe",
                        "email": "jane.doe@firm.com",
                        "active": true,
                        "version": 0,
                        "createdAt": "2024-03-15T10:00:00Z",
                        "updatedAt": "2024-03-15T10:00:00Z",
                        "rateCardAssignment": null
                      },
                      "meta": {
                        "success": true,
                        "message": "Staff member created successfully",
                        "timestamp": "2024-03-15T10:00:00Z",
                        "version": "v1"
                      }
                    }
                  },
                  "staff_with_rate_card": {
                    "summary": "Staff created with billing rates and average cost",
                    "value": {
                      "data": {
                        "id": 312,
                        "pmsRef": "EMP-1042",
                        "ref": "doe-j",
                        "firstName": "Jane",
                        "lastName": "Doe",
                        "fullName": "Jane Doe",
                        "email": "jane.doe@firm.com",
                        "active": true,
                        "version": 0,
                        "createdAt": "2024-03-15T10:00:00Z",
                        "updatedAt": "2024-03-15T10:00:00Z",
                        "rateCardAssignment": {
                          "rateCardId": 5,
                          "billingRateIds": [
                            101,
                            102
                          ],
                          "averageCostId": 201
                        }
                      },
                      "meta": {
                        "success": true,
                        "message": "Staff member created successfully",
                        "timestamp": "2024-03-15T10:00:00Z",
                        "version": "v1"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. Common causes:\n- Missing required fields (`firstName`, `lastName`, `pmsRef`, `ref`)\n- `rateCardAssignment.rateCardId` does not reference an existing rate card\n- One or more `rateTypeId` values in `billingRates` do not exist\n"
          },
          "401": {
            "description": "Unauthorized — missing or invalid bearer token"
          },
          "403": {
            "description": "Forbidden — token does not have the `ROLE_API_ADMIN` role"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/staff/{staffId}": {
      "put": {
        "tags": [
          "Staff"
        ],
        "summary": "Update a staff member",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Update an existing staff member's profile and optionally replace their rate card assignment**\n\nAll fields are optional — only the fields you include will be updated. Omitted fields\nretain their current values.\n\n**Rate card assignment replacement** (`rateCardAssignment`):\nWhen provided, this operation atomically:\n1. Deactivates **all** active `rate_card_staff_billing_rate` and\n   `rate_card_staff_average_cost` records currently linked to this staff member\n   (across any rate card).\n2. Creates new records for the specified `rateCardId`.\n\nOmitting `rateCardAssignment` entirely leaves existing rate card records untouched.\n\nPre-write validation ensures `rateCardId` and all `rateTypeId` values reference\nexisting records — if any are invalid the entire request is rejected with HTTP 400\nand no changes are written.\n",
        "operationId": "updateStaff",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "staffId",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the staff member to update",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "example": 312
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "firstName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Updated first name",
                    "example": "Jane"
                  },
                  "lastName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Updated last name",
                    "example": "Doe"
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "email",
                    "description": "Updated primary email address",
                    "example": "jane.doe@firm.com"
                  },
                  "jobTitle": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Updated job title (free-text)",
                    "example": "Manager"
                  },
                  "jobTitleId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated job title lookup record ID",
                    "example": 8
                  },
                  "departmentId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated department ID",
                    "example": 3
                  },
                  "officeId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated office ID",
                    "example": 2
                  },
                  "orgId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated organization ID",
                    "example": 1
                  },
                  "serviceLineId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated service line ID",
                    "example": 4
                  },
                  "staffTypeId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated staff type ID (e.g. Partner, Manager, Associate)",
                    "example": 3
                  },
                  "partnerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated partner staff member ID",
                    "example": 50
                  },
                  "managerStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated manager staff member ID",
                    "example": 31
                  },
                  "supervisorStaffId": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "format": "int64",
                    "description": "Updated supervisor staff member ID",
                    "example": null
                  },
                  "prefix": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Updated name prefix",
                    "example": "Dr."
                  },
                  "startDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Updated employment start date",
                    "example": "2023-06-01T00:00:00"
                  },
                  "endDate": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Updated employment end date",
                    "example": null
                  },
                  "active": {
                    "type": [
                      "boolean",
                      "null"
                    ],
                    "description": "Updated active status",
                    "example": true
                  },
                  "rateCardAssignment": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "When provided, replaces the staff member's entire rate card assignment.\nAll current active billing rate and average cost records are deactivated\nand new records are created for the specified rate card. Validated before\nany writes — invalid `rateCardId` or `rateTypeId` values return HTTP 400.\n",
                    "required": [
                      "rateCardId",
                      "billingRates"
                    ],
                    "properties": {
                      "rateCardId": {
                        "type": "integer",
                        "format": "int64",
                        "description": "ID of the rate card to assign",
                        "example": 6
                      },
                      "billingRates": {
                        "type": "array",
                        "description": "New billing rate records to create, one per rate type. Can be an empty array if only the average cost is being updated.\n",
                        "items": {
                          "type": "object",
                          "required": [
                            "rateTypeId"
                          ],
                          "properties": {
                            "rateTypeId": {
                              "type": "integer",
                              "format": "int64",
                              "description": "ID of an existing rate type",
                              "example": 12
                            },
                            "hourlyBillingRate": {
                              "type": [
                                "number",
                                "null"
                              ],
                              "format": "decimal",
                              "description": "Hourly billing rate. Defaults to 0 when omitted.",
                              "example": 200
                            }
                          }
                        }
                      },
                      "averageCost": {
                        "type": [
                          "number",
                          "null"
                        ],
                        "format": "decimal",
                        "description": "New average hourly cost. Omit to leave the average cost unset.",
                        "example": 95
                      }
                    }
                  }
                }
              },
              "examples": {
                "fields_only": {
                  "summary": "Update staff fields only (no rate card change)",
                  "value": {
                    "jobTitle": "Manager",
                    "departmentId": 4,
                    "active": true
                  }
                },
                "replace_rate_card": {
                  "summary": "Replace rate card assignment",
                  "value": {
                    "rateCardAssignment": {
                      "rateCardId": 6,
                      "billingRates": [
                        {
                          "rateTypeId": 12,
                          "hourlyBillingRate": 200
                        }
                      ],
                      "averageCost": 95
                    }
                  }
                },
                "fields_and_rate_card": {
                  "summary": "Update fields and replace rate card in one request",
                  "value": {
                    "jobTitle": "Senior Manager",
                    "rateCardAssignment": {
                      "rateCardId": 6,
                      "billingRates": [
                        {
                          "rateTypeId": 12,
                          "hourlyBillingRate": 200
                        },
                        {
                          "rateTypeId": 13,
                          "hourlyBillingRate": 225
                        }
                      ],
                      "averageCost": 95
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Staff member updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Staff member identifier",
                          "example": 312
                        },
                        "pmsRef": {
                          "type": "string",
                          "example": "EMP-1042"
                        },
                        "ref": {
                          "type": "string",
                          "example": "doe-j"
                        },
                        "firstName": {
                          "type": "string",
                          "example": "Jane"
                        },
                        "lastName": {
                          "type": "string",
                          "example": "Doe"
                        },
                        "fullName": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "example": "Jane Doe"
                        },
                        "email": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "email",
                          "example": "jane.doe@firm.com"
                        },
                        "jobTitle": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "example": "Manager"
                        },
                        "active": {
                          "type": "boolean",
                          "example": true
                        },
                        "version": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Record version. A newly onboarded staff member has version 0; updates through this API do not change it.",
                          "example": 0
                        },
                        "createdAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "example": "2024-03-15T10:00:00Z"
                        },
                        "updatedAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "example": "2024-06-01T09:00:00Z"
                        },
                        "rateCardAssignment": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Present only when `rateCardAssignment` was provided in the request. Contains the IDs of the newly created records.\n",
                          "properties": {
                            "rateCardId": {
                              "type": "integer",
                              "format": "int64",
                              "example": 6
                            },
                            "billingRateIds": {
                              "type": "array",
                              "description": "IDs of the newly created rate_card_staff_billing_rate records",
                              "items": {
                                "type": "integer",
                                "format": "int64"
                              },
                              "example": [
                                205
                              ]
                            },
                            "averageCostId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "format": "int64",
                              "description": "ID of the newly created rate_card_staff_average_cost record, or null if averageCost was not provided",
                              "example": 301
                            }
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "example": "Staff member updated successfully"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time",
                          "example": "2024-06-01T09:00:00Z"
                        },
                        "version": {
                          "type": "string",
                          "example": "v1"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "fields_updated": {
                    "summary": "Fields updated, no rate card change",
                    "value": {
                      "data": {
                        "id": 312,
                        "pmsRef": "EMP-1042",
                        "ref": "doe-j",
                        "firstName": "Jane",
                        "lastName": "Doe",
                        "fullName": "Jane Doe",
                        "jobTitle": "Manager",
                        "active": true,
                        "version": 0,
                        "updatedAt": "2024-06-01T09:00:00Z",
                        "rateCardAssignment": null
                      },
                      "meta": {
                        "success": true,
                        "message": "Staff member updated successfully",
                        "timestamp": "2024-06-01T09:00:00Z",
                        "version": "v1"
                      }
                    }
                  },
                  "rate_card_replaced": {
                    "summary": "Rate card assignment replaced",
                    "value": {
                      "data": {
                        "id": 312,
                        "pmsRef": "EMP-1042",
                        "ref": "doe-j",
                        "firstName": "Jane",
                        "lastName": "Doe",
                        "fullName": "Jane Doe",
                        "jobTitle": "Manager",
                        "active": true,
                        "version": 0,
                        "updatedAt": "2024-06-01T09:00:00Z",
                        "rateCardAssignment": {
                          "rateCardId": 6,
                          "billingRateIds": [
                            205
                          ],
                          "averageCostId": 301
                        }
                      },
                      "meta": {
                        "success": true,
                        "message": "Staff member updated successfully",
                        "timestamp": "2024-06-01T09:00:00Z",
                        "version": "v1"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. Common causes:\n- `rateCardAssignment.rateCardId` does not reference an existing rate card\n- One or more `rateTypeId` values in `billingRates` do not exist\n"
          },
          "401": {
            "description": "Unauthorized — missing or invalid bearer token"
          },
          "403": {
            "description": "Forbidden — token does not have the `ROLE_API_ADMIN` role"
          },
          "404": {
            "description": "Staff member not found for the given `staffId`"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/staff/type/batch/create": {
      "post": {
        "tags": [
          "Staff"
        ],
        "summary": "Create staff types in batch",
        "description": "\n> 🔐 **Required role:** `STF_TYP_C`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Create staff types in batch**\n\nCreates up to **100** staff types in a single request.\n\nNotes:\n- The request body is JSON ``{ \"items\": [ ... ] }`` where ``items`` is an array of staff type objects (same shape as single ``/create``).\n- ``items`` must contain **1–100** elements; otherwise the request is rejected with **400**.\n- Successful creates appear under `succeeded`; failures appear under `failed` with an error message (partial success is allowed).\n- **201** when every item succeeds; **422** when every item fails; **200** when there is a mix of successes and failures.\n\n**Response body (201, 200 and 422):** the body is not wrapped in `data`/`meta`. It always has\nboth arrays; `index` is the item's position in the request `items`.\n```json\n{\n  \"succeeded\": [ { \"index\": 0, \"display\": \"Associate\", \"id\": 41 } ],\n  \"failed\": [ { \"index\": 1, \"display\": \"Manager\", \"message\": \"Sorry, the specified permission set was not found or is not active.\" } ]\n}\n```\n- `succeeded[]`: `index` (integer), `display` (string), `id` (integer, id of the new staff type)\n- `failed[]`: `index` (integer), `display` (string), `message` (string, why the item was not created)\n",
        "operationId": "StaffTypeBatchCreate",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "items": [
                  {
                    "display": "Associate",
                    "description": "Associate staff type"
                  },
                  {
                    "display": "Manager",
                    "description": "Manager staff type"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "items"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "display": {
                          "type": "string",
                          "description": "Display"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "permissionSetId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Permissionsetid"
                        }
                      }
                    },
                    "description": "Items"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Partial success — some staff types were created and some failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "succeeded",
                    "failed"
                  ],
                  "properties": {
                    "succeeded": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "id"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Id"
                          }
                        }
                      },
                      "description": "Succeeded"
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "message"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "message": {
                            "type": "string",
                            "description": "Message"
                          }
                        }
                      },
                      "description": "Failed"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "All staff types were created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "succeeded",
                    "failed"
                  ],
                  "properties": {
                    "succeeded": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "id"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Id"
                          }
                        }
                      },
                      "description": "Succeeded"
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "message"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "message": {
                            "type": "string",
                            "description": "Message"
                          }
                        }
                      },
                      "description": "Failed"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires STF_TYP_C)"
          },
          "422": {
            "description": "None of the staff types could be created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "succeeded",
                    "failed"
                  ],
                  "properties": {
                    "succeeded": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "id"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Id"
                          }
                        }
                      },
                      "description": "Succeeded"
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "index",
                          "display",
                          "message"
                        ],
                        "properties": {
                          "index": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Index"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "message": {
                            "type": "string",
                            "description": "Message"
                          }
                        }
                      },
                      "description": "Failed"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/staff/type/batch/lookup": {
      "post": {
        "tags": [
          "Staff"
        ],
        "summary": "Lookup staff types (paged)",
        "description": "\n> 🔐 **Required role:** `STF_TYP_R` or `STF_TYP_C`\n>\n> 📖 **Data dictionary:** [Staff](/reference/data-dictionary/staff)\n\n**Lookup staff types page by page**\n\nReturns a page of staff types ordered by id ascending.\n\nNotes:\n- `pageSize` must be between **1** and **100**\n- `page` is zero-based (`page` 0 is the first page)\n",
        "operationId": "StaffTypeBatchLookup",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 25,
                "page": 0
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "pageSize",
                    "page",
                    "returned",
                    "total",
                    "records"
                  ],
                  "properties": {
                    "pageSize": {
                      "type": "integer",
                      "format": "int32",
                      "description": "Pagesize"
                    },
                    "page": {
                      "type": "integer",
                      "format": "int32",
                      "description": "Page"
                    },
                    "returned": {
                      "type": "integer",
                      "format": "int32",
                      "description": "Returned"
                    },
                    "total": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Total"
                    },
                    "records": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "pmsRef",
                          "display",
                          "active"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Id"
                          },
                          "pmsRef": {
                            "type": "string",
                            "description": "Pmsref"
                          },
                          "display": {
                            "type": "string",
                            "description": "Display"
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Description"
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Active"
                          }
                        }
                      },
                      "description": "Records"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of STF_TYP_R, STF_TYP_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/invoices": {
      "post": {
        "tags": [
          "Invoices"
        ],
        "summary": "List invoices",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Invoice](/reference/data-dictionary/invoice)\n\n**Retrieve invoices with AR transaction data, paginated**\n\nThis operation accepts only `pageSize` and `page`; any other body property is\nrejected with 400. To filter, use `POST /gql/v1/invoices/search`.\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nThis endpoint delivers complete invoice management functionality with:\n- Pagination for large invoice datasets\n- Integration with AR transactions for complete financial context\n- Tax, interest, and payment status tracking\n- Client relationship data for each invoice\n- Aggregate counting for reporting and analytics\n\n**Key Financial Features:**\n- Invoice status tracking (PENDING, PAID, OVERDUE, POSTED, etc.)\n- Tax and interest calculations included\n- Due date monitoring for collections management\n- AR transaction linkage for payment reconciliation\n- Amount and allocation tracking for financial reporting\n\n**Ordering:** newest first (`createdAt` desc), then `invoiceNumber` asc.\n\n**Business Applications:**\n- Accounts receivable management and aging reports\n- Client billing history and statement generation\n- Collections management and overdue tracking\n- Financial reporting and revenue recognition\n- Payment reconciliation and allocation tracking\n",
        "operationId": "getInvoices",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved invoice records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "invoices",
                    "total"
                  ],
                  "properties": {
                    "invoices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "arTranId",
                          "invoiceNumber",
                          "dueDate",
                          "status",
                          "tax",
                          "interest",
                          "description",
                          "createdAt",
                          "updatedAt",
                          "ar_tran",
                          "postedAt",
                          "deliveryMethod",
                          "emailRecipients",
                          "invoiceFileId",
                          "reversalReason",
                          "reversedAt",
                          "reversedByStaffId"
                        ],
                        "properties": {
                          "arTranId": {
                            "type": "integer",
                            "description": "Invoice identifier (equal to the AR transaction id)",
                            "example": 125890
                          },
                          "invoiceNumber": {
                            "type": "string",
                            "description": "Unique invoice number for client reference",
                            "example": "INV-2024-4850"
                          },
                          "dueDate": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Invoice payment due date, as a local date-time with no time-zone offset",
                            "example": "2024-04-24T05:00:00"
                          },
                          "status": {
                            "type": "string",
                            "description": "Current invoice status",
                            "example": "POSTED"
                          },
                          "tax": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Tax amount charged on invoice",
                            "example": 0
                          },
                          "interest": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Interest charges applied to invoice",
                            "example": 0
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Additional invoice description or notes",
                            "example": null
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Invoice record creation timestamp",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Invoice record last update timestamp",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "postedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the invoice was posted. Distinct from `ar_tran.transactionDate`, the date the invoice carries.",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "deliveryMethod": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "How the invoice was delivered: EMAIL, DOWNLOAD, EMAIL_AND_DOWNLOAD or POST_ONLY",
                            "example": "EMAIL"
                          },
                          "emailRecipients": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Email recipients the invoice was sent to",
                            "example": "ap@techflow.example"
                          },
                          "invoiceFileId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Identifier of the invoice PDF file",
                            "example": 88231
                          },
                          "reversalReason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Reason recorded when the posted invoice was reversed",
                            "example": null
                          },
                          "reversedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the invoice was reversed",
                            "example": null
                          },
                          "reversedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Identifier of the staff member who reversed the invoice",
                            "example": null
                          },
                          "ar_tran": {
                            "type": "object",
                            "description": "Associated AR transaction details",
                            "required": [
                              "id",
                              "pmsRef",
                              "transactionDate",
                              "amount",
                              "allocated",
                              "clientId",
                              "allocatedInCurrency",
                              "amountInCurrency",
                              "businessEntityId",
                              "createdAt",
                              "currencyId",
                              "customFieldValues",
                              "exchangeRate",
                              "internalNotes",
                              "isActive",
                              "isCreatedByAiwyn",
                              "isManagedByAiwyn",
                              "isPosted",
                              "isReconciled",
                              "managerStaffId",
                              "notes",
                              "partnerStaffId",
                              "pmsCreatedAt",
                              "projectId",
                              "responsibleStaffId",
                              "type",
                              "updatedAt"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 125890
                              },
                              "pmsRef": {
                                "type": "string",
                                "description": "Practice management system reference",
                                "example": "240815"
                              },
                              "transactionDate": {
                                "type": "string",
                                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                                "description": "Transaction date, as a local date-time with no time-zone offset",
                                "example": "2024-03-22T05:00:00"
                              },
                              "amount": {
                                "type": "number",
                                "format": "decimal",
                                "description": "Transaction amount",
                                "example": 4250
                              },
                              "allocated": {
                                "type": "number",
                                "format": "decimal",
                                "description": "Allocated amount",
                                "example": 4250
                              },
                              "clientId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Client identifier",
                                "example": 7720
                              },
                              "allocatedInCurrency": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Applied amount in the transaction currency",
                                "example": null
                              },
                              "amountInCurrency": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Transaction amount in the transaction currency",
                                "example": null
                              },
                              "businessEntityId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the firm business entity",
                                "example": 1
                              },
                              "createdAt": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the AR transaction was created",
                                "example": "2024-05-12T22:50:20.595961+00:00"
                              },
                              "currencyId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the currency of the amounts ending in InCurrency. Null when no currency is recorded.",
                                "example": null
                              },
                              "customFieldValues": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Firm-defined custom fields, keyed by field name",
                                "example": null
                              },
                              "exchangeRate": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Exchange rate to the firm currency",
                                "example": null
                              },
                              "internalNotes": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Internal notes on the transaction, visible only to firm staff",
                                "example": null
                              },
                              "isActive": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the transaction is active; inactive transactions were deleted or reversed",
                                "example": true
                              },
                              "isCreatedByAiwyn": {
                                "type": "boolean",
                                "description": "Whether the transaction was created in Aiwyn",
                                "example": true
                              },
                              "isManagedByAiwyn": {
                                "type": "boolean",
                                "description": "Whether Aiwyn manages the transaction's lifecycle",
                                "example": false
                              },
                              "isPosted": {
                                "type": "boolean",
                                "description": "Whether the transaction is posted",
                                "example": true
                              },
                              "isReconciled": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the transaction is reconciled",
                                "example": null
                              },
                              "managerStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the manager staff member",
                                "example": 301
                              },
                              "notes": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Notes on the transaction visible to the client",
                                "example": null
                              },
                              "partnerStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the partner staff member",
                                "example": 302
                              },
                              "pmsCreatedAt": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                                "description": "When the transaction was created in your practice management system, as a local date-time with no time-zone offset. Null when the system does not provide it; for transactions created in Aiwyn, when Aiwyn created them.",
                                "example": "2024-03-22T05:00:00"
                              },
                              "projectId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the project the transaction belongs to",
                                "example": 2514
                              },
                              "responsibleStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the responsible staff member",
                                "example": 303
                              },
                              "type": {
                                "type": "string",
                                "description": "AR transaction type, for example Invoice, Receipt, Credit, Debit, LateFee, ProcessingFee, Refund, Dispute, DraftInvoice, Prepayment, ReceiptAdj, BadDebt, InternationalFee, LateFeeReversal or Unknown",
                                "example": "Invoice"
                              },
                              "updatedAt": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the AR transaction was last updated",
                                "example": "2024-05-12T22:50:20.595961+00:00"
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of invoices",
                              "example": 94
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Invoice records with AR transaction details",
                    "value": {
                      "invoices": [
                        {
                          "arTranId": 125890,
                          "invoiceNumber": "INV-2024-4850",
                          "dueDate": "2024-04-24T05:00:00",
                          "status": "POSTED",
                          "tax": 0,
                          "interest": 0,
                          "description": null,
                          "createdAt": "2024-05-12T22:50:20.595961+00:00",
                          "updatedAt": "2024-05-12T22:50:20.595961+00:00",
                          "postedAt": "2024-05-12T22:50:20.595961+00:00",
                          "deliveryMethod": "EMAIL",
                          "emailRecipients": "ap@techflow.example",
                          "invoiceFileId": 88231,
                          "reversalReason": null,
                          "reversedAt": null,
                          "reversedByStaffId": null,
                          "ar_tran": {
                            "id": 125890,
                            "pmsRef": "240815",
                            "transactionDate": "2024-03-22T05:00:00",
                            "amount": 4250,
                            "allocated": 4250,
                            "clientId": 7720,
                            "allocatedInCurrency": null,
                            "amountInCurrency": null,
                            "businessEntityId": 1,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "currencyId": null,
                            "customFieldValues": null,
                            "exchangeRate": null,
                            "internalNotes": null,
                            "isActive": true,
                            "isCreatedByAiwyn": true,
                            "isManagedByAiwyn": false,
                            "isPosted": true,
                            "isReconciled": null,
                            "managerStaffId": 301,
                            "notes": null,
                            "partnerStaffId": 302,
                            "pmsCreatedAt": "2024-03-22T05:00:00",
                            "projectId": 2514,
                            "responsibleStaffId": 303,
                            "type": "Invoice",
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                          }
                        },
                        {
                          "arTranId": 125234,
                          "invoiceNumber": "INV-2024-4721",
                          "dueDate": "2024-03-03T05:00:00",
                          "status": "POSTED",
                          "tax": 0,
                          "interest": 0,
                          "description": null,
                          "createdAt": "2024-05-12T22:50:10.982058+00:00",
                          "updatedAt": "2024-05-12T22:50:10.982058+00:00",
                          "postedAt": "2024-05-12T22:50:20.595961+00:00",
                          "deliveryMethod": "EMAIL",
                          "emailRecipients": "ap@techflow.example",
                          "invoiceFileId": 88231,
                          "reversalReason": null,
                          "reversedAt": null,
                          "reversedByStaffId": null,
                          "ar_tran": {
                            "id": 125234,
                            "pmsRef": "239842",
                            "transactionDate": "2024-02-04T05:00:00",
                            "amount": 3750,
                            "allocated": 3750,
                            "clientId": 7720,
                            "allocatedInCurrency": null,
                            "amountInCurrency": null,
                            "businessEntityId": 1,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "currencyId": null,
                            "customFieldValues": null,
                            "exchangeRate": null,
                            "internalNotes": null,
                            "isActive": true,
                            "isCreatedByAiwyn": true,
                            "isManagedByAiwyn": false,
                            "isPosted": true,
                            "isReconciled": null,
                            "managerStaffId": 301,
                            "notes": null,
                            "partnerStaffId": 302,
                            "pmsCreatedAt": "2024-03-22T05:00:00",
                            "projectId": 2514,
                            "responsibleStaffId": 303,
                            "type": "Invoice",
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                          }
                        },
                        {
                          "arTranId": 124856,
                          "invoiceNumber": "INV-2024-4592",
                          "dueDate": "2024-02-07T05:00:00",
                          "status": "POSTED",
                          "tax": 0,
                          "interest": 0,
                          "description": null,
                          "createdAt": "2024-05-12T22:50:09.194501+00:00",
                          "updatedAt": "2024-05-12T22:50:09.194501+00:00",
                          "postedAt": "2024-05-12T22:50:20.595961+00:00",
                          "deliveryMethod": "EMAIL",
                          "emailRecipients": "ap@techflow.example",
                          "invoiceFileId": 88231,
                          "reversalReason": null,
                          "reversedAt": null,
                          "reversedByStaffId": null,
                          "ar_tran": {
                            "id": 124856,
                            "pmsRef": "238967",
                            "transactionDate": "2024-01-08T05:00:00",
                            "amount": 2850,
                            "allocated": 2850,
                            "clientId": 7720,
                            "allocatedInCurrency": null,
                            "amountInCurrency": null,
                            "businessEntityId": 1,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "currencyId": null,
                            "customFieldValues": null,
                            "exchangeRate": null,
                            "internalNotes": null,
                            "isActive": true,
                            "isCreatedByAiwyn": true,
                            "isManagedByAiwyn": false,
                            "isPosted": true,
                            "isReconciled": null,
                            "managerStaffId": 301,
                            "notes": null,
                            "partnerStaffId": 302,
                            "pmsCreatedAt": "2024-03-22T05:00:00",
                            "projectId": 2514,
                            "responsibleStaffId": 303,
                            "type": "Invoice",
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 94
                        }
                      }
                    }
                  },
                  "real_api_response": {
                    "summary": "Sample from actual API response",
                    "value": {
                      "invoices": [
                        {
                          "arTranId": 119859,
                          "invoiceNumber": "4618",
                          "dueDate": "2023-03-24T05:00:00",
                          "status": "POSTED",
                          "tax": 0,
                          "interest": 0,
                          "description": null,
                          "createdAt": "2023-05-12T22:50:20.595961+00:00",
                          "updatedAt": "2023-05-12T22:50:20.595961+00:00",
                          "postedAt": "2024-05-12T22:50:20.595961+00:00",
                          "deliveryMethod": "EMAIL",
                          "emailRecipients": "ap@techflow.example",
                          "invoiceFileId": 88231,
                          "reversalReason": null,
                          "reversedAt": null,
                          "reversedByStaffId": null,
                          "ar_tran": {
                            "id": 119859,
                            "pmsRef": "224081",
                            "transactionDate": "2023-02-22T05:00:00",
                            "amount": 0,
                            "allocated": 0,
                            "clientId": 7720,
                            "allocatedInCurrency": null,
                            "amountInCurrency": null,
                            "businessEntityId": 1,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "currencyId": null,
                            "customFieldValues": null,
                            "exchangeRate": null,
                            "internalNotes": null,
                            "isActive": true,
                            "isCreatedByAiwyn": true,
                            "isManagedByAiwyn": false,
                            "isPosted": true,
                            "isReconciled": null,
                            "managerStaffId": 301,
                            "notes": null,
                            "partnerStaffId": 302,
                            "pmsCreatedAt": "2024-03-22T05:00:00",
                            "projectId": 2514,
                            "responsibleStaffId": 303,
                            "type": "Invoice",
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                          }
                        },
                        {
                          "arTranId": 96162,
                          "invoiceNumber": "74080",
                          "dueDate": "2018-10-11T04:00:00",
                          "status": "POSTED",
                          "tax": 0,
                          "interest": 0,
                          "description": null,
                          "createdAt": "2023-05-12T22:50:08.928921+00:00",
                          "updatedAt": "2023-05-12T22:50:08.928921+00:00",
                          "postedAt": "2024-05-12T22:50:20.595961+00:00",
                          "deliveryMethod": "EMAIL",
                          "emailRecipients": "ap@techflow.example",
                          "invoiceFileId": 88231,
                          "reversalReason": null,
                          "reversedAt": null,
                          "reversedByStaffId": null,
                          "ar_tran": {
                            "id": 96162,
                            "pmsRef": "108840",
                            "transactionDate": "2018-09-11T04:00:00",
                            "amount": 3516,
                            "allocated": 3516,
                            "clientId": 7720,
                            "allocatedInCurrency": null,
                            "amountInCurrency": null,
                            "businessEntityId": 1,
                            "createdAt": "2024-05-12T22:50:20.595961+00:00",
                            "currencyId": null,
                            "customFieldValues": null,
                            "exchangeRate": null,
                            "internalNotes": null,
                            "isActive": true,
                            "isCreatedByAiwyn": true,
                            "isManagedByAiwyn": false,
                            "isPosted": true,
                            "isReconciled": null,
                            "managerStaffId": 301,
                            "notes": null,
                            "partnerStaffId": 302,
                            "pmsCreatedAt": "2024-03-22T05:00:00",
                            "projectId": 2514,
                            "responsibleStaffId": 303,
                            "type": "Invoice",
                            "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 94
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No invoices found",
                    "value": {
                      "invoices": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination values or an unexpected body property",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "unexpected_variable": {
                    "summary": "Body property other than pageSize/page",
                    "value": {
                      "path": "$",
                      "error": "Unexpected variable clientId",
                      "code": "bad-request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid authentication token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_auth": {
                    "summary": "Missing authentication header",
                    "value": {
                      "error": "Authorization header is required",
                      "code": "MISSING_AUTH_HEADER"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/invoices/search": {
      "post": {
        "tags": [
          "Invoices"
        ],
        "summary": "Search invoices",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Invoice](/reference/data-dictionary/invoice)\n\n**Advanced invoice filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports invoiceNumber text matching, status filtering, and date ranges.\n",
        "operationId": "filterInvoicesDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "invoiceNumber": {
                            "_ilike": "%2024%"
                          }
                        },
                        {
                          "description": {
                            "_ilike": "%service%"
                          }
                        }
                      ]
                    },
                    {
                      "status": {
                        "_in": [
                          "POSTED",
                          "CLOSED"
                        ]
                      }
                    },
                    {
                      "createdAt": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "dueDate": {
                        "_gte": "2024-01-01T00:00:00"
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "invoiceNumber": "asc"
                  },
                  {
                    "createdAt": "desc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex invoice filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "invoiceNumber": {
                                "_ilike": "%2024%"
                              }
                            },
                            {
                              "description": {
                                "_ilike": "%service%"
                              }
                            }
                          ]
                        },
                        {
                          "status": {
                            "_in": [
                              "POSTED",
                              "CLOSED"
                            ]
                          }
                        },
                        {
                          "createdAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "dueDate": {
                            "_gte": "2024-01-01T00:00:00"
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications",
                    "example": [
                      {
                        "invoiceNumber": "asc"
                      },
                      {
                        "createdAt": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered invoices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "invoices",
                    "total"
                  ],
                  "properties": {
                    "invoices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "arTranId",
                          "invoiceNumber",
                          "dueDate",
                          "status",
                          "tax",
                          "interest",
                          "description",
                          "createdAt",
                          "updatedAt",
                          "ar_tran",
                          "postedAt",
                          "deliveryMethod",
                          "emailRecipients",
                          "invoiceFileId",
                          "reversalReason",
                          "reversedAt",
                          "reversedByStaffId"
                        ],
                        "properties": {
                          "arTranId": {
                            "type": "integer",
                            "description": "Invoice identifier (equal to the AR transaction id)",
                            "example": 125890
                          },
                          "invoiceNumber": {
                            "type": "string",
                            "example": "INV-2024-4850"
                          },
                          "dueDate": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Invoice payment due date, as a local date-time with no time-zone offset",
                            "example": "2024-04-24T05:00:00"
                          },
                          "status": {
                            "type": "string",
                            "example": "POSTED"
                          },
                          "tax": {
                            "type": "number",
                            "description": "Tax amount recorded on the invoice",
                            "example": 0
                          },
                          "interest": {
                            "type": "number",
                            "description": "Interest amount recorded on the invoice",
                            "example": 0
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "example": null
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "postedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the invoice was posted. Distinct from `ar_tran.transactionDate`, the date the invoice carries.",
                            "example": "2024-05-12T22:50:20.595961+00:00"
                          },
                          "deliveryMethod": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "How the invoice was delivered: EMAIL, DOWNLOAD, EMAIL_AND_DOWNLOAD or POST_ONLY",
                            "example": "EMAIL"
                          },
                          "emailRecipients": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Email recipients the invoice was sent to",
                            "example": "ap@techflow.example"
                          },
                          "invoiceFileId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Identifier of the invoice PDF file",
                            "example": 88231
                          },
                          "reversalReason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Reason recorded when the posted invoice was reversed",
                            "example": null
                          },
                          "reversedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the invoice was reversed",
                            "example": null
                          },
                          "reversedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Identifier of the staff member who reversed the invoice",
                            "example": null
                          },
                          "ar_tran": {
                            "type": "object",
                            "description": "Associated AR transaction details",
                            "required": [
                              "id",
                              "pmsRef",
                              "transactionDate",
                              "amount",
                              "allocated",
                              "clientId",
                              "allocatedInCurrency",
                              "amountInCurrency",
                              "businessEntityId",
                              "createdAt",
                              "currencyId",
                              "customFieldValues",
                              "exchangeRate",
                              "internalNotes",
                              "isActive",
                              "isCreatedByAiwyn",
                              "isManagedByAiwyn",
                              "isPosted",
                              "isReconciled",
                              "managerStaffId",
                              "notes",
                              "partnerStaffId",
                              "pmsCreatedAt",
                              "projectId",
                              "responsibleStaffId",
                              "type",
                              "updatedAt"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 125890
                              },
                              "pmsRef": {
                                "type": "string",
                                "description": "Practice-management-system reference",
                                "example": "240815"
                              },
                              "transactionDate": {
                                "type": "string",
                                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                                "description": "Transaction date, as a local date-time with no time-zone offset",
                                "example": "2024-03-22T05:00:00"
                              },
                              "amount": {
                                "type": "number",
                                "description": "Total transaction amount",
                                "example": 4250
                              },
                              "allocated": {
                                "type": "number",
                                "description": "Amount allocated (applied/paid) against the transaction",
                                "example": 4250
                              },
                              "clientId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "example": 7720
                              },
                              "allocatedInCurrency": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Applied amount in the transaction currency",
                                "example": null
                              },
                              "amountInCurrency": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Transaction amount in the transaction currency",
                                "example": null
                              },
                              "businessEntityId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the firm business entity",
                                "example": 1
                              },
                              "createdAt": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the AR transaction was created",
                                "example": "2024-05-12T22:50:20.595961+00:00"
                              },
                              "currencyId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the currency of the amounts ending in InCurrency. Null when no currency is recorded.",
                                "example": null
                              },
                              "customFieldValues": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Firm-defined custom fields, keyed by field name",
                                "example": null
                              },
                              "exchangeRate": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Exchange rate to the firm currency",
                                "example": null
                              },
                              "internalNotes": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Internal notes on the transaction, visible only to firm staff",
                                "example": null
                              },
                              "isActive": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the transaction is active; inactive transactions were deleted or reversed",
                                "example": true
                              },
                              "isCreatedByAiwyn": {
                                "type": "boolean",
                                "description": "Whether the transaction was created in Aiwyn",
                                "example": true
                              },
                              "isManagedByAiwyn": {
                                "type": "boolean",
                                "description": "Whether Aiwyn manages the transaction's lifecycle",
                                "example": false
                              },
                              "isPosted": {
                                "type": "boolean",
                                "description": "Whether the transaction is posted",
                                "example": true
                              },
                              "isReconciled": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the transaction is reconciled",
                                "example": null
                              },
                              "managerStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the manager staff member",
                                "example": 301
                              },
                              "notes": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Notes on the transaction visible to the client",
                                "example": null
                              },
                              "partnerStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the partner staff member",
                                "example": 302
                              },
                              "pmsCreatedAt": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                                "description": "When the transaction was created in your practice management system, as a local date-time with no time-zone offset. Null when the system does not provide it; for transactions created in Aiwyn, when Aiwyn created them.",
                                "example": "2024-03-22T05:00:00"
                              },
                              "projectId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the project the transaction belongs to",
                                "example": 2514
                              },
                              "responsibleStaffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Identifier of the responsible staff member",
                                "example": 303
                              },
                              "type": {
                                "type": "string",
                                "description": "AR transaction type, for example Invoice, Receipt, Credit, Debit, LateFee, ProcessingFee, Refund, Dispute, DraftInvoice, Prepayment, ReceiptAdj, BadDebt, InternationalFee, LateFeeReversal or Unknown",
                                "example": "Invoice"
                              },
                              "updatedAt": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the AR transaction was last updated",
                                "example": "2024-05-12T22:50:20.595961+00:00"
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of invoices matching the where clause",
                              "example": 12
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/invoice/{id}": {
      "get": {
        "tags": [
          "Invoices"
        ],
        "summary": "Get invoice by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Invoice](/reference/data-dictionary/invoice)\n\n**Retrieve a specific invoice by its unique identifier**\n\nThis endpoint provides detailed invoice information including:\n- Complete invoice details and line items\n- Invoice status and payment tracking\n- Client and project relationships\n- Tax calculations and compliance data\n- Payment history and outstanding balances\n- Document generation and delivery status\n\n**Invoice Management Features:**\n- Invoice lifecycle tracking\n- Payment status monitoring\n- Tax calculation and compliance\n- Client relationship integration\n- Document generation and delivery\n\n**Invoice Details Include:**\n- Invoice number and reference\n- Invoice status and payment status\n- Client and project information\n- Line items and amounts\n- Tax calculations\n- Payment history\n\n**Business Applications:**\n- Invoice status monitoring\n- Payment tracking and reconciliation\n- Client billing history\n- Revenue recognition analysis\n- Tax compliance reporting\n\nThe invoice is wrapped in an `invoice` property. An id that matches no\ninvoice returns 200 with `\"invoice\": null`; the endpoint never returns 404.\n\n**Response Example:**\n```json\n{\n  \"invoice\": {\n    \"arTranId\": 45678,\n    \"invoiceNumber\": \"INV-2024-001\",\n    \"dueDate\": \"2024-12-31T23:59:59Z\",\n    \"status\": \"POSTED\",\n    \"tax\": 2000.00,\n    \"interest\": 0.00,\n    \"description\": \"Q4 Financial Audit\",\n    \"createdAt\": \"2024-12-01T09:00:00Z\",\n    \"updatedAt\": \"2024-12-15T10:30:00Z\",\n    \"ar_tran\": {\n      \"id\": 45678,\n      \"pmsRef\": \"AR-2024-045678\",\n      \"transactionDate\": \"2024-12-01T00:00:00Z\",\n      \"amount\": 22000.00,\n      \"allocated\": 15000.00,\n      \"clientId\": 789\n    }\n  }\n}\n```\n",
        "operationId": "getInvoiceById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the invoice",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 45678
          }
        ],
        "responses": {
          "200": {
            "description": "Invoice lookup completed. `invoice` is the invoice, or null when no invoice\nhas this id.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "invoice"
                  ],
                  "properties": {
                    "invoice": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The invoice, or null when the id matches no invoice",
                      "required": [
                        "arTranId",
                        "invoiceNumber",
                        "dueDate",
                        "status",
                        "tax",
                        "interest",
                        "description",
                        "createdAt",
                        "updatedAt",
                        "ar_tran",
                        "postedAt",
                        "deliveryMethod",
                        "emailRecipients",
                        "invoiceFileId",
                        "reversalReason",
                        "reversedAt",
                        "reversedByStaffId"
                      ],
                      "properties": {
                        "arTranId": {
                          "type": "integer",
                          "description": "Invoice identifier (equal to the AR transaction id)",
                          "example": 45678
                        },
                        "invoiceNumber": {
                          "type": "string",
                          "description": "Invoice number",
                          "example": "INV-2024-001"
                        },
                        "dueDate": {
                          "type": "string",
                          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                          "description": "Invoice due date, as a local date-time with no time-zone offset",
                          "example": "2024-12-31T23:59:59"
                        },
                        "status": {
                          "type": "string",
                          "description": "Invoice status",
                          "example": "POSTED"
                        },
                        "tax": {
                          "type": "number",
                          "description": "Tax amount recorded on the invoice",
                          "example": 2000
                        },
                        "interest": {
                          "type": "number",
                          "description": "Interest amount recorded on the invoice",
                          "example": 0
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Invoice description",
                          "example": "Q4 Financial Audit"
                        },
                        "createdAt": {
                          "type": "string",
                          "format": "date-time",
                          "description": "Invoice creation timestamp",
                          "example": "2024-12-01T09:00:00Z"
                        },
                        "updatedAt": {
                          "type": "string",
                          "format": "date-time",
                          "description": "Last update timestamp",
                          "example": "2024-12-15T10:30:00Z"
                        },
                        "postedAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "description": "When the invoice was posted. Distinct from `ar_tran.transactionDate`, the date the invoice carries.",
                          "example": "2024-05-12T22:50:20.595961+00:00"
                        },
                        "deliveryMethod": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "How the invoice was delivered: EMAIL, DOWNLOAD, EMAIL_AND_DOWNLOAD or POST_ONLY",
                          "example": "EMAIL"
                        },
                        "emailRecipients": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Email recipients the invoice was sent to",
                          "example": "ap@techflow.example"
                        },
                        "invoiceFileId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "description": "Identifier of the invoice PDF file",
                          "example": 88231
                        },
                        "reversalReason": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Reason recorded when the posted invoice was reversed",
                          "example": null
                        },
                        "reversedAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "description": "When the invoice was reversed",
                          "example": null
                        },
                        "reversedByStaffId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "description": "Identifier of the staff member who reversed the invoice",
                          "example": null
                        },
                        "ar_tran": {
                          "type": "object",
                          "description": "Underlying accounts-receivable transaction",
                          "required": [
                            "id",
                            "pmsRef",
                            "transactionDate",
                            "amount",
                            "allocated",
                            "clientId",
                            "allocatedInCurrency",
                            "amountInCurrency",
                            "businessEntityId",
                            "createdAt",
                            "currencyId",
                            "customFieldValues",
                            "exchangeRate",
                            "internalNotes",
                            "isActive",
                            "isCreatedByAiwyn",
                            "isManagedByAiwyn",
                            "isPosted",
                            "isReconciled",
                            "managerStaffId",
                            "notes",
                            "partnerStaffId",
                            "pmsCreatedAt",
                            "projectId",
                            "responsibleStaffId",
                            "type",
                            "updatedAt"
                          ],
                          "properties": {
                            "id": {
                              "type": "integer",
                              "description": "AR transaction identifier",
                              "example": 45678
                            },
                            "pmsRef": {
                              "type": "string",
                              "description": "Practice-management-system reference",
                              "example": "AR-2024-045678"
                            },
                            "transactionDate": {
                              "type": "string",
                              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                              "description": "AR transaction date, as a local date-time with no time-zone offset",
                              "example": "2024-12-01T00:00:00"
                            },
                            "amount": {
                              "type": "number",
                              "description": "Total transaction amount",
                              "example": 22000
                            },
                            "allocated": {
                              "type": "number",
                              "description": "Amount allocated (applied/paid) against the transaction",
                              "example": 15000
                            },
                            "clientId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Associated client identifier",
                              "example": 789
                            },
                            "allocatedInCurrency": {
                              "type": [
                                "number",
                                "null"
                              ],
                              "description": "Applied amount in the transaction currency",
                              "example": null
                            },
                            "amountInCurrency": {
                              "type": [
                                "number",
                                "null"
                              ],
                              "description": "Transaction amount in the transaction currency",
                              "example": null
                            },
                            "businessEntityId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the firm business entity",
                              "example": 1
                            },
                            "createdAt": {
                              "type": "string",
                              "format": "date-time",
                              "description": "When the AR transaction was created",
                              "example": "2024-05-12T22:50:20.595961+00:00"
                            },
                            "currencyId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the currency of the amounts ending in InCurrency. Null when no currency is recorded.",
                              "example": null
                            },
                            "customFieldValues": {
                              "type": [
                                "object",
                                "null"
                              ],
                              "description": "Firm-defined custom fields, keyed by field name",
                              "example": null
                            },
                            "exchangeRate": {
                              "type": [
                                "number",
                                "null"
                              ],
                              "description": "Exchange rate to the firm currency",
                              "example": null
                            },
                            "internalNotes": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "Internal notes on the transaction, visible only to firm staff",
                              "example": null
                            },
                            "isActive": {
                              "type": [
                                "boolean",
                                "null"
                              ],
                              "description": "Whether the transaction is active; inactive transactions were deleted or reversed",
                              "example": true
                            },
                            "isCreatedByAiwyn": {
                              "type": "boolean",
                              "description": "Whether the transaction was created in Aiwyn",
                              "example": true
                            },
                            "isManagedByAiwyn": {
                              "type": "boolean",
                              "description": "Whether Aiwyn manages the transaction's lifecycle",
                              "example": false
                            },
                            "isPosted": {
                              "type": "boolean",
                              "description": "Whether the transaction is posted",
                              "example": true
                            },
                            "isReconciled": {
                              "type": [
                                "boolean",
                                "null"
                              ],
                              "description": "Whether the transaction is reconciled",
                              "example": null
                            },
                            "managerStaffId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the manager staff member",
                              "example": 301
                            },
                            "notes": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "Notes on the transaction visible to the client",
                              "example": null
                            },
                            "partnerStaffId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the partner staff member",
                              "example": 302
                            },
                            "pmsCreatedAt": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                              "description": "When the transaction was created in your practice management system, as a local date-time with no time-zone offset. Null when the system does not provide it; for transactions created in Aiwyn, when Aiwyn created them.",
                              "example": "2024-03-22T05:00:00"
                            },
                            "projectId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the project the transaction belongs to",
                              "example": 2514
                            },
                            "responsibleStaffId": {
                              "type": [
                                "integer",
                                "null"
                              ],
                              "description": "Identifier of the responsible staff member",
                              "example": 303
                            },
                            "type": {
                              "type": "string",
                              "description": "AR transaction type, for example Invoice, Receipt, Credit, Debit, LateFee, ProcessingFee, Refund, Dispute, DraftInvoice, Prepayment, ReceiptAdj, BadDebt, InternationalFee, LateFeeReversal or Unknown",
                              "example": "Invoice"
                            },
                            "updatedAt": {
                              "type": "string",
                              "format": "date-time",
                              "description": "When the AR transaction was last updated",
                              "example": "2024-05-12T22:50:20.595961+00:00"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "found": {
                    "summary": "Invoice found",
                    "value": {
                      "invoice": {
                        "arTranId": 45678,
                        "invoiceNumber": "INV-2024-001",
                        "dueDate": "2024-12-31T23:59:59",
                        "status": "POSTED",
                        "tax": 2000,
                        "interest": 0,
                        "description": "Q4 Financial Audit",
                        "createdAt": "2024-12-01T09:00:00Z",
                        "updatedAt": "2024-12-15T10:30:00Z",
                        "postedAt": "2024-05-12T22:50:20.595961+00:00",
                        "deliveryMethod": "EMAIL",
                        "emailRecipients": "ap@techflow.example",
                        "invoiceFileId": 88231,
                        "reversalReason": null,
                        "reversedAt": null,
                        "reversedByStaffId": null,
                        "ar_tran": {
                          "id": 45678,
                          "pmsRef": "AR-2024-045678",
                          "transactionDate": "2024-12-01T00:00:00",
                          "amount": 22000,
                          "allocated": 15000,
                          "clientId": 789,
                          "allocatedInCurrency": null,
                          "amountInCurrency": null,
                          "businessEntityId": 1,
                          "createdAt": "2024-05-12T22:50:20.595961+00:00",
                          "currencyId": null,
                          "customFieldValues": null,
                          "exchangeRate": null,
                          "internalNotes": null,
                          "isActive": true,
                          "isCreatedByAiwyn": true,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "isReconciled": null,
                          "managerStaffId": 301,
                          "notes": null,
                          "partnerStaffId": 302,
                          "pmsCreatedAt": "2024-03-22T05:00:00",
                          "projectId": 2514,
                          "responsibleStaffId": 303,
                          "type": "Invoice",
                          "updatedAt": "2024-05-12T22:50:20.595961+00:00"
                        }
                      }
                    }
                  },
                  "not_found": {
                    "summary": "No invoice with this id",
                    "value": {
                      "invoice": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "example": "invalid input syntax for type integer: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "example": "data-exception"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this invoice"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/invoices/unpaid": {
      "get": {
        "tags": [
          "Invoices"
        ],
        "summary": "List a client's unpaid invoices",
        "description": "> 🔐 **Required role:** `INVC_R` or `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Invoice](/reference/data-dictionary/invoice)\n\n**Return the unpaid invoices of one client, resolved by client reference**\n\nThe client is resolved by `clientRef`, the same identifier `POST /api/v1/clients/v1/link/payment`\naccepts, and the invoices returned are exactly the ones that endpoint accepts in `invoiceIds` or\n`invoiceNumbers`: active invoices whose amount is larger than what has been allocated to them so\nfar. Fully paid, reversed, inactive and unposted (draft) invoices are not returned. Invoices are ordered by due date,\nthen invoice number.\n\nAmounts are decimal strings in the firm's currency. `outstanding` is `amount - allocated`.\n\nThe `id` of each invoice is the value to pass as `invoiceIds` when creating a payment link.\n",
        "operationId": "getUnpaidInvoicesByClientRef",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "clientRef",
            "in": "query",
            "required": true,
            "description": "Client reference of the client whose unpaid invoices are requested.",
            "schema": {
              "type": "string"
            },
            "example": "ACME-001"
          }
        ],
        "responses": {
          "200": {
            "description": "Client resolved and its unpaid invoices returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "client": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "integer",
                              "format": "int64",
                              "example": 7720
                            },
                            "clientRef": {
                              "type": "string",
                              "example": "ACME-001"
                            },
                            "name": {
                              "type": "string",
                              "example": "Acme Corporation"
                            }
                          }
                        },
                        "invoices": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "description": "Invoice identifier, accepted by the payment link endpoint as `invoiceIds`",
                                "example": 125890
                              },
                              "invoiceNumber": {
                                "type": "string",
                                "description": "Invoice number, accepted by the payment link endpoint as `invoiceNumbers`",
                                "example": "INV-2026-4850"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "example": "2025 individual tax return"
                              },
                              "status": {
                                "type": "string",
                                "enum": [
                                  "POSTED",
                                  "CLOSED",
                                  "CANCEL",
                                  "REVERSED"
                                ],
                                "example": "POSTED"
                              },
                              "transactionDate": {
                                "type": "string",
                                "format": "date",
                                "example": "2026-08-01"
                              },
                              "dueDate": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "format": "date",
                                "example": "2026-08-31"
                              },
                              "amount": {
                                "type": "string",
                                "description": "Invoice total, decimal string",
                                "example": "1250.00"
                              },
                              "allocated": {
                                "type": "string",
                                "description": "Amount already paid or credited against the invoice, decimal string",
                                "example": "250.00"
                              },
                              "outstanding": {
                                "type": "string",
                                "description": "Amount still owed, decimal string",
                                "example": "1000.00"
                              }
                            }
                          }
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "client": {
                      "id": 7720,
                      "clientRef": "ACME-001",
                      "name": "Acme Corporation"
                    },
                    "invoices": [
                      {
                        "id": 125890,
                        "invoiceNumber": "INV-2026-4850",
                        "description": "2025 individual tax return",
                        "status": "POSTED",
                        "transactionDate": "2026-08-01",
                        "dueDate": "2026-08-31",
                        "amount": "1250.00",
                        "allocated": "250.00",
                        "outstanding": "1000.00"
                      }
                    ]
                  },
                  "error": null,
                  "meta": {
                    "success": true,
                    "message": "Unpaid invoices retrieved successfully",
                    "timestamp": "2026-09-02T14:03:11.412Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "`clientRef` blank (`CLIENT_REF_REQUIRED`), more than one client carries that reference\n(`CLIENT_REF_AMBIGUOUS`), or the client is inactive (`CLIENT_INACTIVE`). The code is in `error.code`.\n"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires INVC_R or API_ADMIN)"
          },
          "404": {
            "description": "No client with that reference (`error.code` is `CLIENT_NOT_FOUND`)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/payments": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "List payments",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Payment](/reference/data-dictionary/payment)\n\n**Retrieve payment records with transaction details and security compliance**\n\nThis operation accepts only `pageSize` and `page`; any other body property is\nrejected with 400. To filter, use `POST /gql/v1/payments/search`.\n\n**Pagination (v1 — limit/offset, see [Pagination](/reference/pagination)):** `pageSize` is a limit (records to return).\n`page` is an offset (records to skip), not a page index. Hasura maps these as\n`limit: $pageSize` and `offset: $page`. When `page` is at or beyond\n`total.aggregate.count`, the result array is empty.\n\nThis endpoint provides secure payment data access with:\n- PCI-compliant payment information (masked card data)\n- Payment method categorization and tracking\n- Integration with AR transactions for complete context\n- Payment processor integration (PayPal, Stripe, etc.)\n- Client relationship data for payment attribution\n\n**Security & Compliance:**\n- PCI DSS compliant data handling (last 4 digits only)\n- Secure payment processor ID tracking\n- Payment confirmation date logging\n- Audit trail for payment processing\n\n**Payment Method Support:**\n- Credit/debit card payments with masked PAN\n- ACH/bank transfer processing\n- Check and wire transfer tracking\n- Digital wallet integration (PayPal, Apple Pay, etc.)\n\n**Reconciliation Features:**\n- Payment-to-invoice matching via AR transactions\n- Payment confirmation status tracking\n- Processor reference ID management\n- Multi-currency payment support\n\n**Business Applications:**\n- Payment reconciliation and matching\n- Revenue recognition and cash flow analysis\n- Client payment history and patterns\n- Payment method performance analysis\n- Compliance reporting and audit trails\n",
        "operationId": "getPayments",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved payment records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "payments",
                    "total"
                  ],
                  "properties": {
                    "payments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "payment_ar_tran_id",
                          "ar_transaction_date",
                          "client_name",
                          "client_ref",
                          "invoice_numbers",
                          "is_aiwyn_payment",
                          "is_partial_payment",
                          "is_payment_success",
                          "notes",
                          "engagement_names",
                          "paid_by_full_name",
                          "payment_payment_method",
                          "payment_pp_id",
                          "refund_date",
                          "refund_status",
                          "staff_admin_id",
                          "status",
                          "total_bill_amount",
                          "amount",
                          "principal",
                          "total_processing_fee_amount",
                          "total_international_fee_amount",
                          "total_late_fee_amount",
                          "is_posted",
                          "posted_to_bank_dt",
                          "estimated_deposit_date",
                          "dispute_status",
                          "dispute_refund_date",
                          "total_bill_amount_in_currency",
                          "amount_in_currency",
                          "principal_in_currency",
                          "total_processing_fee_amount_in_currency",
                          "total_international_fee_amount_in_currency",
                          "total_late_fee_amount_in_currency",
                          "currency_code",
                          "card_type",
                          "last4",
                          "failure_reason",
                          "failed_at",
                          "payment_confirmation_date",
                          "payment_source",
                          "payment"
                        ],
                        "properties": {
                          "payment_ar_tran_id": {
                            "type": "integer",
                            "description": "AR transaction id of the payment",
                            "example": 1048
                          },
                          "ar_transaction_date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Date/time of the AR transaction, as a local date-time with no time-zone offset",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "client_name": {
                            "type": "string",
                            "description": "Name of the client the payment belongs to",
                            "example": "Acme Corporation"
                          },
                          "client_ref": {
                            "type": "string",
                            "description": "External client reference number",
                            "example": "1337"
                          },
                          "invoice_numbers": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Comma-separated invoice numbers the payment is applied to",
                            "example": null
                          },
                          "is_aiwyn_payment": {
                            "type": "boolean",
                            "description": "Whether the payment was created through Aiwyn",
                            "example": true
                          },
                          "is_partial_payment": {
                            "type": "boolean",
                            "description": "Whether the payment only partially covers the billed amount",
                            "example": false
                          },
                          "is_payment_success": {
                            "type": "boolean",
                            "description": "Whether the payment succeeded",
                            "example": true
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Free-text notes on the payment",
                            "example": "Paid by check"
                          },
                          "engagement_names": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Names of engagements associated with the payment",
                            "example": null
                          },
                          "paid_by_full_name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Full name of the payer",
                            "example": "Jane Doe"
                          },
                          "payment_payment_method": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Human-readable payment method",
                            "example": "Bank Transfer"
                          },
                          "payment_pp_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Payment processor (Stripe) identifier",
                            "example": "pi_3UAtArIog7gyKVjp2xxxxxx"
                          },
                          "refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of refund, if refunded",
                            "example": null
                          },
                          "refund_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Refund status, if refunded",
                            "example": null
                          },
                          "staff_admin_id": {
                            "type": "boolean",
                            "description": "Staff/admin association flag",
                            "example": true
                          },
                          "status": {
                            "type": "string",
                            "description": "Human-readable payment status",
                            "example": "Completed"
                          },
                          "total_bill_amount": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount",
                            "example": null
                          },
                          "amount": {
                            "type": "number",
                            "description": "Payment amount",
                            "example": 10
                          },
                          "principal": {
                            "type": "number",
                            "description": "Principal portion of the payment",
                            "example": 10
                          },
                          "total_processing_fee_amount": {
                            "type": "number",
                            "description": "Total processing fee amount",
                            "example": 0
                          },
                          "total_international_fee_amount": {
                            "type": "number",
                            "description": "Total international fee amount",
                            "example": 0
                          },
                          "total_late_fee_amount": {
                            "type": "number",
                            "description": "Total late fee amount",
                            "example": 0
                          },
                          "is_posted": {
                            "type": "boolean",
                            "description": "Whether the payment has been posted to the bank",
                            "example": false
                          },
                          "posted_to_bank_dt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Date/time the payment was posted to the bank",
                            "example": null
                          },
                          "estimated_deposit_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Estimated deposit date, as a local date-time with no time-zone offset",
                            "example": null
                          },
                          "dispute_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Dispute status, if disputed",
                            "example": null
                          },
                          "dispute_refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of dispute-related refund, if any",
                            "example": null
                          },
                          "total_bill_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount in the payment's currency",
                            "example": null
                          },
                          "amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Payment amount in the payment's currency",
                            "example": null
                          },
                          "principal_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Principal portion in the payment's currency",
                            "example": null
                          },
                          "total_processing_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total processing fee in the payment's currency",
                            "example": null
                          },
                          "total_international_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total international fee in the payment's currency",
                            "example": null
                          },
                          "total_late_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total late fee in the payment's currency",
                            "example": null
                          },
                          "currency_code": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "ISO currency code of the payment",
                            "example": null
                          },
                          "card_type": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Card brand for card payments (for example visa), or the bank name for bank payments, as reported by the payment processor",
                            "example": "visa"
                          },
                          "last4": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Last four digits of the card or account used for the payment",
                            "example": "4242"
                          },
                          "failure_reason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Why the payment failed",
                            "example": null
                          },
                          "failed_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the payment failed",
                            "example": null
                          },
                          "payment_confirmation_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "When the payment was confirmed, as a local date-time with no time-zone offset. Determines whether a payment counts as completed or still pending.",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "payment_source": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "How the payment was made: MANUAL, AUTO_PAY, SCHEDULED, AUTO_DRAFT, PAYMENT_LINK, CLIENT_PORTAL, PRE_PAYMENT or UNSPECIFIED",
                            "example": "CLIENT_PORTAL"
                          },
                          "payment": {
                            "type": "object",
                            "description": "Details from the payment record behind this row",
                            "required": [
                              "application_fee_amount",
                              "company_name",
                              "created_at",
                              "created_by_contact_id",
                              "created_by_staff_id",
                              "firm_bank_account_id",
                              "is_manual",
                              "payor_name",
                              "posted_to_bank",
                              "refunded_amount",
                              "updated_at"
                            ],
                            "properties": {
                              "application_fee_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Processor application fee charged on the payment",
                                "example": null
                              },
                              "company_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Company name of the payer",
                                "example": null
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was created",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              },
                              "created_by_contact_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Contact who made the payment",
                                "example": null
                              },
                              "created_by_staff_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Staff member who recorded the payment",
                                "example": null
                              },
                              "firm_bank_account_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Firm bank account the payment was deposited into; often empty because not every firm records it",
                                "example": null
                              },
                              "is_manual": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was recorded manually rather than taken through the gateway",
                                "example": false
                              },
                              "payor_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Name of the payer",
                                "example": null
                              },
                              "posted_to_bank": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was posted to the bank",
                                "example": false
                              },
                              "refunded_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Amount refunded",
                                "example": null
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was last updated",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of payment records",
                              "example": 97
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "Typical response with payment data",
                    "value": {
                      "payments": [
                        {
                          "payment_ar_tran_id": 1048,
                          "ar_transaction_date": "2026-09-01T15:00:34.317714",
                          "client_name": "Client Test",
                          "client_ref": "1337",
                          "invoice_numbers": null,
                          "is_aiwyn_payment": true,
                          "is_partial_payment": false,
                          "is_payment_success": true,
                          "notes": "inv 33",
                          "engagement_names": null,
                          "paid_by_full_name": "Client Test",
                          "payment_payment_method": "Bank Transfer",
                          "payment_pp_id": "pi_3UAtArIog7gyKVjp2xxxxx",
                          "refund_date": null,
                          "refund_status": null,
                          "staff_admin_id": true,
                          "status": "Completed",
                          "total_bill_amount": null,
                          "amount": 10,
                          "principal": 10,
                          "total_processing_fee_amount": 0,
                          "total_international_fee_amount": 0,
                          "total_late_fee_amount": 0,
                          "is_posted": false,
                          "posted_to_bank_dt": null,
                          "estimated_deposit_date": null,
                          "dispute_status": null,
                          "dispute_refund_date": null,
                          "total_bill_amount_in_currency": null,
                          "amount_in_currency": null,
                          "principal_in_currency": null,
                          "total_processing_fee_amount_in_currency": null,
                          "total_international_fee_amount_in_currency": null,
                          "total_late_fee_amount_in_currency": null,
                          "currency_code": null,
                          "card_type": "visa",
                          "last4": "4242",
                          "failure_reason": null,
                          "failed_at": null,
                          "payment_confirmation_date": "2026-09-01T15:00:34.317714",
                          "payment_source": "CLIENT_PORTAL",
                          "payment": {
                            "application_fee_amount": null,
                            "company_name": null,
                            "created_at": "2026-09-01T15:00:34.317714+00:00",
                            "created_by_contact_id": null,
                            "created_by_staff_id": null,
                            "firm_bank_account_id": null,
                            "is_manual": false,
                            "payor_name": null,
                            "posted_to_bank": false,
                            "refunded_amount": null,
                            "updated_at": "2026-09-01T15:00:34.317714+00:00"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 97
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No payments (or offset at/beyond total)",
                    "value": {
                      "payments": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination values or an unexpected body property",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "unexpected_variable": {
                    "summary": "Body property other than pageSize/page",
                    "value": {
                      "path": "$",
                      "error": "Unexpected variable clientId",
                      "code": "bad-request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid authentication token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_auth": {
                    "summary": "Missing authentication header",
                    "value": {
                      "error": "Authorization header is required",
                      "code": "MISSING_AUTH_HEADER"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden - insufficient permissions for payment data access",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "insufficient_permissions": {
                    "summary": "Insufficient permissions for payment data",
                    "value": {
                      "error": "Access to payment data requires elevated permissions",
                      "code": "INSUFFICIENT_PAYMENT_PERMISSIONS"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/payments/search": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Search payments",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Payment](/reference/data-dictionary/payment)\n\n**Advanced payment filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports text matching, date ranges, and flags.\n",
        "operationId": "filterPaymentsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "payment_payment_method": {
                            "_ilike": "%card%"
                          }
                        },
                        {
                          "client_name": {
                            "_ilike": "%Acme%"
                          }
                        }
                      ]
                    },
                    {
                      "is_payment_success": {
                        "_eq": true
                      }
                    },
                    {
                      "ar_transaction_date": {
                        "_gte": "1900-01-01T00:00:00"
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "ar_transaction_date": "desc"
                  },
                  {
                    "client_name": "asc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex payment filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "payment_payment_method": {
                                "_ilike": "%card%"
                              }
                            },
                            {
                              "client_name": {
                                "_ilike": "%Acme%"
                              }
                            }
                          ]
                        },
                        {
                          "is_payment_success": {
                            "_eq": true
                          }
                        },
                        {
                          "ar_transaction_date": {
                            "_gte": "1900-01-01T00:00:00"
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications",
                    "example": [
                      {
                        "ar_transaction_date": "desc"
                      },
                      {
                        "client_name": "asc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered payments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "payments",
                    "total"
                  ],
                  "properties": {
                    "payments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "payment_ar_tran_id",
                          "ar_transaction_date",
                          "client_name",
                          "client_ref",
                          "invoice_numbers",
                          "is_aiwyn_payment",
                          "is_partial_payment",
                          "is_payment_success",
                          "notes",
                          "engagement_names",
                          "paid_by_full_name",
                          "payment_payment_method",
                          "payment_pp_id",
                          "refund_date",
                          "refund_status",
                          "staff_admin_id",
                          "status",
                          "total_bill_amount",
                          "amount",
                          "principal",
                          "total_processing_fee_amount",
                          "total_international_fee_amount",
                          "total_late_fee_amount",
                          "is_posted",
                          "posted_to_bank_dt",
                          "estimated_deposit_date",
                          "dispute_status",
                          "dispute_refund_date",
                          "total_bill_amount_in_currency",
                          "amount_in_currency",
                          "principal_in_currency",
                          "total_processing_fee_amount_in_currency",
                          "total_international_fee_amount_in_currency",
                          "total_late_fee_amount_in_currency",
                          "currency_code",
                          "card_type",
                          "last4",
                          "failure_reason",
                          "failed_at",
                          "payment_confirmation_date",
                          "payment_source",
                          "payment"
                        ],
                        "properties": {
                          "payment_ar_tran_id": {
                            "type": "integer",
                            "description": "AR transaction id of the payment",
                            "example": 1048
                          },
                          "ar_transaction_date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Date/time of the AR transaction, as a local date-time with no time-zone offset",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "client_name": {
                            "type": "string",
                            "description": "Name of the client the payment belongs to",
                            "example": "Acme Corporation"
                          },
                          "client_ref": {
                            "type": "string",
                            "description": "External client reference number",
                            "example": "1337"
                          },
                          "invoice_numbers": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Comma-separated invoice numbers the payment is applied to",
                            "example": null
                          },
                          "is_aiwyn_payment": {
                            "type": "boolean",
                            "description": "Whether the payment was created through Aiwyn",
                            "example": true
                          },
                          "is_partial_payment": {
                            "type": "boolean",
                            "description": "Whether the payment only partially covers the billed amount",
                            "example": false
                          },
                          "is_payment_success": {
                            "type": "boolean",
                            "description": "Whether the payment succeeded",
                            "example": true
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Free-text notes on the payment",
                            "example": "Paid by check"
                          },
                          "engagement_names": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Names of engagements associated with the payment",
                            "example": null
                          },
                          "paid_by_full_name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Full name of the payer",
                            "example": "Jane Doe"
                          },
                          "payment_payment_method": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Human-readable payment method",
                            "example": "Bank Transfer"
                          },
                          "payment_pp_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Payment processor (Stripe) identifier",
                            "example": "pi_3UAtArIog7gyKVjp2cNQXIBJ"
                          },
                          "refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of refund, if refunded",
                            "example": null
                          },
                          "refund_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Refund status, if refunded",
                            "example": null
                          },
                          "staff_admin_id": {
                            "type": "boolean",
                            "description": "Staff/admin association flag",
                            "example": true
                          },
                          "status": {
                            "type": "string",
                            "description": "Human-readable payment status",
                            "example": "Completed"
                          },
                          "total_bill_amount": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount",
                            "example": null
                          },
                          "amount": {
                            "type": "number",
                            "description": "Payment amount",
                            "example": 10
                          },
                          "principal": {
                            "type": "number",
                            "description": "Principal portion of the payment",
                            "example": 10
                          },
                          "total_processing_fee_amount": {
                            "type": "number",
                            "description": "Total processing fee amount",
                            "example": 0
                          },
                          "total_international_fee_amount": {
                            "type": "number",
                            "description": "Total international fee amount",
                            "example": 0
                          },
                          "total_late_fee_amount": {
                            "type": "number",
                            "description": "Total late fee amount",
                            "example": 0
                          },
                          "is_posted": {
                            "type": "boolean",
                            "description": "Whether the payment has been posted to the bank",
                            "example": false
                          },
                          "posted_to_bank_dt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Date/time the payment was posted to the bank",
                            "example": null
                          },
                          "estimated_deposit_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Estimated deposit date, as a local date-time with no time-zone offset",
                            "example": null
                          },
                          "dispute_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Dispute status, if disputed",
                            "example": null
                          },
                          "dispute_refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of dispute-related refund, if any",
                            "example": null
                          },
                          "total_bill_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount in the payment's currency",
                            "example": null
                          },
                          "amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Payment amount in the payment's currency",
                            "example": null
                          },
                          "principal_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Principal portion in the payment's currency",
                            "example": null
                          },
                          "total_processing_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total processing fee in the payment's currency",
                            "example": null
                          },
                          "total_international_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total international fee in the payment's currency",
                            "example": null
                          },
                          "total_late_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total late fee in the payment's currency",
                            "example": null
                          },
                          "currency_code": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "ISO currency code of the payment",
                            "example": null
                          },
                          "card_type": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Card brand for card payments (for example visa), or the bank name for bank payments, as reported by the payment processor",
                            "example": "visa"
                          },
                          "last4": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Last four digits of the card or account used for the payment",
                            "example": "4242"
                          },
                          "failure_reason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Why the payment failed",
                            "example": null
                          },
                          "failed_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the payment failed",
                            "example": null
                          },
                          "payment_confirmation_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "When the payment was confirmed, as a local date-time with no time-zone offset. Determines whether a payment counts as completed or still pending.",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "payment_source": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "How the payment was made: MANUAL, AUTO_PAY, SCHEDULED, AUTO_DRAFT, PAYMENT_LINK, CLIENT_PORTAL, PRE_PAYMENT or UNSPECIFIED",
                            "example": "CLIENT_PORTAL"
                          },
                          "payment": {
                            "type": "object",
                            "description": "Details from the payment record behind this row",
                            "required": [
                              "application_fee_amount",
                              "company_name",
                              "created_at",
                              "created_by_contact_id",
                              "created_by_staff_id",
                              "firm_bank_account_id",
                              "is_manual",
                              "payor_name",
                              "posted_to_bank",
                              "refunded_amount",
                              "updated_at"
                            ],
                            "properties": {
                              "application_fee_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Processor application fee charged on the payment",
                                "example": null
                              },
                              "company_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Company name of the payer",
                                "example": null
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was created",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              },
                              "created_by_contact_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Contact who made the payment",
                                "example": null
                              },
                              "created_by_staff_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Staff member who recorded the payment",
                                "example": null
                              },
                              "firm_bank_account_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Firm bank account the payment was deposited into; often empty because not every firm records it",
                                "example": null
                              },
                              "is_manual": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was recorded manually rather than taken through the gateway",
                                "example": false
                              },
                              "payor_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Name of the payer",
                                "example": null
                              },
                              "posted_to_bank": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was posted to the bank",
                                "example": false
                              },
                              "refunded_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Amount refunded",
                                "example": null
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was last updated",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of payments matching the where clause",
                              "example": 12
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/payment/{id}": {
      "get": {
        "tags": [
          "Payments"
        ],
        "summary": "Get payment by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Payment](/reference/data-dictionary/payment)\n\n**Retrieve a specific payment by its unique identifier**\n\nThis endpoint provides detailed payment information including:\n- Complete payment transaction details\n- PCI-compliant payment method information (masked)\n- Payment status and confirmation data\n- Associated invoice and client relationships\n- Payment processor integration details\n- Audit trail and security compliance data\n\n**Security & Compliance:**\n- PCI DSS compliant data handling\n- Secure payment processor ID tracking\n- Payment confirmation date logging\n- Audit trail for payment processing\n\n**Payment Details Include:**\n- Payment amount and currency\n- Payment method (masked for security)\n- Payment status and confirmation\n- Associated invoice references\n- Client relationship data\n- Payment processor details\n\n**Business Applications:**\n- Payment verification and reconciliation\n- Client payment history lookup\n- Payment dispute resolution\n- Audit and compliance reporting\n- Payment method analysis\n\nThe `payment` field is an array containing at most one record. An id that\nmatches no payment returns 200 with `\"payment\": []`; the endpoint never\nreturns 404.\n\n**Response Example:**\n```json\n{\n  \"payment\": [\n    {\n      \"payment_ar_tran_id\": 1048,\n      \"ar_transaction_date\": \"2026-09-01T15:00:34.317714\",\n      \"client_name\": \"Acme Corporation\",\n      \"client_ref\": \"1337\",\n      \"invoice_numbers\": null,\n      \"is_aiwyn_payment\": true,\n      \"is_partial_payment\": false,\n      \"is_payment_success\": true,\n      \"notes\": \"Paid by check\",\n      \"engagement_names\": null,\n      \"paid_by_full_name\": \"Jane Doe\",\n      \"payment_payment_method\": \"Bank Transfer\",\n      \"payment_pp_id\": \"pi_3UAtArIog7gyKVjp2cNQXIBJ\",\n      \"refund_date\": null,\n      \"refund_status\": null,\n      \"staff_admin_id\": true,\n      \"status\": \"Completed\",\n      \"total_bill_amount\": null,\n      \"amount\": 10,\n      \"principal\": 10,\n      \"total_processing_fee_amount\": 0,\n      \"total_international_fee_amount\": 0,\n      \"total_late_fee_amount\": 0,\n      \"is_posted\": false,\n      \"posted_to_bank_dt\": null,\n      \"estimated_deposit_date\": null,\n      \"dispute_status\": null,\n      \"dispute_refund_date\": null,\n      \"total_bill_amount_in_currency\": null,\n      \"amount_in_currency\": null,\n      \"principal_in_currency\": null,\n      \"total_processing_fee_amount_in_currency\": null,\n      \"total_international_fee_amount_in_currency\": null,\n      \"total_late_fee_amount_in_currency\": null,\n      \"currency_code\": null\n    }\n  ]\n}\n```\n",
        "operationId": "getPaymentById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the payment",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 12345
          }
        ],
        "responses": {
          "200": {
            "description": "Payment lookup completed. `payment` holds the matching payment, or is an\nempty array when no payment has this id.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "payment"
                  ],
                  "properties": {
                    "payment": {
                      "type": "array",
                      "description": "Array containing the matching payment (empty if not found)",
                      "maxItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "payment_ar_tran_id",
                          "ar_transaction_date",
                          "client_name",
                          "client_ref",
                          "invoice_numbers",
                          "is_aiwyn_payment",
                          "is_partial_payment",
                          "is_payment_success",
                          "notes",
                          "engagement_names",
                          "paid_by_full_name",
                          "payment_payment_method",
                          "payment_pp_id",
                          "refund_date",
                          "refund_status",
                          "staff_admin_id",
                          "status",
                          "total_bill_amount",
                          "amount",
                          "principal",
                          "total_processing_fee_amount",
                          "total_international_fee_amount",
                          "total_late_fee_amount",
                          "is_posted",
                          "posted_to_bank_dt",
                          "estimated_deposit_date",
                          "dispute_status",
                          "dispute_refund_date",
                          "total_bill_amount_in_currency",
                          "amount_in_currency",
                          "principal_in_currency",
                          "total_processing_fee_amount_in_currency",
                          "total_international_fee_amount_in_currency",
                          "total_late_fee_amount_in_currency",
                          "currency_code",
                          "card_type",
                          "last4",
                          "failure_reason",
                          "failed_at",
                          "payment_confirmation_date",
                          "payment_source",
                          "payment"
                        ],
                        "properties": {
                          "payment_ar_tran_id": {
                            "type": "integer",
                            "description": "AR transaction id of the payment (the id used by this endpoint)",
                            "example": 1048
                          },
                          "ar_transaction_date": {
                            "type": "string",
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Date/time of the AR transaction, as a local date-time with no time-zone offset",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "client_name": {
                            "type": "string",
                            "description": "Name of the client the payment belongs to",
                            "example": "Acme Corporation"
                          },
                          "client_ref": {
                            "type": "string",
                            "description": "External client reference number",
                            "example": "1337"
                          },
                          "invoice_numbers": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Comma-separated invoice numbers the payment is applied to",
                            "example": null
                          },
                          "is_aiwyn_payment": {
                            "type": "boolean",
                            "description": "Whether the payment was created through Aiwyn",
                            "example": true
                          },
                          "is_partial_payment": {
                            "type": "boolean",
                            "description": "Whether the payment only partially covers the billed amount",
                            "example": false
                          },
                          "is_payment_success": {
                            "type": "boolean",
                            "description": "Whether the payment succeeded",
                            "example": true
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Free-text notes on the payment",
                            "example": "Paid by check"
                          },
                          "engagement_names": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Names of engagements associated with the payment",
                            "example": null
                          },
                          "paid_by_full_name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Full name of the payer",
                            "example": "Jane Doe"
                          },
                          "payment_payment_method": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Human-readable payment method",
                            "example": "Bank Transfer"
                          },
                          "payment_pp_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Payment processor (Stripe) identifier",
                            "example": "pi_3UAtArIog7gyKVjp2cNQXIBJ"
                          },
                          "refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of refund, if refunded",
                            "example": null
                          },
                          "refund_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Refund status, if refunded",
                            "example": null
                          },
                          "staff_admin_id": {
                            "type": "boolean",
                            "description": "Staff/admin association flag",
                            "example": true
                          },
                          "status": {
                            "type": "string",
                            "description": "Human-readable payment status",
                            "example": "Completed"
                          },
                          "total_bill_amount": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount",
                            "example": null
                          },
                          "amount": {
                            "type": "number",
                            "description": "Payment amount",
                            "example": 10
                          },
                          "principal": {
                            "type": "number",
                            "description": "Principal portion of the payment",
                            "example": 10
                          },
                          "total_processing_fee_amount": {
                            "type": "number",
                            "description": "Total processing fee amount",
                            "example": 0
                          },
                          "total_international_fee_amount": {
                            "type": "number",
                            "description": "Total international fee amount",
                            "example": 0
                          },
                          "total_late_fee_amount": {
                            "type": "number",
                            "description": "Total late fee amount",
                            "example": 0
                          },
                          "is_posted": {
                            "type": "boolean",
                            "description": "Whether the payment has been posted to the bank",
                            "example": false
                          },
                          "posted_to_bank_dt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Date/time the payment was posted to the bank",
                            "example": null
                          },
                          "estimated_deposit_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "Estimated deposit date, as a local date-time with no time-zone offset",
                            "example": null
                          },
                          "dispute_status": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Dispute status, if disputed",
                            "example": null
                          },
                          "dispute_refund_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Date of dispute-related refund, if any",
                            "example": null
                          },
                          "total_bill_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total billed amount in the payment's currency",
                            "example": null
                          },
                          "amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Payment amount in the payment's currency",
                            "example": null
                          },
                          "principal_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Principal portion in the payment's currency",
                            "example": null
                          },
                          "total_processing_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total processing fee in the payment's currency",
                            "example": null
                          },
                          "total_international_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total international fee in the payment's currency",
                            "example": null
                          },
                          "total_late_fee_amount_in_currency": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Total late fee in the payment's currency",
                            "example": null
                          },
                          "currency_code": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "ISO currency code of the payment",
                            "example": null
                          },
                          "card_type": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Card brand for card payments (for example visa), or the bank name for bank payments, as reported by the payment processor",
                            "example": "visa"
                          },
                          "last4": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Last four digits of the card or account used for the payment",
                            "example": "4242"
                          },
                          "failure_reason": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Why the payment failed",
                            "example": null
                          },
                          "failed_at": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the payment failed",
                            "example": null
                          },
                          "payment_confirmation_date": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
                            "description": "When the payment was confirmed, as a local date-time with no time-zone offset. Determines whether a payment counts as completed or still pending.",
                            "example": "2026-09-01T15:00:34.317714"
                          },
                          "payment_source": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "How the payment was made: MANUAL, AUTO_PAY, SCHEDULED, AUTO_DRAFT, PAYMENT_LINK, CLIENT_PORTAL, PRE_PAYMENT or UNSPECIFIED",
                            "example": "CLIENT_PORTAL"
                          },
                          "payment": {
                            "type": "object",
                            "description": "Details from the payment record behind this row",
                            "required": [
                              "application_fee_amount",
                              "company_name",
                              "created_at",
                              "created_by_contact_id",
                              "created_by_staff_id",
                              "firm_bank_account_id",
                              "is_manual",
                              "payor_name",
                              "posted_to_bank",
                              "refunded_amount",
                              "updated_at"
                            ],
                            "properties": {
                              "application_fee_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Processor application fee charged on the payment",
                                "example": null
                              },
                              "company_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Company name of the payer",
                                "example": null
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was created",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              },
                              "created_by_contact_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Contact who made the payment",
                                "example": null
                              },
                              "created_by_staff_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Staff member who recorded the payment",
                                "example": null
                              },
                              "firm_bank_account_id": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Firm bank account the payment was deposited into; often empty because not every firm records it",
                                "example": null
                              },
                              "is_manual": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was recorded manually rather than taken through the gateway",
                                "example": false
                              },
                              "payor_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Name of the payer",
                                "example": null
                              },
                              "posted_to_bank": {
                                "type": [
                                  "boolean",
                                  "null"
                                ],
                                "description": "Whether the payment was posted to the bank",
                                "example": false
                              },
                              "refunded_amount": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "Amount refunded",
                                "example": null
                              },
                              "updated_at": {
                                "type": "string",
                                "format": "date-time",
                                "description": "When the payment record was last updated",
                                "example": "2026-09-01T15:00:34.317714+00:00"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "example": "invalid input syntax for type integer: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "example": "data-exception"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this payment"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/clients/v1/link/payment": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Create a payment link for a client",
        "description": "> 🔐 **Required role:** `PAYLNK_C` or `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Payment](/reference/data-dictionary/payment)\n\n**Create a single-use quick payment link that lets a client pay in the Aiwyn payment portal**\n\nThe client is resolved by `clientRef`, the same identifier the client carries in the firm's\npractice management system. Exactly one active client must match.\n\nThe link is locked to the arguments given: the payer sees the selected invoices, the amount and\nthe note prefilled and cannot change them, and the link accepts one payment. Use it to gate a\ndeliverable behind a specific invoice. At least one of `invoiceIds`, `invoiceNumbers`, `amount`,\n`note`, `returnUrl`, `returnLabel`, `returnAutomatically`, `metadata` or `expiresInDays` must be present; a body carrying only `clientRef` is rejected\nwith `400`, because this route never issues a link to the client's full account. Invoices must\nbelong to the client and must be unpaid; use `GET /api/v1/invoices/unpaid` to list them. The link\nid (the `qpLink` query parameter of the returned URL) is shown only in this response and is never\nstored: the `Payment` webhook events the payment raises carry its lowercase hex SHA-256 as\n`metadata.paymentLinkPlIdSha256` and the link's id as `metadata.paymentLinkId`, so a payment can be\nmatched to the link that produced it by hashing the `qpLink` value. The events no longer carry\n`metadata.paymentLinkPlId`.\n\n`metadata` attaches up to 20 key-value pairs of your own to the link, such as the id of the\nreturn or the order the payment is for. Keys are 1 to 40 letters, digits, underscores or hyphens;\nvalues are strings of at most 500 printable characters. The payer never sees them. They are echoed\nback unchanged as `metadata.paymentLinkMetadata` on the `Payment` webhook events the link's\npayment raises, so you can match the payment to your records without storing the link id. Only\nyour own subscriptions (those of the API user that created the link) receive them; another API user\nof the firm with a firm-wide Payment subscription gets the event without them. Use identifiers, not\ntaxpayer names or other personal data.\n\nA link stays payable for 14 days after it is created. `expiresInDays` sets a different lifetime: one of\n`7`, `14`, `30`, `60` or `90`. Any other value is rejected with `400` and `extensions.details.reason`\n`INVALID_EXPIRY`, and no link is created. Create the link with a lifetime that covers the time the payer\nneeds; once it expires, create a new one.\n\nA quick payment link can carry a `returnUrl`. After a successful payment the portal sends the payer back to it (the URL is disclosed only on the charge result, never when the link is opened). The URL must be `https` and its host must be on the firm's `payment_return_url_allowed_hosts` configuration; a firm without that configuration rejects any `returnUrl` with `400`. A link that carries a `returnUrl` must also name invoices (`invoiceIds` or `invoiceNumbers`) or an `amount`: the portal releases the URL only once the link is paid in full, and a link with neither has no full amount to check, so it is rejected with `400` and `extensions.details.reason` `RETURN_URL_REQUIRES_OBLIGATION`. `returnLabel` names that destination on the return button. `returnAutomatically: true` asks the portal to return on its own after the confirmation, after a short countdown, instead of waiting for the payer to press the button: it navigates to `returnUrl` when the link has one, and otherwise closes the payment tab, which it can do only when your system opened that tab by script.\n\nThe body is decoded strictly: a key that is not one of `clientRef`, `invoiceIds`, `invoiceNumbers`,\n`amount`, `note`, `returnUrl`, `returnLabel`, `returnAutomatically`, `metadata`, `expiresInDays` is rejected with `400` instead\nof being ignored.\n",
        "operationId": "createClientPaymentLink",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "clientRef"
                ],
                "properties": {
                  "clientRef": {
                    "type": "string",
                    "description": "Client reference of the client the link is for. Exactly one active client must match.",
                    "example": "ACME-001"
                  },
                  "invoiceIds": {
                    "type": "array",
                    "items": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "description": "Unpaid invoices of the client to lock the link to, by invoice `id`. At most 100 invoices per link, counted together with `invoiceNumbers`.",
                    "example": [
                      125890
                    ]
                  },
                  "invoiceNumbers": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Unpaid invoices of the client to lock the link to, by invoice number. Resolved to the same invoices as `invoiceIds`; an invoice given both ways is counted once.",
                    "example": [
                      "INV-2026-4850"
                    ]
                  },
                  "amount": {
                    "type": "string",
                    "description": "Amount the payer is asked for, decimal with at most two decimal places. Accepted as a JSON number as well. Omit to let the invoices' outstanding balance drive the amount.",
                    "example": "1000.00"
                  },
                  "note": {
                    "type": "string",
                    "description": "Free text shown to the payer. Treated as sensitive; it is never written to logs.",
                    "example": "2025 individual tax return"
                  },
                  "returnUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "Where the portal sends the payer once the link is paid in full. `https` only, host must be allow-listed for the firm. Requires `invoiceIds`, `invoiceNumbers` or `amount`.",
                    "example": "https://app.safesend.example/returns/42"
                  },
                  "returnLabel": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "Name of the destination shown on the return control, plain text. Requires `returnUrl`.",
                    "example": "SafeSend"
                  },
                  "returnAutomatically": {
                    "type": "boolean",
                    "default": false,
                    "description": "Return on its own after the payment confirmation, after a short countdown, instead of waiting for the payer to press the return button. With `returnUrl` the portal navigates there; without one it closes the payment tab, which only works when your system opened the tab by script. Makes the link a quick payment link even on its own.",
                    "example": true
                  },
                  "metadata": {
                    "type": "object",
                    "maxProperties": 20,
                    "additionalProperties": {
                      "type": "string",
                      "maxLength": 500
                    },
                    "description": "Your own key-value pairs, echoed back as `metadata.paymentLinkMetadata` on the `Payment` webhook events. At most 20 keys; each key 1 to 40 letters, digits, underscores or hyphens; each value at most 500 printable characters. Never shown to the payer, and delivered only to the subscriptions of the API user that created the link; do not put personal data in it. Makes the link a quick payment link even on its own.",
                    "example": {
                      "returnId": "R-42",
                      "taxYear": "2025"
                    }
                  },
                  "expiresInDays": {
                    "type": "integer",
                    "format": "int64",
                    "enum": [
                      7,
                      14,
                      30,
                      60,
                      90
                    ],
                    "description": "Days the link stays payable after it is created. Defaults to 14 when left out. Makes the link a quick payment link even on its own.",
                    "example": 30
                  }
                }
              },
              "examples": {
                "invoiceLocked": {
                  "summary": "Quick payment link locked to one invoice, returning to the caller afterwards",
                  "value": {
                    "clientRef": "ACME-001",
                    "invoiceIds": [
                      125890
                    ],
                    "note": "2025 individual tax return",
                    "returnUrl": "https://app.safesend.example/returns/42",
                    "returnLabel": "SafeSend",
                    "returnAutomatically": true,
                    "metadata": {
                      "returnId": "R-42"
                    }
                  }
                },
                "amountOnly": {
                  "summary": "Quick payment link for an amount with no invoice",
                  "value": {
                    "clientRef": "ACME-001",
                    "amount": "500.00",
                    "note": "Retainer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Client was found and the payment link returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "response": {
                      "type": "string",
                      "description": "URL to hand to the payer. For a quick payment link the `qpLink` query parameter is the link id.",
                      "example": "https://acme.aiwyn.app/client-portal/payments?qpLink=qpl_9f1c2a7b3d4e5f60718293a4b5c6d7e8"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "One of five rejections, told apart by `message` and `extensions.details.reason`:\n\n- The body could not be parsed or contains an unknown key. `extensions.details.reason` is\n  `INVALID_REQUEST_BODY`.\n- The body carries no quick payment link argument. `extensions.details.reason` is\n  `QUICK_PAYMENT_LINK_ARGUMENTS_REQUIRED`.\n- The body carries a `returnUrl` but neither invoices (`invoiceIds`, `invoiceNumbers`) nor an `amount`. Nothing is created. `message` starts with `RETURN_URL_REQUIRES_OBLIGATION:` and `extensions.details.reason` is `RETURN_URL_REQUIRES_OBLIGATION`.\n- `clientRef` matches no client or more than one: `Multiple or no clients found for the\n  reference provided.`\n- An embedded argument was rejected: `The invoice, amount or note provided cannot be used to\n  build a payment link for this client.` Causes: an invoice does not exist, is not open, or\n  belongs to another client; more than 100 invoices; an amount with more than two decimal\n  places; a `returnUrl` that is not `https`, whose host is not allow-listed, or sent to a firm\n  with no allow-list; a `returnLabel` without a `returnUrl`; `metadata` with more than 20 keys, a key outside\n  the allowed shape, or a value over 500 characters. The exact cause is written to\n  Aiwyn's server log, not to the response, because it can echo caller data. Check the input\n  against `GET /api/v1/invoices/unpaid` and the firm's allow-list.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "The invoice, amount or note provided cannot be used to build a payment link for this client."
                    },
                    "extensions": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "integer",
                          "example": 400
                        },
                        "details": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "properties": {
                            "reason": {
                              "type": "string",
                              "example": "RETURN_URL_REQUIRES_OBLIGATION"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "One of two refusals:\n\n- The caller lacks the PAYLNK_C or API_ADMIN role.\n- Quick payment links are not enabled for this firm. Aiwyn enables them per firm; until then\n  every request is refused, nothing is created, and retrying does not help. `message` starts\n  with `QUICK_PAYMENT_LINKS_DISABLED:` and `extensions.details.reason` is\n  `QUICK_PAYMENT_LINKS_DISABLED`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "QUICK_PAYMENT_LINKS_DISABLED: Quick payment links are not enabled for this firm"
                    },
                    "extensions": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "integer",
                          "example": 403
                        },
                        "details": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "properties": {
                            "reason": {
                              "type": "string",
                              "example": "QUICK_PAYMENT_LINKS_DISABLED"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/projects": {
      "post": {
        "tags": [
          "Projects"
        ],
        "summary": "List projects",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Retrieve all projects with basic pagination support**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nDefault ordering by `updatedAt` desc.\n",
        "operationId": "getProjectsPaginated",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count)."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved projects",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectListResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid pagination parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/projects/search": {
      "post": {
        "tags": [
          "Projects"
        ],
        "summary": "Search projects",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Advanced project filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nProjects are stored in the Jobs table (vw_job view). Supports manager, dates, and flags.\n`where` and `orderBy` use the project field names of the response (camelCase, for example\n`status`, `isActive`, `partnerStaffId`, `managerStaffId`, `updatedAt`); an unknown field is\nrejected with 400. The response holds the matching rows in `projects` and the number of\nprojects matching `where` in `total.aggregate.count`.\n",
        "operationId": "filterProjectsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "name": {
                            "_ilike": "%migration%"
                          }
                        },
                        {
                          "serviceDescription": {
                            "_ilike": "%review%"
                          }
                        }
                      ]
                    },
                    {
                      "isActive": {
                        "_eq": true
                      }
                    },
                    {
                      "updatedAt": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "partnerStaffId": {
                        "_in": [
                          101,
                          102,
                          103
                        ]
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "updatedAt": "desc"
                  },
                  {
                    "name": "asc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N`\nand `page: N`. An offset at or beyond `total.aggregate.count`\nreturns an empty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex project filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "name": {
                                "_ilike": "%migration%"
                              }
                            },
                            {
                              "serviceDescription": {
                                "_ilike": "%review%"
                              }
                            }
                          ]
                        },
                        {
                          "isActive": {
                            "_eq": true
                          }
                        },
                        {
                          "updatedAt": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "partnerStaffId": {
                            "_in": [
                              101,
                              102,
                              103
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications",
                    "example": [
                      {
                        "updatedAt": "desc"
                      },
                      {
                        "name": "asc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered projects",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectListResponse"
                },
                "examples": {
                  "projects": {
                    "summary": "A page of projects",
                    "value": {
                      "projects": [
                        {
                          "id": 5012,
                          "name": "Q1 Financial Review 2024",
                          "startDate": "2024-01-01T00:00:00Z",
                          "targetEndDate": "2024-03-31T23:59:59Z",
                          "dueDate": "2024-03-15T00:00:00Z",
                          "targetStartDate": "2023-12-01T00:00:00Z",
                          "pmsRef": "JOB-2024-115",
                          "isCreatedByAiwyn": true,
                          "managerStaffId": 102,
                          "partnerStaffId": 101,
                          "status": "ACTIVE",
                          "updatedAt": "2024-05-20T12:34:56.123456+00:00",
                          "jobStatus": {
                            "id": 4,
                            "name": "In Progress",
                            "state": "ACTIVE"
                          },
                          "client": {
                            "id": 2180,
                            "name": "TechFlow Enterprises",
                            "clientRef": "TF-2024-789",
                            "clientGroup": {
                              "id": 12,
                              "name": "Enterprise"
                            }
                          },
                          "managerStaff": {
                            "id": 102,
                            "firstName": "Lisa",
                            "lastName": "Rodriguez",
                            "email": "lisa.rodriguez@company.com"
                          },
                          "partnerStaff": {
                            "id": 101,
                            "firstName": "Michael",
                            "lastName": "Chen",
                            "email": "michael.chen@company.com"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 137
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$.selectionSet.aiwynreleasecut_vw_job.args.where._and[1].active"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "field 'active' not found in type: 'aiwynreleasecut_vw_job_bool_exp'"
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "validation-failed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/project/{id}": {
      "get": {
        "tags": [
          "Projects"
        ],
        "summary": "Get project by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Retrieve a specific project by its unique identifier**\n\nThe project is returned in a `project` array that holds at most one row, with the same\nrow shape as the project list and search operations: dates, status, fee structure,\nclient, project owner, partner and service lines.\n\nAn id that matches no project returns 200 with `\"project\": []`; this operation never\nreturns 404. A non-numeric id returns 400.\n\n**Response Example:**\n```json\n{\n  \"project\": [\n    {\n      \"id\": 1703,\n      \"name\": \"Tax: General Tax Consulting\",\n      \"startDate\": null,\n      \"endDate\": null,\n      \"dueDate\": null,\n      \"targetStartDate\": \"2026-10-08\",\n      \"targetedStartDate\": \"2026-10-08\",\n      \"targetEndDate\": \"2026-10-31\",\n      \"targetedEndDate\": \"2026-10-31\",\n      \"feeStructureId\": null,\n      \"pmsRef\": \"AIWYN_1703\",\n      \"isCreatedByAiwyn\": true,\n      \"managerStaffId\": null,\n      \"partnerStaffId\": null,\n      \"serviceId\": null,\n      \"serviceDescription\": \"Tax: General Tax Consulting\",\n      \"extendedServiceDescription\": null,\n      \"status\": \"DRAFT\",\n      \"createdAt\": \"2026-10-08T15:17:05.651201+00:00\",\n      \"updatedAt\": \"2026-10-08T15:17:05.685193+00:00\",\n      \"customFieldValues\": null,\n      \"sysRefs\": {},\n      \"feeStructureV4\": null,\n      \"client\": { \"id\": 281, \"name\": \"Ettore Test Over\", \"clientRef\": \"9001726\" },\n      \"projectOwner\": null,\n      \"partnerStaff\": null,\n      \"jobServiceLines\": []\n    }\n  ]\n}\n```\n",
        "operationId": "getProjectById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the project",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1703
          }
        ],
        "responses": {
          "200": {
            "description": "Project lookup completed. `project` holds the project, or is empty when no project\nhas this id.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "project"
                  ],
                  "properties": {
                    "project": {
                      "type": "array",
                      "maxItems": 1,
                      "description": "The project, or an empty array when the id matches no project",
                      "items": {
                        "$ref": "#/components/schemas/Project"
                      }
                    }
                  }
                },
                "examples": {
                  "not_found": {
                    "summary": "No project with this id",
                    "value": {
                      "project": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "code"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "invalid input syntax for type integer: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "data-exception"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\"",
                      "path": "$"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this project"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/projects/create_from_template": {
      "post": {
        "tags": [
          "Projects"
        ],
        "summary": "Create one or more jobs from job templates",
        "description": "> 🔐 **Required role:** `PROJ_C`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Create jobs from job templates**\n\nCreates one or more jobs for a client from job templates. Up to 100 templates\nmay be provided in a single request. Each entry in `jobTemplates` can override\nfield-level defaults defined on the template.\n\n**Required fields:**\n- `clientId` — the client for whom the jobs are being created\n- `jobTemplates` — list of job templates to instantiate (1–100 entries)\n  - `jobTemplateId` — the template to create a job from\n\n**Optional per-template overrides** (each overrides the template default if provided):\n- `startDate` — job start date\n- `name` — job name\n- `serviceDescription` — service description\n- `estimationHours` — estimated hours\n- `feeAmount` — fee amount\n- `requiredPrepayment` — required prepayment amount\n- `includeWipType` — WIP billing behavior (`INCLUDE_WIP`, `INCLUDE_WIP_IF_FINAL`, `DO_NOT_INCLUDE`)\n",
        "operationId": "createProjectsFromTemplate",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "clientId",
                  "jobTemplates"
                ],
                "properties": {
                  "clientId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Unique identifier of the client for whom jobs are being created",
                    "example": 420
                  },
                  "jobTemplates": {
                    "type": "array",
                    "description": "List of job templates to instantiate (1–100 entries)",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": [
                        "jobTemplateId"
                      ],
                      "properties": {
                        "jobTemplateId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Unique identifier of the job template to use",
                          "example": 7
                        },
                        "startDate": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date",
                          "description": "Job start date (YYYY-MM-DD); overrides the template default",
                          "example": "2025-01-01"
                        },
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Job name; overrides the template default",
                          "example": "Tax Return 2024"
                        },
                        "serviceDescription": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Service description; overrides the template default",
                          "example": "Annual federal and state tax preparation"
                        },
                        "estimationHours": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Estimated hours for the job; overrides the template default",
                          "example": 8.5
                        },
                        "feeAmount": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Fee amount for the job; overrides the template default",
                          "example": 1500
                        },
                        "requiredPrepayment": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "Required prepayment amount; overrides the template default",
                          "example": 500
                        },
                        "includeWipType": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "WIP billing behavior; overrides the template default",
                          "enum": [
                            "INCLUDE_WIP",
                            "INCLUDE_WIP_IF_FINAL",
                            "DO_NOT_INCLUDE",
                            null
                          ],
                          "example": "INCLUDE_WIP_IF_FINAL"
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "minimal": {
                  "summary": "Single job from template, no overrides",
                  "value": {
                    "clientId": 420,
                    "jobTemplates": [
                      {
                        "jobTemplateId": 7
                      }
                    ]
                  }
                },
                "full": {
                  "summary": "Multiple jobs with field overrides",
                  "value": {
                    "clientId": 420,
                    "jobTemplates": [
                      {
                        "jobTemplateId": 7,
                        "startDate": "2025-01-01",
                        "name": "Tax Return 2024",
                        "serviceDescription": "Annual federal and state tax preparation",
                        "estimationHours": 8.5,
                        "feeAmount": 1500,
                        "requiredPrepayment": 500,
                        "includeWipType": "INCLUDE_WIP_IF_FINAL"
                      },
                      {
                        "jobTemplateId": 12,
                        "startDate": "2025-02-01",
                        "name": "Bookkeeping Q1 2025"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Jobs created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "description": "List of IDs for the newly created jobs"
                },
                "examples": {
                  "success": {
                    "summary": "Two jobs created",
                    "value": [
                      1001,
                      1002
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires ROLE_PROJ_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/projects/assign_staff": {
      "post": {
        "tags": [
          "Projects"
        ],
        "summary": "Assign staff to a project",
        "description": "\n> 🔐 **Required role:** `PROJ_C`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Assign staff to a project**\n\nCreates associations between staff members and a job:\n- ``staffJobAssignments``: assigns staff directly to the job via ``staff_job`` records\n- ``staffTaskAssignments``: assigns staff to specific task types on the job via ``task_type_staff_job`` records\n\nIf an association already exists but is inactive, it will be re-activated.\n\nReturns the IDs of created or re-activated records as\n``{\"staffJobIds\": [<staff_job id>, ...], \"staffTaskIds\": [<task_type_staff_job id>, ...]}``.\n",
        "operationId": "AssignStaffToProject",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "jobId": 5001,
                "staffJobAssignments": [
                  {
                    "staffId": 103
                  },
                  {
                    "staffId": 104
                  }
                ],
                "staffTaskAssignments": [
                  {
                    "staffId": 103,
                    "taskTypeId": 10
                  },
                  {
                    "staffId": 104,
                    "taskTypeId": 11
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "jobId"
                ],
                "properties": {
                  "jobId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Jobid"
                  },
                  "staffJobAssignments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "staffId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Staffid"
                        }
                      }
                    },
                    "description": "Staffjobassignments"
                  },
                  "staffTaskAssignments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "staffId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Staffid"
                        },
                        "taskTypeId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Tasktypeid"
                        }
                      }
                    },
                    "description": "Stafftaskassignments"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Staff assigned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "staffJobIds",
                    "staffTaskIds"
                  ],
                  "properties": {
                    "staffJobIds": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "description": "IDs of the staff_job records created, re-activated or deactivated"
                    },
                    "staffTaskIds": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "description": "IDs of the task_type_staff_job records created, re-activated or deactivated"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires PROJ_C)"
          },
          "404": {
            "description": "Job, staff, or task type not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/projects/remove_staff": {
      "post": {
        "tags": [
          "Projects"
        ],
        "summary": "Remove staff from a project",
        "description": "\n> 🔐 **Required role:** `PROJ_C`\n>\n> 📖 **Data dictionary:** [Project](/reference/data-dictionary/project)\n\n**Remove staff from a project**\n\nDeactivates associations between staff members and a job:\n- ``staffJobAssignments``: deactivates matching ``staff_job`` records\n- ``staffTaskAssignments``: deactivates matching ``task_type_staff_job`` records\n\nReturns the IDs of deactivated records, in the same shape as the assign endpoint's response.\nItems with no matching active record are silently skipped.\n",
        "operationId": "RemoveStaffFromProject",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "jobId": 5001,
                "staffJobAssignments": [
                  {
                    "staffId": 103
                  },
                  {
                    "staffId": 104
                  }
                ],
                "staffTaskAssignments": [
                  {
                    "staffId": 103,
                    "taskTypeId": 10
                  },
                  {
                    "staffId": 104,
                    "taskTypeId": 11
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "jobId"
                ],
                "properties": {
                  "jobId": {
                    "type": "integer",
                    "format": "int64",
                    "description": "Jobid"
                  },
                  "staffJobAssignments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "staffId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Staffid"
                        }
                      }
                    },
                    "description": "Staffjobassignments"
                  },
                  "staffTaskAssignments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "staffId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Staffid"
                        },
                        "taskTypeId": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Tasktypeid"
                        }
                      }
                    },
                    "description": "Stafftaskassignments"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Staff removed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "staffJobIds",
                    "staffTaskIds"
                  ],
                  "properties": {
                    "staffJobIds": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "description": "IDs of the staff_job records created, re-activated or deactivated"
                    },
                    "staffTaskIds": {
                      "type": "array",
                      "items": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "description": "IDs of the task_type_staff_job records created, re-activated or deactivated"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires PROJ_C)"
          },
          "404": {
            "description": "Job, staff, or task type not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/task-types": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "List all task types",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Task type](/reference/data-dictionary/task-type)\n\n**Retrieve all task types**\n\nReturns every **active** task type for the tenant, ordered alphabetically by\ndisplay name. Deactivated task types are not returned; use the search endpoint with\n`{ \"active\": { \"_eq\": false } }` to list them. Task types classify the work performed on time entries and\nprojects, and carry billing and tax settings used downstream in invoicing.\n\n**Each task type includes:**\n- Display name, code, and description\n- Billing and tax flags (`billable`, `taxable`)\n- Optional custom hourly rate and rate type\n- Service line and category associations\n- Usage counts across projects and invoices\n- Aiwyn-managed vs firm-defined indicators\n- Active status and audit timestamps\n",
        "operationId": "getTaskTypes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Task types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskTypes": {
                      "type": "array",
                      "description": "List of task types ordered by display name",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Unique identifier of the task type",
                            "example": 1
                          },
                          "pmsRef": {
                            "type": "string",
                            "description": "Practice management system reference identifier",
                            "example": "TAX-PREP"
                          },
                          "code": {
                            "type": "string",
                            "description": "Short code used to identify the task type",
                            "example": "TXPRP"
                          },
                          "display": {
                            "type": "string",
                            "description": "Human-readable display name",
                            "example": "Tax Preparation"
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Detailed description of the task type",
                            "example": "Federal and state income tax preparation"
                          },
                          "billable": {
                            "type": "boolean",
                            "description": "Whether time logged under this task type is billable",
                            "example": true
                          },
                          "taxable": {
                            "type": "boolean",
                            "description": "Whether this task type is subject to tax",
                            "example": false
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Whether the task type is currently active",
                            "example": true
                          },
                          "customHourlyRate": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Optional custom hourly rate that overrides the default rate",
                            "example": 275
                          },
                          "rateTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the rate type associated with this task type",
                            "example": 3
                          },
                          "taskTypeCategoryId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the task type category",
                            "example": 2
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the service line this task type belongs to",
                            "example": 5
                          },
                          "projectsUsedInCount": {
                            "type": "integer",
                            "description": "Number of projects this task type is used in",
                            "example": 42
                          },
                          "invoicesUsedInCount": {
                            "type": "integer",
                            "description": "Number of invoices this task type appears on",
                            "example": 118
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task type was created by Aiwyn",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task type is managed by Aiwyn",
                            "example": false
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task type was created",
                            "example": "2023-01-15T08:00:00Z"
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task type was last updated",
                            "example": "2024-06-01T12:30:00Z"
                          },
                          "version": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Optimistic locking version number",
                            "example": 3
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the task type",
                            "example": 412
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the task type",
                            "example": 415
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "description": "Aggregate count information",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of task types",
                              "example": 25
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Task types retrieved",
                    "value": {
                      "taskTypes": [
                        {
                          "id": 1,
                          "pmsRef": "TAX-PREP",
                          "code": "TXPRP",
                          "display": "Tax Preparation",
                          "description": "Federal and state income tax preparation",
                          "billable": true,
                          "taxable": false,
                          "active": true,
                          "customHourlyRate": 275,
                          "rateTypeId": 3,
                          "taskTypeCategoryId": 2,
                          "serviceLineId": 5,
                          "projectsUsedInCount": 42,
                          "invoicesUsedInCount": 118,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "createdAt": "2023-01-15T08:00:00Z",
                          "updatedAt": "2024-06-01T12:30:00Z",
                          "version": 3,
                          "createdByStaffId": 412,
                          "lastUpdatedByStaffId": 415
                        },
                        {
                          "id": 2,
                          "pmsRef": "AUDIT",
                          "code": "AUDIT",
                          "display": "Audit",
                          "description": null,
                          "billable": true,
                          "taxable": false,
                          "active": true,
                          "customHourlyRate": null,
                          "rateTypeId": null,
                          "taskTypeCategoryId": 1,
                          "serviceLineId": 2,
                          "projectsUsedInCount": 17,
                          "invoicesUsedInCount": 53,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "createdAt": "2023-01-15T08:00:00Z",
                          "updatedAt": "2023-01-15T08:00:00Z",
                          "version": 1,
                          "createdByStaffId": 412,
                          "lastUpdatedByStaffId": 415
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 25
                        }
                      }
                    }
                  },
                  "empty": {
                    "summary": "No task types found",
                    "value": {
                      "taskTypes": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN role)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/task-types/search": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Search task types",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Task type](/reference/data-dictionary/task-type)\n\n**Advanced task type filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports flexible filtering across any task type field using a flexible `where`\nclause, with pagination and dynamic ordering.\n\nDeactivated task types (including deactivated `TimeCode` records) are included, unlike\n`GET /gql/v1/task-types`; filter on `active` to choose them: `{ \"active\": { \"_eq\": false } }`\nreturns only deactivated task types.\n\n**Common filter examples (pass in the `where` field):**\n- By code:          `{ \"code\": { \"_eq\": \"PREP\" } }`\n- By active status: `{ \"active\": { \"_eq\": true } }`\n- By billable flag: `{ \"billable\": { \"_eq\": true } }`\n- By category:      `{ \"taskTypeCategoryId\": { \"_eq\": 5 } }`\n- By service line:  `{ \"serviceLineId\": { \"_eq\": 2 } }`\n- Combined:         `{ \"_and\": [ { \"billable\": { \"_eq\": true } }, { \"active\": { \"_eq\": true } } ] }`\n",
        "operationId": "searchTaskTypesDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count).",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N` and\n`page: N`. An offset at or beyond `total.aggregate.count` returns an\nempty result array.\n",
                    "example": 0
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for filtering. Supports operators such as `_eq`, `_neq`, `_in`, `_nin`, `_ilike`, `_gte`, `_lte`, and logical combinators `_and`, `_or`, `_not`.\n",
                    "example": {
                      "_and": [
                        {
                          "billable": {
                            "_eq": true
                          }
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications. Each element is an object mapping a field name to `\"asc\"` or `\"desc\"`. Defaults to `[{ \"display\": \"asc\" }]`.\n",
                    "example": [
                      {
                        "display": "asc"
                      }
                    ]
                  }
                }
              },
              "examples": {
                "billable_active": {
                  "summary": "All active billable task types",
                  "value": {
                    "pageSize": 25,
                    "page": 0,
                    "where": {
                      "_and": [
                        {
                          "billable": {
                            "_eq": true
                          }
                        },
                        {
                          "active": {
                            "_eq": true
                          }
                        }
                      ]
                    },
                    "orderBy": [
                      {
                        "display": "asc"
                      }
                    ]
                  }
                },
                "by_service_line": {
                  "summary": "Task types for a specific service line",
                  "value": {
                    "pageSize": 50,
                    "page": 0,
                    "where": {
                      "serviceLineId": {
                        "_eq": 2
                      }
                    }
                  }
                },
                "by_code": {
                  "summary": "Exact code lookup",
                  "value": {
                    "pageSize": 1,
                    "page": 0,
                    "where": {
                      "code": {
                        "_eq": "TXPRP"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "taskTypes": {
                      "type": "array",
                      "description": "List of task types matching the filter criteria",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Unique identifier of the task type",
                            "example": 1
                          },
                          "pmsRef": {
                            "type": "string",
                            "description": "Practice management system reference identifier",
                            "example": "TAX-PREP"
                          },
                          "code": {
                            "type": "string",
                            "description": "Short code used to identify the task type",
                            "example": "TXPRP"
                          },
                          "display": {
                            "type": "string",
                            "description": "Human-readable display name",
                            "example": "Tax Preparation"
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Detailed description of the task type",
                            "example": "Federal and state income tax preparation"
                          },
                          "billable": {
                            "type": "boolean",
                            "description": "Whether time logged under this task type is billable",
                            "example": true
                          },
                          "taxable": {
                            "type": "boolean",
                            "description": "Whether this task type is subject to tax",
                            "example": false
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Whether the task type is currently active",
                            "example": true
                          },
                          "customHourlyRate": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Optional custom hourly rate that overrides the default rate",
                            "example": 275
                          },
                          "rateTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the rate type associated with this task type",
                            "example": 3
                          },
                          "taskTypeCategoryId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the task type category",
                            "example": 2
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the service line this task type belongs to",
                            "example": 5
                          },
                          "projectsUsedInCount": {
                            "type": "integer",
                            "description": "Number of projects this task type is used in",
                            "example": 42
                          },
                          "invoicesUsedInCount": {
                            "type": "integer",
                            "description": "Number of invoices this task type appears on",
                            "example": 118
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task type was created by Aiwyn",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task type is managed by Aiwyn",
                            "example": false
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task type was created",
                            "example": "2023-01-15T08:00:00Z"
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task type was last updated",
                            "example": "2024-06-01T12:30:00Z"
                          },
                          "version": {
                            "type": "integer",
                            "format": "int64",
                            "description": "Optimistic locking version number",
                            "example": 3
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the task type",
                            "example": 412
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the task type",
                            "example": 415
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "description": "Aggregate count matching the filter (ignores pagination)",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of task types matching the where clause",
                              "example": 12
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Active billable task types returned",
                    "value": {
                      "taskTypes": [
                        {
                          "id": 1,
                          "pmsRef": "TAX-PREP",
                          "code": "TXPRP",
                          "display": "Tax Preparation",
                          "description": "Federal and state income tax preparation",
                          "billable": true,
                          "taxable": false,
                          "active": true,
                          "customHourlyRate": 275,
                          "rateTypeId": 3,
                          "taskTypeCategoryId": 2,
                          "serviceLineId": 5,
                          "projectsUsedInCount": 42,
                          "invoicesUsedInCount": 118,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "createdAt": "2023-01-15T08:00:00Z",
                          "updatedAt": "2024-06-01T12:30:00Z",
                          "version": 3,
                          "createdByStaffId": 412,
                          "lastUpdatedByStaffId": 415
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 12
                        }
                      }
                    }
                  },
                  "empty": {
                    "summary": "No task types matched the filter",
                    "value": {
                      "taskTypes": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid filter parameters"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN role)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/task/{id}": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "Get task by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Task](/reference/data-dictionary/task)\n\n**Retrieve a specific task by its unique identifier**\n\nReturns full task details including the associated task type, assignee staff\nmember, and parent job reference.\n",
        "operationId": "findTaskById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the task",
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 1
            },
            "example": 456
          }
        ],
        "responses": {
          "200": {
            "description": "Task retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tasks"
                  ],
                  "properties": {
                    "tasks": {
                      "type": "array",
                      "description": "Single-element array containing the matching task (empty if not found)",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "name",
                          "overrideName",
                          "status",
                          "pmsRef",
                          "jobId",
                          "taskTypeId",
                          "assigneeStaffId",
                          "startDate",
                          "dueDate",
                          "targetStartDate",
                          "targetDueDate",
                          "estimatedHours",
                          "completedAt",
                          "description",
                          "ordinal",
                          "parentTaskId",
                          "jobTemplateTaskId",
                          "isCreatedByAiwyn",
                          "isManagedByAiwyn",
                          "createdAt",
                          "updatedAt",
                          "createdByStaffId",
                          "lastUpdatedByStaffId",
                          "taskSectionId",
                          "task",
                          "taskType",
                          "assigneeStaff",
                          "job"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Unique identifier of the task",
                            "example": 456
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Task name from the task row. Null when the task's name is carried in `overrideName`.",
                            "example": "Q4 Financial Statement Review"
                          },
                          "overrideName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Optional name that overrides the default task name",
                            "example": null
                          },
                          "status": {
                            "type": "string",
                            "description": "Current status of the task",
                            "example": "IN_PROGRESS"
                          },
                          "pmsRef": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Practice management system reference identifier",
                            "example": "TASK-001"
                          },
                          "jobId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the job this task belongs to",
                            "example": 67890
                          },
                          "taskTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the task type",
                            "example": 1
                          },
                          "assigneeStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the staff member assigned to this task",
                            "example": 123
                          },
                          "startDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Actual start date of the task",
                            "example": "2024-10-01"
                          },
                          "dueDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Actual due date of the task",
                            "example": "2024-12-31"
                          },
                          "targetStartDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Planned target start date",
                            "example": "2024-09-15"
                          },
                          "targetDueDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Planned target due date",
                            "example": "2024-12-15"
                          },
                          "estimatedHours": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Estimated hours to complete the task",
                            "example": 40
                          },
                          "completedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was completed",
                            "example": null
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Detailed description of the task",
                            "example": "Review and analyse Q4 financial statements including variance analysis"
                          },
                          "ordinal": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Display order position of the task",
                            "example": 1
                          },
                          "parentTaskId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int32",
                            "description": "ID of the parent task if this is a subtask",
                            "example": null
                          },
                          "jobTemplateTaskId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the job template task this was created from",
                            "example": 10
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task was created by Aiwyn",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task is managed by Aiwyn",
                            "example": false
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was created",
                            "example": "2024-09-01T08:00:00Z"
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was last updated",
                            "example": "2024-10-01T09:30:00Z"
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the task",
                            "example": 412
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the task",
                            "example": 415
                          },
                          "taskSectionId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the task section",
                            "example": 8
                          },
                          "task": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The task's active flag and custom field values",
                            "required": [
                              "active",
                              "customFieldValues"
                            ],
                            "properties": {
                              "active": {
                                "type": "boolean",
                                "description": "Whether the task is active",
                                "example": true
                              },
                              "customFieldValues": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": true,
                                "description": "Firm-defined custom fields, keyed by custom field code"
                              }
                            }
                          },
                          "taskType": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The task type associated with this task",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 1
                              },
                              "code": {
                                "type": "string",
                                "example": "TXPRP"
                              },
                              "display": {
                                "type": "string",
                                "example": "Tax Preparation"
                              },
                              "billable": {
                                "type": "boolean",
                                "example": true
                              },
                              "taxable": {
                                "type": "boolean",
                                "example": false
                              },
                              "active": {
                                "type": "boolean",
                                "example": true
                              }
                            }
                          },
                          "assigneeStaff": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The staff member assigned to this task",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 123
                              },
                              "firstName": {
                                "type": "string",
                                "example": "John"
                              },
                              "lastName": {
                                "type": "string",
                                "example": "Smith"
                              },
                              "email": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "format": "email",
                                "example": "john.smith@firm.com"
                              }
                            }
                          },
                          "job": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The job this task belongs to",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 67890
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Task found",
                    "value": {
                      "tasks": [
                        {
                          "id": 456,
                          "name": "Q4 Financial Statement Review",
                          "overrideName": null,
                          "status": "IN_PROGRESS",
                          "pmsRef": "TASK-001",
                          "jobId": 67890,
                          "taskTypeId": 1,
                          "assigneeStaffId": 123,
                          "startDate": "2024-10-01",
                          "dueDate": "2024-12-31",
                          "targetStartDate": "2024-09-15",
                          "targetDueDate": "2024-12-15",
                          "estimatedHours": 40,
                          "completedAt": null,
                          "description": "Review and analyse Q4 financial statements including variance analysis",
                          "ordinal": 1,
                          "parentTaskId": null,
                          "jobTemplateTaskId": 10,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "createdAt": "2024-09-01T08:00:00Z",
                          "updatedAt": "2024-10-01T09:30:00Z",
                          "createdByStaffId": 412,
                          "lastUpdatedByStaffId": 415,
                          "taskSectionId": 8,
                          "task": {
                            "active": true,
                            "customFieldValues": {}
                          },
                          "taskType": {
                            "id": 1,
                            "code": "TXPRP",
                            "display": "Tax Preparation",
                            "billable": true,
                            "taxable": false,
                            "active": true
                          },
                          "assigneeStaff": {
                            "id": 123,
                            "firstName": "John",
                            "lastName": "Smith",
                            "email": "john.smith@firm.com"
                          },
                          "job": {
                            "id": 67890
                          }
                        }
                      ]
                    }
                  },
                  "not_found": {
                    "summary": "Task not found",
                    "value": {
                      "tasks": []
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN role)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/tasks/search": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Search tasks",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Task](/reference/data-dictionary/task)\n\n**Advanced task filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports flexible filtering across any task field — including nested relations\nsuch as `taskType` and `job` — using a flexible `where` clause, with\npagination and dynamic ordering.\n\n**Common filter examples (pass in the `where` field):**\n- By task type ID:   `{ \"taskTypeId\": { \"_eq\": 123 } }`\n- By task type code: `{ \"taskType\": { \"code\": { \"_eq\": \"PREP\" } } }`\n- By client:         `{ \"job\": { \"clientId\": { \"_eq\": 456 } } }`\n- Start date range:  `{ \"startDate\": { \"_gte\": \"2024-01-01\", \"_lte\": \"2024-12-31\" } }`\n- Due date range:    `{ \"dueDate\": { \"_gte\": \"2024-01-01\", \"_lte\": \"2024-12-31\" } }`\n- By assignee:       `{ \"assigneeStaffId\": { \"_eq\": 789 } }`\n- Combined:          `{ \"_and\": [ { \"taskType\": { \"code\": { \"_eq\": \"PREP\" } } }, { \"assigneeStaffId\": { \"_eq\": 789 } } ] }`\n",
        "operationId": "searchTasksDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count).",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N` and\n`page: N`. An offset at or beyond `total.aggregate.count` returns an\nempty result array.\n",
                    "example": 0
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for filtering. Supports operators such as `_eq`, `_neq`, `_in`, `_nin`, `_ilike`, `_gte`, `_lte`, and logical combinators `_and`, `_or`, `_not`. Nested relations `taskType` and `job` can be filtered inline.\n",
                    "example": {
                      "_and": [
                        {
                          "taskType": {
                            "code": {
                              "_eq": "PREP"
                            }
                          }
                        },
                        {
                          "assigneeStaffId": {
                            "_eq": 789
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications. Each element maps a field name to `\"asc\"` or `\"desc\"`. Defaults to `[{ \"id\": \"asc\" }]`.\n",
                    "example": [
                      {
                        "dueDate": "asc"
                      }
                    ]
                  }
                }
              },
              "examples": {
                "by_task_type_and_assignee": {
                  "summary": "Tasks of a specific type assigned to a staff member",
                  "value": {
                    "pageSize": 25,
                    "page": 0,
                    "where": {
                      "_and": [
                        {
                          "taskType": {
                            "code": {
                              "_eq": "PREP"
                            }
                          }
                        },
                        {
                          "assigneeStaffId": {
                            "_eq": 789
                          }
                        }
                      ]
                    },
                    "orderBy": [
                      {
                        "dueDate": "asc"
                      }
                    ]
                  }
                },
                "by_client": {
                  "summary": "All tasks for a specific client",
                  "value": {
                    "pageSize": 50,
                    "page": 0,
                    "where": {
                      "job": {
                        "clientId": {
                          "_eq": 456
                        }
                      }
                    }
                  }
                },
                "due_date_range": {
                  "summary": "Tasks due within a date range",
                  "value": {
                    "pageSize": 50,
                    "page": 0,
                    "where": {
                      "dueDate": {
                        "_gte": "2024-01-01",
                        "_lte": "2024-12-31"
                      }
                    },
                    "orderBy": [
                      {
                        "dueDate": "asc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tasks retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "tasks",
                    "total"
                  ],
                  "properties": {
                    "tasks": {
                      "type": "array",
                      "description": "List of tasks matching the filter criteria",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "name",
                          "overrideName",
                          "status",
                          "pmsRef",
                          "jobId",
                          "taskTypeId",
                          "assigneeStaffId",
                          "startDate",
                          "dueDate",
                          "targetStartDate",
                          "targetDueDate",
                          "estimatedHours",
                          "completedAt",
                          "description",
                          "ordinal",
                          "parentTaskId",
                          "isCreatedByAiwyn",
                          "isManagedByAiwyn",
                          "createdAt",
                          "updatedAt",
                          "createdByStaffId",
                          "lastUpdatedByStaffId",
                          "taskSectionId",
                          "jobTemplateTaskId",
                          "task",
                          "taskType",
                          "assigneeStaff",
                          "job"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "format": "int32",
                            "description": "Unique identifier of the task",
                            "example": 456
                          },
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Task name from the task row. Null when the task's name is carried in `overrideName`.",
                            "example": "Q4 Financial Statement Review"
                          },
                          "overrideName": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Optional name that overrides the default task name",
                            "example": null
                          },
                          "status": {
                            "type": "string",
                            "description": "Current status of the task",
                            "example": "IN_PROGRESS"
                          },
                          "pmsRef": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Practice management system reference identifier",
                            "example": "TASK-001"
                          },
                          "jobId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the job this task belongs to",
                            "example": 67890
                          },
                          "taskTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the task type",
                            "example": 1
                          },
                          "assigneeStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the staff member assigned to this task",
                            "example": 789
                          },
                          "startDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Actual start date of the task",
                            "example": "2024-10-01"
                          },
                          "dueDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Actual due date of the task",
                            "example": "2024-12-31"
                          },
                          "targetStartDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Planned target start date",
                            "example": "2024-09-15"
                          },
                          "targetDueDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date",
                            "description": "Planned target due date",
                            "example": "2024-12-15"
                          },
                          "estimatedHours": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Estimated hours to complete the task",
                            "example": 40
                          },
                          "completedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was completed",
                            "example": null
                          },
                          "description": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Detailed description of the task",
                            "example": "Review and analyse Q4 financial statements"
                          },
                          "ordinal": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Display order position of the task",
                            "example": 1
                          },
                          "parentTaskId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int32",
                            "description": "ID of the parent task if this is a subtask",
                            "example": null
                          },
                          "isCreatedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task was created by Aiwyn",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": "boolean",
                            "description": "Whether this task is managed by Aiwyn",
                            "example": false
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was created",
                            "example": "2024-09-01T08:00:00Z"
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "Timestamp when the task was last updated",
                            "example": "2024-10-01T09:30:00Z"
                          },
                          "createdByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who created the task",
                            "example": 412
                          },
                          "lastUpdatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the task",
                            "example": 415
                          },
                          "taskSectionId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the task section",
                            "example": 8
                          },
                          "jobTemplateTaskId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64",
                            "description": "ID of the project template task this task was created from",
                            "example": 10
                          },
                          "task": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The task's active flag and custom field values",
                            "required": [
                              "active",
                              "customFieldValues"
                            ],
                            "properties": {
                              "active": {
                                "type": "boolean",
                                "description": "Whether the task is active",
                                "example": true
                              },
                              "customFieldValues": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": true,
                                "description": "Firm-defined custom fields, keyed by custom field code"
                              }
                            }
                          },
                          "taskType": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The task type associated with this task",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 1
                              },
                              "code": {
                                "type": "string",
                                "example": "PREP"
                              },
                              "display": {
                                "type": "string",
                                "example": "Tax Preparation"
                              },
                              "billable": {
                                "type": "boolean",
                                "example": true
                              },
                              "taxable": {
                                "type": "boolean",
                                "example": false
                              },
                              "active": {
                                "type": "boolean",
                                "example": true
                              }
                            }
                          },
                          "assigneeStaff": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The staff member assigned to this task",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 789
                              },
                              "firstName": {
                                "type": "string",
                                "example": "Jane"
                              },
                              "lastName": {
                                "type": "string",
                                "example": "Doe"
                              },
                              "email": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "format": "email",
                                "example": "jane.doe@firm.com"
                              }
                            }
                          },
                          "job": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "The job this task belongs to",
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "example": 67890
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "description": "Aggregate count matching the filter (ignores pagination)",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of tasks matching the where clause",
                              "example": 84
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "Tasks returned",
                    "value": {
                      "tasks": [
                        {
                          "id": 456,
                          "name": "Q4 Financial Statement Review",
                          "overrideName": null,
                          "status": "IN_PROGRESS",
                          "pmsRef": "TASK-001",
                          "jobId": 67890,
                          "taskTypeId": 1,
                          "assigneeStaffId": 789,
                          "startDate": "2024-10-01",
                          "dueDate": "2024-12-31",
                          "targetStartDate": "2024-09-15",
                          "targetDueDate": "2024-12-15",
                          "estimatedHours": 40,
                          "completedAt": null,
                          "description": "Review and analyse Q4 financial statements",
                          "ordinal": 1,
                          "parentTaskId": null,
                          "isCreatedByAiwyn": false,
                          "isManagedByAiwyn": false,
                          "createdAt": "2024-09-01T08:00:00Z",
                          "updatedAt": "2024-10-01T09:30:00Z",
                          "createdByStaffId": 412,
                          "lastUpdatedByStaffId": 415,
                          "taskSectionId": 8,
                          "jobTemplateTaskId": 10,
                          "task": {
                            "active": true,
                            "customFieldValues": {}
                          },
                          "taskType": {
                            "id": 1,
                            "code": "PREP",
                            "display": "Tax Preparation",
                            "billable": true,
                            "taxable": false,
                            "active": true
                          },
                          "assigneeStaff": {
                            "id": 789,
                            "firstName": "Jane",
                            "lastName": "Doe",
                            "email": "jane.doe@firm.com"
                          },
                          "job": {
                            "id": 67890
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 84
                        }
                      }
                    }
                  },
                  "empty": {
                    "summary": "No tasks matched the filter",
                    "value": {
                      "tasks": [],
                      "total": {
                        "aggregate": {
                          "count": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid filter parameters"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN role)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/wip": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "List WIP entries",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Work in progress (WIP)](/reference/data-dictionary/wip)\n\n**Work in Progress tracking with comprehensive financial lifecycle management**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `<tenant>_vw_wip_unified_aggregate.aggregate.count` to detect the end.\n\n**Response keys are tenant-specific.** Unlike the other list endpoints, this response is\nnot aliased: the records are under `<tenant>_vw_wip_unified` and the totals under\n`<tenant>_vw_wip_unified_aggregate`, where `<tenant>` is your tenant's schema name (for\nexample `acme_vw_wip_unified`). Read the two keys by suffix rather than by a fixed name.\n`POST /gql/v1/wips/search` returns fixed keys.\n\nThis advanced endpoint provides complete WIP management including:\n- WIP value tracking from creation through billing completion\n- Outstanding balance calculations for unbilled work\n- Multi-dimensional analysis (client, job, date-based)\n- Financial aggregations for WIP reporting and analysis\n- Integration with client data for complete context\n\n**Financial Tracking Features:**\n- WIP value recording and outstanding balance calculation\n- Billed amount tracking for revenue recognition\n- Write-off amount management for uncollectible WIP\n- Job and client correlation for project profitability\n\n**WIP Lifecycle Management:**\n- Creation date logging for aging analysis\n- WIP type categorization (TIME, EXPENSE, FIXED_FEE, etc.)\n- Outstanding value calculation for billing preparation\n- Billed amount reconciliation for revenue tracking\n\n**Business Intelligence & Reporting:**\n- Client-specific WIP analysis and aging\n- Job-based profitability and WIP tracking\n- WIP aging reports for collections management\n- Revenue recognition and billing pipeline analysis\n\n**Financial Aggregations:**\n- Total WIP value across filtered records\n- Outstanding WIP calculations for billing preparation\n- Billed amount summaries for revenue analysis\n- Write-off tracking for financial reporting\n\n**Filtering:** this endpoint accepts only `pageSize` and `page`; any other body\nproperty is rejected with 400 (`Unexpected variable …`). To filter (by client, job,\nWIP type, logged date, …) or sort, use `POST /gql/v1/wips/search`.\n\n**Active Record Filtering:**\n- Only active WIP records are returned (inactive records represent deletions), newest `loggedDate` first\n- Each record includes `isActive` so clients can distinguish active from inactive when querying by ID\n",
        "operationId": "getWip",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`.",
                    "example": 25
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N` and\n`page: N`. An offset at or beyond `total.aggregate.count` returns an\nempty result array.\n",
                    "example": 0
                  }
                }
              },
              "examples": {
                "default_pagination": {
                  "summary": "Default pagination",
                  "value": {
                    "pageSize": 25,
                    "page": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved WIP records with financial aggregations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "patternProperties": {
                    "^[a-z0-9_]+_vw_wip_unified$": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "wipType",
                          "loggedDate",
                          "wipValue",
                          "wipValueOutstanding",
                          "billedAmount",
                          "writeOffAmount",
                          "notes",
                          "clientId",
                          "jobId",
                          "isActive",
                          "createdAt",
                          "updatedAt",
                          "approvedDate",
                          "approvedStaffId",
                          "billedPerUnit",
                          "costPerUnit",
                          "customFieldValues",
                          "deptId",
                          "isApproved",
                          "isCreatedByAiwyn",
                          "isLocked",
                          "isManagedByAiwyn",
                          "isPosted",
                          "loggedStaffId",
                          "officeId",
                          "pmsRef",
                          "postedDate",
                          "postedStaffId",
                          "rawUnits",
                          "serviceLineId",
                          "staffTypeId",
                          "taskTypeId",
                          "units",
                          "updatedByStaffId",
                          "client"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "Unique WIP record identifier",
                            "example": 850321
                          },
                          "wipType": {
                            "type": "string",
                            "description": "Type of WIP entry",
                            "example": "Time"
                          },
                          "loggedDate": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Date when WIP was logged",
                            "example": "2024-01-17T05:00:00"
                          },
                          "wipValue": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Original WIP value recorded",
                            "example": 1250
                          },
                          "wipValueOutstanding": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Outstanding WIP value yet to be billed",
                            "example": 0
                          },
                          "billedAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount that has been billed from this WIP",
                            "example": 1225
                          },
                          "writeOffAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount written off as uncollectible",
                            "example": 25
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Additional notes or description for the WIP entry",
                            "example": "Consultation and analysis for Q1 financial review"
                          },
                          "clientId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated client identifier. Null when the entry is not linked to a client.",
                            "example": 1561
                          },
                          "jobId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated job identifier. Null when the entry is not linked to a job, as is usual for an expense.",
                            "example": 2514
                          },
                          "isActive": {
                            "type": "boolean",
                            "description": "Whether the WIP record is active (inactive records represent deletions)",
                            "example": true
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record creation timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record last update timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "approvedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was approved",
                            "example": "2024-01-18T05:00:00"
                          },
                          "approvedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who approved the WIP record",
                            "example": 412
                          },
                          "billedPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Billing rate per unit",
                            "example": 250
                          },
                          "costPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Cost per unit of the WIP record",
                            "example": 95
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields, keyed by custom field code"
                          },
                          "deptId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the department",
                            "example": 3
                          },
                          "isApproved": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is approved",
                            "example": true
                          },
                          "isCreatedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record was created in Aiwyn",
                            "example": false
                          },
                          "isLocked": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is locked",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether Aiwyn manages the WIP record's lifecycle",
                            "example": false
                          },
                          "isPosted": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is posted",
                            "example": true
                          },
                          "loggedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member the WIP record was logged for",
                            "example": 412
                          },
                          "officeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the office",
                            "example": 2
                          },
                          "pmsRef": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Identifier of the WIP record in the external practice management system",
                            "example": "1789456"
                          },
                          "postedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was posted",
                            "example": "2024-01-19T05:00:00"
                          },
                          "postedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who posted the WIP record",
                            "example": 415
                          },
                          "rawUnits": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units before rounding",
                            "example": 5
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the service line",
                            "example": 4
                          },
                          "staffTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff type",
                            "example": 7
                          },
                          "taskTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the work code (task type)",
                            "example": 12
                          },
                          "units": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units (hours for time entries)",
                            "example": 5
                          },
                          "updatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the WIP record",
                            "example": 415
                          },
                          "client": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "Associated client information. Null when the client is not in the client view (for example an inactive client).",
                            "required": [
                              "id",
                              "name"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 1561
                              },
                              "name": {
                                "type": "string",
                                "example": "TechFlow Enterprises"
                              }
                            }
                          }
                        }
                      }
                    },
                    "^[a-z0-9_]+_vw_wip_unified_aggregate$": {
                      "type": "object",
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of WIP records matching criteria",
                              "example": 84
                            },
                            "sum": {
                              "type": "object",
                              "properties": {
                                "wipValue": {
                                  "type": "number",
                                  "format": "decimal",
                                  "description": "Total WIP value across all matching records",
                                  "example": 24186.15
                                },
                                "billedAmount": {
                                  "type": "number",
                                  "format": "decimal",
                                  "description": "Total billed amount across all matching records",
                                  "example": 19612.07
                                },
                                "wipValueOutstanding": {
                                  "type": "number",
                                  "format": "decimal",
                                  "description": "Total outstanding WIP value",
                                  "example": 0
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "successful_response": {
                    "summary": "WIP records with financial tracking and aggregations",
                    "value": {
                      "acme_vw_wip_unified": [
                        {
                          "id": 850321,
                          "wipType": "Time",
                          "loggedDate": "2024-01-17T05:00:00",
                          "wipValue": 1250,
                          "wipValueOutstanding": 0,
                          "billedAmount": 1225,
                          "writeOffAmount": 25,
                          "notes": "Consultation and analysis for Q1 financial review",
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2024-05-12T23:02:33.24516+00:00",
                          "updatedAt": "2024-05-12T23:02:33.24516+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "TechFlow Enterprises"
                          }
                        },
                        {
                          "id": 850142,
                          "wipType": "Expense",
                          "loggedDate": "2024-01-15T05:00:00",
                          "wipValue": 350,
                          "wipValueOutstanding": 0,
                          "billedAmount": 343.5,
                          "writeOffAmount": 6.5,
                          "notes": null,
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2024-05-12T23:00:05.824148+00:00",
                          "updatedAt": "2024-05-12T23:00:05.824148+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "TechFlow Enterprises"
                          }
                        },
                        {
                          "id": 849987,
                          "wipType": "Time",
                          "loggedDate": "2024-01-12T05:00:00",
                          "wipValue": 875,
                          "wipValueOutstanding": 125,
                          "billedAmount": 750,
                          "writeOffAmount": 0,
                          "notes": "Document review and preparation",
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2024-05-12T23:00:07.784813+00:00",
                          "updatedAt": "2024-05-12T23:00:07.784813+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "TechFlow Enterprises"
                          }
                        }
                      ],
                      "acme_vw_wip_unified_aggregate": {
                        "aggregate": {
                          "count": 84,
                          "sum": {
                            "wipValue": 24186.15,
                            "billedAmount": 19612.07,
                            "wipValueOutstanding": 125
                          }
                        }
                      }
                    }
                  },
                  "real_api_response": {
                    "summary": "Sample from actual API response",
                    "value": {
                      "acme_vw_wip_unified": [
                        {
                          "id": 743292,
                          "wipType": "Time",
                          "loggedDate": "2018-01-17T05:00:00",
                          "wipValue": 127.5,
                          "wipValueOutstanding": 0,
                          "billedAmount": 0,
                          "writeOffAmount": 127.5,
                          "notes": "Velit aut provident sint dolorum eaque necessitatibus dicta reprehenderit eveniet dolore eius neque est.",
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2023-05-12T23:02:33.24516+00:00",
                          "updatedAt": "2023-05-12T23:02:33.24516+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "Cammie Cremin"
                          }
                        },
                        {
                          "id": 510044,
                          "wipType": "Time",
                          "loggedDate": "2016-03-23T04:00:00",
                          "wipValue": 87.5,
                          "wipValueOutstanding": 0,
                          "billedAmount": 86.05,
                          "writeOffAmount": 1.45,
                          "notes": null,
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2023-05-12T23:00:05.824148+00:00",
                          "updatedAt": "2023-05-12T23:00:05.824148+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "Cammie Cremin"
                          }
                        }
                      ],
                      "acme_vw_wip_unified_aggregate": {
                        "aggregate": {
                          "count": 84,
                          "sum": {
                            "wipValue": 24186.15,
                            "billedAmount": 19612.07,
                            "wipValueOutstanding": 0
                          }
                        }
                      }
                    }
                  },
                  "empty_response": {
                    "summary": "No WIP records found",
                    "value": {
                      "acme_vw_wip_unified": [],
                      "acme_vw_wip_unified_aggregate": {
                        "aggregate": {
                          "count": 0,
                          "sum": {
                            "wipValue": 0,
                            "billedAmount": 0,
                            "wipValueOutstanding": 0
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request. Returned by Hasura for a body property other than `pageSize`/`page`\n(`Unexpected variable …`) or an invalid value (for example a negative `pageSize`).\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "Unexpected variable clientId"
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "bad-request"
                    }
                  }
                },
                "examples": {
                  "unexpected_variable": {
                    "summary": "Filter property sent to the list endpoint",
                    "value": {
                      "path": "$",
                      "error": "Unexpected variable clientId",
                      "code": "bad-request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "missing_auth": {
                    "summary": "Missing authentication header",
                    "value": {
                      "error": "Authorization header is required",
                      "code": "MISSING_AUTH_HEADER"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/gql/v1/wips/search": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Search WIP entries",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Work in progress (WIP)](/reference/data-dictionary/wip)\n\n**Advanced WIP filtering with a flexible `where` clause and dynamic ordering**\n\nUses standard limit/offset pagination via `pageSize` and `page` — see [Pagination](/reference/pagination). Use `total.aggregate.count` to detect the end.\n\nSupports wipType selection, date ranges, and client/job constraints.\nWithout a `where`, only active WIP records are returned (the default is\n`{ \"isActive\": { \"_eq\": true } }`). A `where` replaces that default, so add\n`isActive` to it to keep excluding inactive records. Default order is\n`loggedDate desc, createdAt desc`.\n",
        "operationId": "filterWipsDynamic",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "example": {
                "pageSize": 1,
                "where": {
                  "_and": [
                    {
                      "_or": [
                        {
                          "wipType": {
                            "_in": [
                              "Time",
                              "Expense"
                            ]
                          }
                        },
                        {
                          "notes": {
                            "_ilike": "%consultation%"
                          }
                        }
                      ]
                    },
                    {
                      "isActive": {
                        "_eq": true
                      }
                    },
                    {
                      "loggedDate": {
                        "_gte": "1900-01-01T00:00:00Z"
                      }
                    },
                    {
                      "clientId": {
                        "_in": [
                          1001,
                          1002,
                          1003
                        ]
                      }
                    }
                  ]
                },
                "orderBy": [
                  {
                    "loggedDate": "desc"
                  },
                  {
                    "wipValue": "desc"
                  }
                ]
              },
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000,
                    "default": 50,
                    "description": "Limit — number of records to return (not a page count). Hasura maps this to `limit`."
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0,
                    "description": "Offset — number of records to skip. This is not a page index.\nTo fetch the next N rows after the first N, send `pageSize: N` and\n`page: N`. An offset at or beyond `total.aggregate.count` returns an\nempty result array.\n"
                  },
                  "where": {
                    "type": "object",
                    "description": "Flexible `where` clause for complex WIP filtering",
                    "example": {
                      "_and": [
                        {
                          "_or": [
                            {
                              "wipType": {
                                "_in": [
                                  "Time",
                                  "Expense"
                                ]
                              }
                            },
                            {
                              "notes": {
                                "_ilike": "%consultation%"
                              }
                            }
                          ]
                        },
                        {
                          "isActive": {
                            "_eq": true
                          }
                        },
                        {
                          "loggedDate": {
                            "_gte": "1900-01-01T00:00:00Z"
                          }
                        },
                        {
                          "clientId": {
                            "_in": [
                              1001,
                              1002,
                              1003
                            ]
                          }
                        }
                      ]
                    }
                  },
                  "orderBy": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Dynamic ordering specifications. Defaults to `[{ \"loggedDate\": \"desc\" }, { \"createdAt\": \"desc\" }]`.\n",
                    "example": [
                      {
                        "loggedDate": "desc"
                      },
                      {
                        "wipValue": "desc"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully retrieved filtered WIP entries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "wips",
                    "total"
                  ],
                  "properties": {
                    "wips": {
                      "type": "array",
                      "description": "WIP records matching the filter (at most `pageSize`)",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "wipType",
                          "loggedDate",
                          "wipValue",
                          "wipValueOutstanding",
                          "billedAmount",
                          "writeOffAmount",
                          "notes",
                          "clientId",
                          "jobId",
                          "isActive",
                          "createdAt",
                          "updatedAt",
                          "approvedDate",
                          "approvedStaffId",
                          "billedPerUnit",
                          "costPerUnit",
                          "customFieldValues",
                          "deptId",
                          "isApproved",
                          "isCreatedByAiwyn",
                          "isLocked",
                          "isManagedByAiwyn",
                          "isPosted",
                          "loggedStaffId",
                          "officeId",
                          "pmsRef",
                          "postedDate",
                          "postedStaffId",
                          "rawUnits",
                          "serviceLineId",
                          "staffTypeId",
                          "taskTypeId",
                          "units",
                          "updatedByStaffId",
                          "client"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "Unique WIP record identifier",
                            "example": 89012
                          },
                          "wipType": {
                            "type": "string",
                            "description": "Type of WIP entry",
                            "example": "Progress"
                          },
                          "loggedDate": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Date when WIP was logged",
                            "example": "2024-01-17T05:00:00"
                          },
                          "wipValue": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Original WIP value recorded",
                            "example": 1250
                          },
                          "wipValueOutstanding": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Outstanding WIP value yet to be billed",
                            "example": 0
                          },
                          "billedAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount that has been billed from this WIP",
                            "example": 1225
                          },
                          "writeOffAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount written off as uncollectible",
                            "example": 25
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Additional notes or description for the WIP entry",
                            "example": "Consultation and analysis for Q1 financial review"
                          },
                          "clientId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated client identifier. Null when the entry is not linked to a client.",
                            "example": 1561
                          },
                          "jobId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated job identifier. Null when the entry is not linked to a job, as is usual for an expense.",
                            "example": 2514
                          },
                          "isActive": {
                            "type": "boolean",
                            "description": "Whether the WIP record is active (inactive records represent deletions)",
                            "example": true
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record creation timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record last update timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "approvedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was approved",
                            "example": "2024-01-18T05:00:00"
                          },
                          "approvedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who approved the WIP record",
                            "example": 412
                          },
                          "billedPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Billing rate per unit",
                            "example": 250
                          },
                          "costPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Cost per unit of the WIP record",
                            "example": 95
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields, keyed by custom field code"
                          },
                          "deptId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the department",
                            "example": 3
                          },
                          "isApproved": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is approved",
                            "example": true
                          },
                          "isCreatedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record was created in Aiwyn",
                            "example": false
                          },
                          "isLocked": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is locked",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether Aiwyn manages the WIP record's lifecycle",
                            "example": false
                          },
                          "isPosted": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is posted",
                            "example": true
                          },
                          "loggedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member the WIP record was logged for",
                            "example": 412
                          },
                          "officeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the office",
                            "example": 2
                          },
                          "pmsRef": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Identifier of the WIP record in the external practice management system",
                            "example": "1789456"
                          },
                          "postedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was posted",
                            "example": "2024-01-19T05:00:00"
                          },
                          "postedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who posted the WIP record",
                            "example": 415
                          },
                          "rawUnits": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units before rounding",
                            "example": 5
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the service line",
                            "example": 4
                          },
                          "staffTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff type",
                            "example": 7
                          },
                          "taskTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the work code (task type)",
                            "example": 12
                          },
                          "units": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units (hours for time entries)",
                            "example": 5
                          },
                          "updatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the WIP record",
                            "example": 415
                          },
                          "client": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "Associated client information. Null when the client is not in the client view (for example an inactive client).",
                            "required": [
                              "id",
                              "name"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 1561
                              },
                              "name": {
                                "type": "string",
                                "example": "TechFlow Enterprises"
                              }
                            }
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "object",
                      "description": "Count and financial aggregates over every record matching the filter (ignores pagination)",
                      "required": [
                        "aggregate"
                      ],
                      "properties": {
                        "aggregate": {
                          "type": "object",
                          "required": [
                            "count",
                            "sum",
                            "avg"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "description": "Total number of WIP records matching the where clause",
                              "example": 84
                            },
                            "sum": {
                              "type": "object",
                              "description": "Sums over the matching records; each is null when nothing matches",
                              "required": [
                                "wipValue",
                                "wipValueOutstanding",
                                "billedAmount",
                                "writeOffAmount"
                              ],
                              "properties": {
                                "wipValue": {
                                  "type": [
                                    "number",
                                    "null"
                                  ],
                                  "format": "decimal",
                                  "description": "Total WIP value"
                                },
                                "wipValueOutstanding": {
                                  "type": [
                                    "number",
                                    "null"
                                  ],
                                  "format": "decimal",
                                  "description": "Total outstanding WIP value"
                                },
                                "billedAmount": {
                                  "type": [
                                    "number",
                                    "null"
                                  ],
                                  "format": "decimal",
                                  "description": "Total billed amount"
                                },
                                "writeOffAmount": {
                                  "type": [
                                    "number",
                                    "null"
                                  ],
                                  "format": "decimal",
                                  "description": "Total written-off amount"
                                }
                              }
                            },
                            "avg": {
                              "type": "object",
                              "description": "Averages over the matching records; null when nothing matches",
                              "required": [
                                "wipValue"
                              ],
                              "properties": {
                                "wipValue": {
                                  "type": [
                                    "number",
                                    "null"
                                  ],
                                  "format": "decimal",
                                  "description": "Average WIP value"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "WIP records with aggregates",
                    "value": {
                      "wips": [
                        {
                          "id": 89012,
                          "wipType": "Progress",
                          "loggedDate": "2024-01-17T05:00:00",
                          "wipValue": 1250,
                          "wipValueOutstanding": 0,
                          "billedAmount": 1225,
                          "writeOffAmount": 25,
                          "notes": "Consultation and analysis for Q1 financial review",
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2024-05-12T23:02:33.24516+00:00",
                          "updatedAt": "2024-05-12T23:02:33.24516+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "TechFlow Enterprises"
                          }
                        }
                      ],
                      "total": {
                        "aggregate": {
                          "count": 84,
                          "sum": {
                            "wipValue": 24186.15,
                            "wipValueOutstanding": 125,
                            "billedAmount": 19612.07,
                            "writeOffAmount": 449.08
                          },
                          "avg": {
                            "wipValue": 287.93
                          }
                        }
                      }
                    }
                  },
                  "empty": {
                    "summary": "No WIP records matched the filter",
                    "value": {
                      "wips": [],
                      "total": {
                        "aggregate": {
                          "count": 0,
                          "sum": {
                            "wipValue": null,
                            "wipValueOutstanding": null,
                            "billedAmount": null,
                            "writeOffAmount": null
                          },
                          "avg": {
                            "wipValue": null
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid where/orderBy (for example a field that does not exist on the WIP view)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$.selectionSet.wips.args.where.unknownField"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "field 'unknownField' not found in type: 'vw_wip_unified_bool_exp'"
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "validation-failed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/gql/v1/time/wip/{id}": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "Get WIP entry by ID",
        "description": "> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [Work in progress (WIP)](/reference/data-dictionary/wip)\n\n**Retrieve a specific work-in-progress (WIP) record by its unique identifier**\n\nReturns the WIP record with the same fields as `POST /gql/v1/wip`, including\ninactive records (check `isActive`; inactive records represent deletions).\nThe record is wrapped in a `wip` array that holds at most one element; an id\nthat does not exist returns 200 with an empty array.\n",
        "operationId": "getWipById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the WIP record",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 89012
          }
        ],
        "responses": {
          "200": {
            "description": "The WIP record, wrapped in a `wip` array with at most one element.\nAn id that does not exist returns an empty array.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "wip"
                  ],
                  "properties": {
                    "wip": {
                      "type": "array",
                      "description": "Single-element array containing the matching WIP record (empty if not found)",
                      "maxItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "wipType",
                          "loggedDate",
                          "wipValue",
                          "wipValueOutstanding",
                          "billedAmount",
                          "writeOffAmount",
                          "notes",
                          "clientId",
                          "jobId",
                          "isActive",
                          "createdAt",
                          "updatedAt",
                          "approvedDate",
                          "approvedStaffId",
                          "billedPerUnit",
                          "costPerUnit",
                          "customFieldValues",
                          "deptId",
                          "isApproved",
                          "isCreatedByAiwyn",
                          "isLocked",
                          "isManagedByAiwyn",
                          "isPosted",
                          "loggedStaffId",
                          "officeId",
                          "pmsRef",
                          "postedDate",
                          "postedStaffId",
                          "rawUnits",
                          "serviceLineId",
                          "staffTypeId",
                          "taskTypeId",
                          "units",
                          "updatedByStaffId",
                          "client"
                        ],
                        "properties": {
                          "id": {
                            "type": "integer",
                            "description": "Unique WIP record identifier",
                            "example": 89012
                          },
                          "wipType": {
                            "type": "string",
                            "description": "Type of WIP entry",
                            "example": "Progress"
                          },
                          "loggedDate": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Date when WIP was logged",
                            "example": "2024-01-17T05:00:00"
                          },
                          "wipValue": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Original WIP value recorded",
                            "example": 1250
                          },
                          "wipValueOutstanding": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Outstanding WIP value yet to be billed",
                            "example": 0
                          },
                          "billedAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount that has been billed from this WIP",
                            "example": 1225
                          },
                          "writeOffAmount": {
                            "type": "number",
                            "format": "decimal",
                            "description": "Amount written off as uncollectible",
                            "example": 25
                          },
                          "notes": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Additional notes or description for the WIP entry",
                            "example": "Consultation and analysis for Q1 financial review"
                          },
                          "clientId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated client identifier. Null when the entry is not linked to a client.",
                            "example": 1561
                          },
                          "jobId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "Associated job identifier. Null when the entry is not linked to a job, as is usual for an expense.",
                            "example": 2514
                          },
                          "isActive": {
                            "type": "boolean",
                            "description": "Whether the WIP record is active (inactive records represent deletions)",
                            "example": true
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record creation timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time",
                            "description": "WIP record last update timestamp",
                            "example": "2024-05-12T23:02:33.24516+00:00"
                          },
                          "approvedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was approved",
                            "example": "2024-01-18T05:00:00"
                          },
                          "approvedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who approved the WIP record",
                            "example": 412
                          },
                          "billedPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Billing rate per unit",
                            "example": 250
                          },
                          "costPerUnit": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "format": "decimal",
                            "description": "Cost per unit of the WIP record",
                            "example": 95
                          },
                          "customFieldValues": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "additionalProperties": true,
                            "description": "Firm-defined custom fields, keyed by custom field code"
                          },
                          "deptId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the department",
                            "example": 3
                          },
                          "isApproved": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is approved",
                            "example": true
                          },
                          "isCreatedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record was created in Aiwyn",
                            "example": false
                          },
                          "isLocked": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is locked",
                            "example": false
                          },
                          "isManagedByAiwyn": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether Aiwyn manages the WIP record's lifecycle",
                            "example": false
                          },
                          "isPosted": {
                            "type": [
                              "boolean",
                              "null"
                            ],
                            "description": "Whether the WIP record is posted",
                            "example": true
                          },
                          "loggedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member the WIP record was logged for",
                            "example": 412
                          },
                          "officeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the office",
                            "example": 2
                          },
                          "pmsRef": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Identifier of the WIP record in the external practice management system",
                            "example": "1789456"
                          },
                          "postedDate": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "date-time",
                            "description": "When the WIP record was posted",
                            "example": "2024-01-19T05:00:00"
                          },
                          "postedStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who posted the WIP record",
                            "example": 415
                          },
                          "rawUnits": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units before rounding",
                            "example": 5
                          },
                          "serviceLineId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the service line",
                            "example": 4
                          },
                          "staffTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff type",
                            "example": 7
                          },
                          "taskTypeId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the work code (task type)",
                            "example": 12
                          },
                          "units": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Units (hours for time entries)",
                            "example": 5
                          },
                          "updatedByStaffId": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "description": "ID of the staff member who last updated the WIP record",
                            "example": 415
                          },
                          "client": {
                            "type": [
                              "object",
                              "null"
                            ],
                            "description": "Associated client information. Null when the client is not in the client view (for example an inactive client).",
                            "required": [
                              "id",
                              "name"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "example": 1561
                              },
                              "name": {
                                "type": "string",
                                "example": "TechFlow Enterprises"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "success": {
                    "summary": "WIP record found",
                    "value": {
                      "wip": [
                        {
                          "id": 89012,
                          "wipType": "Progress",
                          "loggedDate": "2024-01-17T05:00:00",
                          "wipValue": 1250,
                          "wipValueOutstanding": 0,
                          "billedAmount": 1225,
                          "writeOffAmount": 25,
                          "notes": "Consultation and analysis for Q1 financial review",
                          "clientId": 1561,
                          "jobId": 2514,
                          "isActive": true,
                          "createdAt": "2024-05-12T23:02:33.24516+00:00",
                          "updatedAt": "2024-05-12T23:02:33.24516+00:00",
                          "approvedDate": "2024-01-18T05:00:00",
                          "approvedStaffId": 412,
                          "billedPerUnit": 250,
                          "costPerUnit": 95,
                          "customFieldValues": {},
                          "deptId": 3,
                          "isApproved": true,
                          "isCreatedByAiwyn": false,
                          "isLocked": false,
                          "isManagedByAiwyn": false,
                          "isPosted": true,
                          "loggedStaffId": 412,
                          "officeId": 2,
                          "pmsRef": "1789456",
                          "postedDate": "2024-01-19T05:00:00",
                          "postedStaffId": 415,
                          "rawUnits": 5,
                          "serviceLineId": 4,
                          "staffTypeId": 7,
                          "taskTypeId": 12,
                          "units": 5,
                          "updatedByStaffId": 415,
                          "client": {
                            "id": 1561,
                            "name": "TechFlow Enterprises"
                          }
                        }
                      ]
                    }
                  },
                  "not_found": {
                    "summary": "WIP record not found",
                    "value": {
                      "wip": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - the id is not an integer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "code"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "JSON path of the failing input",
                      "example": "$"
                    },
                    "error": {
                      "type": "string",
                      "description": "Human-readable error message",
                      "example": "invalid input syntax for type integer: \"abc\""
                    },
                    "code": {
                      "type": "string",
                      "description": "Hasura error code",
                      "example": "data-exception"
                    }
                  }
                },
                "examples": {
                  "non_numeric_id": {
                    "summary": "Non-numeric id",
                    "value": {
                      "code": "data-exception",
                      "error": "invalid input syntax for type integer: \"abc\""
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions to access this WIP record"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/codes/types": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "List available time management code record types",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**List available time management code record types**\n\nReturns the code types that can be managed via the Product API under `/api/v1/codes`:\n`TimeCode`, `ExpenseCode`, `OperationalCode`, and `PtoCode`.\n",
        "operationId": "listTimeManagementCodeTypes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Code types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityTypes"
                      ],
                      "properties": {
                        "entityTypes": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "schemaUrl",
                              "isCustom"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "schemaUrl": {
                                "type": "string",
                                "description": "Schemaurl"
                              },
                              "isCustom": {
                                "type": "boolean",
                                "description": "Iscustom"
                              }
                            }
                          },
                          "description": "Entitytypes"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/codes/schema/{type}": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "Get field schema for a time management code type",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Get field schema for a time management code type**\n\nReturns field definitions for the requested code type.\n\nFor `ExpenseCode`, `code` and `display` are required; `pmsRef` defaults to `systemRef.reference`,\nand `description`, `billable`, `taxable`, `reimbursable`, and `active` are optional.\nUse `GET /api/v1/codes/schema/ExpenseCode` for the full attribute list.\n",
        "operationId": "getTimeManagementCodeSchema",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "description": "Code type, as listed by `GET /api/v1/codes/types` (for example `TimeCode`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schema retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityType",
                        "fields"
                      ],
                      "properties": {
                        "entityType": {
                          "type": "string",
                          "description": "Entitytype"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid code type"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/codes": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Create or update time management code records (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Create or update time management code records (upsert)**\n\nRecords are created if they don't exist, or updated if matched by `systemRef`.\nMaximum 100 records per request.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\nA type that is not a code type returns 400.\n\n### ExpenseCode\n\nExpense codes classify `ExpenseEntry` records. Persist them here first, then reference\nthem from entries by `code` (the exact `code` value) or by `expenseCodeId`. See the\n`ExpenseCode` request sample.\n",
        "operationId": "upsertTimeManagementCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "type": "ExpenseCode",
                    "systemRef": {
                      "system": "PM",
                      "reference": "TRAVEL"
                    },
                    "attributes": {
                      "pmsRef": "TRAVEL",
                      "code": "TRAVEL",
                      "display": "Travel",
                      "description": "Mileage, airfare and lodging",
                      "billable": true,
                      "reimbursable": true,
                      "taxable": false,
                      "active": true
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All codes processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some code records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_CODE_C)"
          },
          "422": {
            "description": "Every code record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/codes/batch/{type}": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Lookup time management code records in pages (by type)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Lookup time management code records in pages**\n\n`{type}` is any code type from `GET /api/v1/codes/types`, e.g. `/api/v1/codes/batch/ExpenseCode`.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupTimeManagementCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "description": "Code type, as listed by `GET /api/v1/codes/types` (for example `TimeCode`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/entries/types": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "List available time management entry record types",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time entry](/reference/data-dictionary/time-entry)\n\n**List available time management entry record types**\n\nReturns the entry types that can be managed via the Product API under `/api/v1/entries`:\n`TimeEntry`, `ExpenseEntry`, `OperationalEntry`, and `PtoEntry`. Expense entries share the\nupsert, schema, and lookup endpoints with time entries.\n",
        "operationId": "listTimeManagementEntryTypes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Entry types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityTypes"
                      ],
                      "properties": {
                        "entityTypes": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "schemaUrl",
                              "isCustom"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "schemaUrl": {
                                "type": "string",
                                "description": "Schemaurl"
                              },
                              "isCustom": {
                                "type": "boolean",
                                "description": "Iscustom"
                              }
                            }
                          },
                          "description": "Entitytypes"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/entries/schema/{type}": {
      "get": {
        "tags": [
          "Time Management"
        ],
        "summary": "Get field schema for a time management entry type",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time entry](/reference/data-dictionary/time-entry)\n\n**Get field schema for a time management entry type**\n\nReturns field definitions for the requested entry type.\n\nFor `TimeEntry`, the schema includes optional `taskId` (FK to Task) and `code`\n(work code string). Use `GET /api/v1/entries/schema/TimeEntry` to see the full\nattribute list for your tenant, including custom fields.\n\nFor `ExpenseEntry`, the schema includes `expenseCodeId` (FK to ExpenseCode), `billable`,\n`internalNotes`, and the optional `code` (expense code string). Use\n`GET /api/v1/entries/schema/ExpenseEntry` for the full attribute list.\n",
        "operationId": "getTimeManagementEntrySchema",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "description": "Entry type, as listed by `GET /api/v1/entries/types` (for example `TimeEntry`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schema retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityType",
                        "fields"
                      ],
                      "properties": {
                        "entityType": {
                          "type": "string",
                          "description": "Entitytype"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid entry type"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/entries": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Create or update time management entry records (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time entry](/reference/data-dictionary/time-entry)\n\n**Create or update time management entry records (upsert)**\n\nRecords are created if they don't exist, or updated if matched by top-level `systemRef`.\nMaximum 100 records per request.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\nA type that is not an entry type returns 400.\n\n### TimeEntry — hours, rate and amounts\n\n- `units` is the **hours** worked. `value` is the **amount in currency**, not the hours.\n- Omit `billedPerUnit` when your system does not know the firm's billing rates (a time-entry\n  tool, for example). Aiwyn then resolves the rate card rate for the logged staff, the work code\n  and the logged date exactly as the firm portal does, and computes `value`, `billedPerUnit`\n  and `costPerUnit` from `units`. The entry also gets an audit transaction. `value` is still\n  required by the schema: send `0`, it is overwritten.\n- Send `billedPerUnit` only when your system is the source of truth for rates (a practice\n  management system). The record is then stored exactly as sent, nothing is computed.\n- A billable work code with no active rate card rate for that staff type and date fails the\n  record with `RATE_NOT_FOUND`. Set the rate card up in Aiwyn first.\n- Re-posting an entry (same `systemRef`) without `billedPerUnit` resolves the rate again from the\n  values sent, as an edit in the firm portal does. An entry already on an invoice is locked and\n  fails the record with `LOCKED`.\n- `type` (`\"Time\"`), `billedAmount`, `writeOffAmount` and `costPerUnit` are required by the schema.\n  Send `0` for the three amounts on a new entry. `loggedDate` is an ISO-8601 date-time with zone\n  (`2026-06-17T09:00:00Z`).\n- `posted` and `approved` default to `true`: an entry posted by an external system is\n  treated as already approved and posted. Send `false` explicitly if the firm reviews\n  entries in Aiwyn before billing.\n\n### TimeEntry — identifying the work (task type)\n\nThe work code decides whether the entry is billable and which rate applies. Send one of:\n- `code` — the work code string. It must match the exact `time_management_entry_code.code`\n  value, or fall back to `task_type.code`. Stored as `entry_code_id`.\n- `taskId` — a project task. Accepts a systemRef (`{ \"system\": \"PM\", \"reference\": \"<task-pmsRef>\" }`),\n  a numeric Aiwyn id, or a string numeric id (treated as Aiwyn id). The work code is derived\n  from the task's task type when no `code` is supplied. When both are provided, `code` wins.\n\nAn entry with neither is stored as **non-billable with a zero amount**, because no rate\ncan be resolved without a work code.\n\n### Resolving task references\n\nLook up tasks before upserting entries:\n- `GET /gql/v1/task/{id}` — get a task by Aiwyn id\n- `POST /gql/v1/tasks/search` — search tasks (filter by job, assignee, task type, dates)\n\nSee `GET /api/v1/entries/schema/TimeEntry` for the full attribute list, including custom fields.\n\n### Example — time-entry tool (rate resolved by Aiwyn)\n\nSee the request sample: hours in `units`, `value` and `costPerUnit` 0,\nno `billedPerUnit`, the work code in `code`.\n\n### Example — practice management system (rate already resolved)\n\n```json\n{\n  \"records\": [\n    {\n      \"type\": \"TimeEntry\",\n      \"systemRef\": {\"system\": \"PM\", \"reference\": \"pms-entry-002\"},\n      \"attributes\": {\n        \"pmsRef\": \"pms-entry-002\",\n        \"type\": \"Time\",\n        \"loggedDate\": \"2026-06-17T14:00:00Z\",\n        \"units\": 1.0,\n        \"billedPerUnit\": 250,\n        \"value\": 250,\n        \"costPerUnit\": 90,\n        \"billedAmount\": 0,\n        \"writeOffAmount\": 0,\n        \"billable\": true,\n        \"clientId\": {\"system\": \"PM\", \"reference\": \"37584\"},\n        \"jobId\": {\"system\": \"PM\", \"reference\": \"AIWYN_29059\"},\n        \"loggedStaffId\": {\"system\": \"PM\", \"reference\": \"12345\"},\n        \"taskId\": {\"system\": \"PM\", \"reference\": \"AIWYN_98765\"}\n      }\n    }\n  ]\n}\n```\n\n### Recording an expense with ExpenseEntry\n\n`ExpenseEntry` is WIP-backed like `TimeEntry`: it carries `clientId`, `jobId`, and\n`loggedStaffId`, and the same checks apply (inactive client, inactive project,\nclient/project mismatch, inactive staff). An entry already on an invoice is locked and\nfails the record with `LOCKED`. No rate is resolved for an expense: it is stored as sent.\n\n- `type` (`\"Expense\"`), `loggedDate`, `clientId`, `loggedStaffId`, `value`, `costPerUnit`,\n  `billedAmount`, `writeOffAmount`, and `billable` are required by the schema. `value` is the\n  expense amount. Send what the firm portal stores for an expense: `units` 1, `costPerUnit` and\n  `billedPerUnit` equal to `value`, and `0` for `billedAmount` and `writeOffAmount`.\n- `posted` and `approved` default to `true`: an expense posted by an external system is\n  treated as already approved and posted. Send `false` explicitly if the firm reviews\n  expenses in Aiwyn before billing, as it does for expenses entered in the firm portal.\n- `notes` is the entry description carried on the WIP; `internalNotes` is the firm-internal note.\n\nSelect the expense code with either attribute:\n- `expenseCodeId`: the numeric Aiwyn id of an `ExpenseCode`. A non-null `expenseCodeId` wins\n  when both are supplied.\n- `code`: the exact `code` value of an `ExpenseCode`; when several codes share the value,\n  an active one is preferred. An unknown code fails the record with\n  `Unknown ExpenseEntry code`; persist codes first via `POST /api/v1/codes`.\n\nSee `GET /api/v1/entries/schema/ExpenseEntry` for the full attribute list, including custom\nfields, and the `ExpenseEntry` request example at the end of this page.\n\n### Migrating from the firm portal expense form\n\n| Firm portal field | `ExpenseEntry` attribute |\n|---|---|\n| `amount` | `value`, `costPerUnit`, and `billedPerUnit`; `units` is `1`, `billedAmount` and `writeOffAmount` are `0` |\n| `expenseCodeId` | `expenseCodeId`, or `code` |\n| `clientId`, `jobId`, `loggedStaffId` | same name; numeric Aiwyn id or `{\"system\": \"PM\", \"reference\": \"<pmsRef>\"}` |\n| `loggedDate`, `notes`, `internalNotes` | same name; `loggedDate` is an ISO-8601 date-time with offset, e.g. `2026-06-17T00:00:00Z` |\n| not on the form | `type` `\"Expense\"`; `billable` (the form copies it from the expense code); `posted` and `approved` `false` to match a form submission |\n| `wipId` | not sent; records are matched by `systemRef` |\n\n**Business Applications:**\n- Sync time entries from external time-tracking systems\n- Sync expense entries from expense-management and reimbursement systems\n- Attach project tasks to time entries\n- Upsert entries by external system reference\n\n**ExpenseEntry with expense code:**\n```json\n{\n  \"records\": [\n    {\n      \"type\": \"ExpenseEntry\",\n      \"systemRef\": {\"system\": \"PM\", \"reference\": \"beeye-expense-001\"},\n      \"attributes\": {\n        \"pmsRef\": \"beeye-expense-001\",\n        \"type\": \"Expense\",\n        \"loggedDate\": \"2026-06-17T00:00:00Z\",\n        \"value\": 123.45,\n        \"units\": 1,\n        \"costPerUnit\": 123.45,\n        \"billedPerUnit\": 123.45,\n        \"billedAmount\": 0,\n        \"writeOffAmount\": 0,\n        \"billable\": true,\n        \"notes\": \"Client site travel\",\n        \"internalNotes\": \"Mileage, 150 mi\",\n        \"clientId\": {\"system\": \"PM\", \"reference\": \"37584\"},\n        \"jobId\": {\"system\": \"PM\", \"reference\": \"AIWYN_29059\"},\n        \"loggedStaffId\": {\"system\": \"PM\", \"reference\": \"12345\"},\n        \"code\": \"TRAVEL\"\n      }\n    }\n  ]\n}\n```\n",
        "operationId": "upsertTimeManagementEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "type": "TimeEntry",
                    "systemRef": {
                      "system": "PM",
                      "reference": "laurel-entry-001"
                    },
                    "attributes": {
                      "pmsRef": "laurel-entry-001",
                      "type": "Time",
                      "loggedDate": "2026-06-17T09:00:00Z",
                      "units": 2.5,
                      "value": 0,
                      "costPerUnit": 0,
                      "billedAmount": 0,
                      "writeOffAmount": 0,
                      "notes": "Worked on tax planning deliverable",
                      "clientId": {
                        "system": "PM",
                        "reference": "37584"
                      },
                      "jobId": {
                        "system": "PM",
                        "reference": "AIWYN_29059"
                      },
                      "loggedStaffId": {
                        "system": "PM",
                        "reference": "12345"
                      },
                      "code": "TXBLE30X01"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All entries processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some entry records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_ENTRY_C)"
          },
          "422": {
            "description": "Every entry record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/entries/batch/{type}": {
      "post": {
        "tags": [
          "Time Management"
        ],
        "summary": "Lookup time management entry records in pages (by type)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time entry](/reference/data-dictionary/time-entry)\n\n**Lookup time management entry records in pages**\n\n`{type}` is any entry type from `GET /api/v1/entries/types`, e.g. `/api/v1/entries/batch/ExpenseEntry`.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupTimeManagementEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "description": "Entry type, as listed by `GET /api/v1/entries/types` (for example `TimeEntry`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-codes": {
      "post": {
        "tags": [
          "Time"
        ],
        "summary": "Create or update time codes (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Create or update time codes (upsert)**\n\nTime codes are the task types that time entries are logged against.\n\nEvery record is saved with type `TimeCode`, so records carry no `type`. Maximum 100 records per request.\n\nA record updates the code its `systemRef` names: the same `system` and `reference`, the code with\nthat Aiwyn ID when `system` is `aiwyn`, or else the code whose `pmsRef` is the `reference`. Without\na `systemRef`, it updates the code whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a\nnew code is created. Attributes left out of an update keep their values. A record with any field\nother than `systemRef` and `attributes` is rejected with 400.\nTime codes kept as task types appear in the lookup but aren't matched here, so sending one\ncreates a new time code.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | `systemRef.reference` | Reference in your practice management system. |\n| `code` | string | Yes | — | Code value that time entries reference. |\n| `display` | string | No | `code` | Name shown in Aiwyn. |\n| `description` | string | No | — | Longer description. |\n| `billable` | boolean | No | `true` | Whether time logged against the code is billable. |\n| `taxable` | boolean | No | `false` | Whether time logged against the code is taxable. |\n| `reimbursable` | boolean | No | `false` | Whether costs logged against the code are reimbursable. |\n| `active` | boolean | No | `true` | `false` deactivates the code. |\n| `rateTypeId` | integer | No | — | Aiwyn ID of the rate type used to price time on this code. |\n| `customHourlyRate` | number | No | — | Hourly rate that overrides the rate type. |\n| `taskTypeCategoryId` | integer | No | — | Aiwyn ID of the task type category. |\n| `serviceLineId` | integer | No | — | Aiwyn ID of the service line. |\n\nA new time code needs `code`, and `pmsRef` or a `systemRef`. The paged lookup and\n`GET /api/v1/time-codes/{id}` return `reimbursable` as `false`, and for time codes created here they\ndon't return `rateTypeId`, `customHourlyRate`, `taskTypeCategoryId` or `serviceLineId`; the values you\nsend are kept. A deactivated time code is no longer returned by either.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertTimeCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "ADMIN"
                    },
                    "attributes": {
                      "pmsRef": "ADMIN",
                      "code": "ADMIN",
                      "display": "Administration",
                      "billable": false,
                      "active": true
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All time codes processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_CODE_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-codes/batch": {
      "post": {
        "tags": [
          "Time"
        ],
        "summary": "Lookup time codes in pages",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Lookup time codes in pages**\n\nReturns one page of active `TimeCode` records.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupTimeCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-codes/{id}": {
      "get": {
        "tags": [
          "Time"
        ],
        "summary": "Get a time code by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Get a time code by Aiwyn ID**\n\nReturns the `TimeCode` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup.\nOnly active time codes are returned, as in the paged lookup.\nAn ID that belongs to no `TimeCode` returns 404.\n",
        "operationId": "getTimeCodeById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the code, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Time code retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "404": {
            "description": "No time code has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-entries": {
      "post": {
        "tags": [
          "Time"
        ],
        "summary": "Create or update time entries (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Create or update time entries (upsert)**\n\nEvery record is saved with type `TimeEntry`, so records carry no `type`; `attributes.type` is always\n`Time`, and a `type` sent in `attributes` is replaced. Maximum 100 records per request.\n\nA record updates the entry its `systemRef` names: the same `system` and `reference`, the entry with that\nAiwyn ID when `system` is `aiwyn`, or else the entry whose `pmsRef` is the `reference`. Without a\n`systemRef`, it updates the entry whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a new entry\nis created. Attributes left out of an update keep their values. A record with any field other than\n`systemRef` and `attributes` is rejected with 400.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | see below | Reference in your practice management system. |\n| `loggedDate` | date-time | Yes | — | When the work was done; see below. |\n| `loggedStaffId` | Aiwyn ID or `{system, reference}` | Yes | — | Staff member who did the work. |\n| `clientId` | Aiwyn ID or `{system, reference}` | Yes | — | Client the work was for. |\n| `jobId` | Aiwyn ID or `{system, reference}` | Yes | — | Project. |\n| `taskId` | Aiwyn ID or `{system, reference}` | No | — | Project task; sets the work code. |\n| `code` | string | No | — | Work code: a time code `code` (active preferred), else a task type `code`. |\n| `units` | number | No | see below | Hours worked. Always send it; see below. |\n| `value` | number | Yes | — | Amount in currency; see below. |\n| `billedPerUnit` | number | No | see below | Billing rate. |\n| `costPerUnit` | number | Yes | — | Cost rate; see below. |\n| `billedAmount` | number | Yes | — | Amount already billed. `0` for a new entry. |\n| `writeOffAmount` | number | Yes | — | Amount written off. `0` for a new entry. |\n| `billable` | boolean | No | see below | Whether the work is billable. |\n| `posted` | boolean | No | `true` | Whether the entry is posted. |\n| `approved` | boolean | No | `true` | Whether the entry is approved. |\n| `notes` | string | No | — | Entry description. |\n| `internalNotes` | string | No | — | Note for your firm. |\n| `onCalendar` | boolean | No | `false` | Whether the entry shows on the staff calendar. |\n| `active` | boolean | No | `true` | `false` deactivates the entry. |\n\nWithout `pmsRef`, a new entry takes `systemRef.reference` when `systemRef.system` is `PM`, and a generated\nreference otherwise. `loggedDate` is an ISO-8601 date-time with `Z` or an offset, for example\n`2026-06-17T00:00:00Z`; an offset is converted to UTC. A date alone, or a date-time without `Z` or an\noffset, fails with `VALIDATION_ERROR`.\n\nHow rates are set depends on whether rate resolution is enabled for your firm (ask Aiwyn support).\n\nWith rate resolution enabled, leave `billedPerUnit` out when your system does not know the firm's billing\nrates (a time-entry tool). Aiwyn rounds the hours to the firm's increment, takes `billable` from the work\ncode when you don't send it (`false` without a work code), resolves the rate card rate and average cost for\nthe staff member, the work code and the date, and computes `value`, `billedPerUnit` and `costPerUnit`; send\n`0` for `value` and `costPerUnit`. Always send `units`: without it, `value` is read as the hours. An update\nwithout `billedPerUnit` is priced again from the entry as it stands after the update, with `billable` taken\nfrom the work code unless the update sends it. That includes a submitted entry, whose rate the firm portal\nkeeps on edit. Send `billedPerUnit` when your system owns the rates (a practice management system); the\nentry is then stored as sent.\n\nWithout rate resolution, every entry is stored as sent: send `units`, `value`, `billedPerUnit` and\n`costPerUnit`; `units` defaults to `1` and `billable` to `true`.\n\nSend the work code as `code` (a time code, else a task type with that code) or as a `taskId` whose task type\nis the work code; `code` wins when both are sent. With rate resolution enabled, an entry with neither and no\n`billable` is non-billable.\n\nA record fails with `INACTIVE_CLIENT`, `INACTIVE_PROJECT` or `INACTIVE_RESOURCE` when the client, project or\nstaff member is inactive, `REFERENCE_MISMATCH` when the project belongs to another client, `LOCKED` when the\nentry is already on an invoice, `CONVERSION_ERROR` for an unknown `code`, `UNRESOLVED_REFERENCE` when a\n`{system, reference}` matches no staff member, client, project or task (an Aiwyn ID is stored as sent,\nwithout a check), `BUILD_ERROR` when a required attribute is missing, and `VALIDATION_ERROR` for a negative\n`units`, a blank `reference` in `loggedStaffId`, `clientId`, `jobId` or `taskId`, or an invalid\n`loggedDate`. With rate resolution enabled, it also fails with `RATE_NOT_FOUND` when no rate card rate or\naverage cost exists for the staff type and date, when the staff member has no staff type, or when `code` is\na billable time code with no task type of that code, and with `WORK_CODE_SERVICE_LINE_MISMATCH` when the\nwork code does not belong to the project's service line.\n\nCustom fields your firm defines for `TimeEntry` are accepted too; list them with\n`GET /api/v1/entries/schema/TimeEntry`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none succeeded —\nsee [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n\n**TimeEntry with rates (rate resolution off, or rates owned by your system):**\n```json\n{\n  \"records\": [\n    {\n      \"systemRef\": {\"system\": \"PM\", \"reference\": \"entry-002\"},\n      \"attributes\": {\n        \"loggedDate\": \"2026-06-17T00:00:00Z\",\n        \"loggedStaffId\": {\"system\": \"PM\", \"reference\": \"12345\"},\n        \"clientId\": {\"system\": \"PM\", \"reference\": \"37584\"},\n        \"jobId\": {\"system\": \"PM\", \"reference\": \"AIWYN_29059\"},\n        \"code\": \"TXBLE30X01\",\n        \"units\": 2.5,\n        \"value\": 375.00,\n        \"billedPerUnit\": 150.00,\n        \"costPerUnit\": 60.00,\n        \"billedAmount\": 0,\n        \"writeOffAmount\": 0,\n        \"billable\": true,\n        \"notes\": \"Tax planning deliverable\"\n      }\n    }\n  ]\n}\n```\n",
        "operationId": "upsertTimeEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "entry-001"
                    },
                    "attributes": {
                      "loggedDate": "2026-06-17T09:00:00Z",
                      "loggedStaffId": {
                        "system": "PM",
                        "reference": "12345"
                      },
                      "clientId": {
                        "system": "PM",
                        "reference": "37584"
                      },
                      "jobId": {
                        "system": "PM",
                        "reference": "AIWYN_29059"
                      },
                      "code": "TXBLE30X01",
                      "units": 2.5,
                      "value": 0,
                      "costPerUnit": 0,
                      "billedAmount": 0,
                      "writeOffAmount": 0,
                      "notes": "Tax planning deliverable"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All time entries processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_ENTRY_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-entries/batch": {
      "post": {
        "tags": [
          "Time"
        ],
        "summary": "Lookup time entries in pages",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Lookup time entries in pages**\n\nReturns one page of active `TimeEntry` records; a deactivated entry is not listed.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see [Time\nmanagement code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupTimeEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/time-entries/{id}": {
      "get": {
        "tags": [
          "Time"
        ],
        "summary": "Get a time entry by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Get a time entry by Aiwyn ID**\n\nReturns the `TimeEntry` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup. Only\nactive entries are returned, as in the paged lookup. An ID that belongs to no `TimeEntry` returns 404.\n",
        "operationId": "getTimeEntryById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the entry, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Time entry retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "404": {
            "description": "No time entry has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-codes": {
      "post": {
        "tags": [
          "Expenses"
        ],
        "summary": "Create or update expense codes (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Create or update expense codes (upsert)**\n\nExpense codes classify expense entries; an entry references one by its `code` or by `expenseCodeId`.\n\nEvery record is saved with type `ExpenseCode`, so records carry no `type`. Maximum 100 records per request.\n\nA record updates the code its `systemRef` names: the same `system` and `reference`, the code with\nthat Aiwyn ID when `system` is `aiwyn`, or else the code whose `pmsRef` is the `reference`. Without\na `systemRef`, it updates the code whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a\nnew code is created. Attributes left out of an update keep their values. A record with any field\nother than `systemRef` and `attributes` is rejected with 400.\nSome older expense codes appear in the lookup but aren't matched here, so sending one creates a\nnew expense code.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | see below | Reference in your practice management system. |\n| `code` | string | Yes | — | Code value that expense entries reference. |\n| `display` | string | Yes | — | Name shown in Aiwyn. |\n| `description` | string | No | — | Longer description. |\n| `billable` | boolean | No | `true` | Whether expenses on the code are billable. |\n| `taxable` | boolean | No | `false` | Whether expenses on the code are taxable. |\n| `reimbursable` | boolean | No | `false` | Whether expenses on the code are reimbursable. |\n| `active` | boolean | No | `true` | `false` deactivates the code. |\n\nWithout `pmsRef`, a new code takes `systemRef.reference` when `systemRef.system` is `PM`, and a\ngenerated reference otherwise.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertExpenseCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "TRAVEL"
                    },
                    "attributes": {
                      "pmsRef": "TRAVEL",
                      "code": "TRAVEL",
                      "display": "Travel",
                      "description": "Mileage, airfare and lodging",
                      "billable": true,
                      "reimbursable": true,
                      "taxable": false,
                      "active": true
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All expense codes processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_CODE_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-codes/batch": {
      "post": {
        "tags": [
          "Expenses"
        ],
        "summary": "Lookup expense codes in pages",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Lookup expense codes in pages**\n\nReturns one page of `ExpenseCode` records.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupExpenseCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-codes/{id}": {
      "get": {
        "tags": [
          "Expenses"
        ],
        "summary": "Get an expense code by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Get an expense code by Aiwyn ID**\n\nReturns the `ExpenseCode` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup.\nAn ID that belongs to no `ExpenseCode` returns 404.\n",
        "operationId": "getExpenseCodeById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the code, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expense code retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "404": {
            "description": "No expense code has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-entries": {
      "post": {
        "tags": [
          "Expenses"
        ],
        "summary": "Create or update expense entries (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Create or update expense entries (upsert)**\n\nEvery record is saved with type `ExpenseEntry`, so records carry no `type`; `attributes.type` is always\n`Expense`, and a `type` sent in `attributes` is replaced. Maximum 100 records per request.\n\nA record updates the entry its `systemRef` names: the same `system` and `reference`, the entry with that\nAiwyn ID when `system` is `aiwyn`, or else the entry whose `pmsRef` is the `reference`. Without a\n`systemRef`, it updates the entry whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a new entry\nis created. Attributes left out of an update keep their values. A record with any field other than\n`systemRef` and `attributes` is rejected with 400.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | see below | Reference in your practice management system. |\n| `loggedDate` | date-time | Yes | — | Date of the expense; see below. |\n| `loggedStaffId` | Aiwyn ID or `{system, reference}` | Yes | — | Staff member who incurred the expense. |\n| `clientId` | Aiwyn ID or `{system, reference}` | Yes | — | Client the expense is for. |\n| `jobId` | Aiwyn ID or `{system, reference}` | No | — | Project. |\n| `code` | string | No | — | Expense code `code`; an active code is preferred when several share it. |\n| `expenseCodeId` | integer | No | — | Aiwyn ID of the expense code; wins over `code`. |\n| `value` | number | Yes | — | Expense amount. |\n| `units` | number | No | `1` | Send `1`. |\n| `costPerUnit` | number | Yes | — | Send the expense amount. |\n| `billedPerUnit` | number | No | `0` | Send the expense amount. |\n| `billedAmount` | number | Yes | — | Amount already billed. `0` for a new expense. |\n| `writeOffAmount` | number | Yes | — | Amount written off. `0` for a new expense. |\n| `billable` | boolean | Yes | — | Whether the expense is billable. |\n| `posted` | boolean | No | `true` | Whether the expense is posted. |\n| `approved` | boolean | No | `true` | Whether the expense is approved. |\n| `notes` | string | No | — | Expense description. |\n| `internalNotes` | string | No | — | Note for your firm. |\n| `active` | boolean | No | `true` | `false` deactivates the expense. |\n\nWithout `pmsRef`, a new entry takes `systemRef.reference` when `systemRef.system` is `PM`, and a generated\nreference otherwise. `loggedDate` is an ISO-8601 date-time with `Z` or an offset, for example\n`2026-06-17T00:00:00Z`; an offset is converted to UTC. A date alone, or a date-time without `Z` or an\noffset, fails with `VALIDATION_ERROR`.\n\nNo rate is resolved for an expense; it is stored as sent. Send what the firm portal stores: `units` `1`,\n`costPerUnit` and `billedPerUnit` equal to `value`, and `0` for `billedAmount` and `writeOffAmount`. Select\nthe expense code with `code` or `expenseCodeId`.\n\nA record fails with `INACTIVE_CLIENT`, `INACTIVE_PROJECT` or `INACTIVE_RESOURCE` when the client, project or\nstaff member is inactive, `REFERENCE_MISMATCH` when the project belongs to another client, `LOCKED` when the\nentry is already on an invoice, `CONVERSION_ERROR` for an unknown `code`, `UNRESOLVED_REFERENCE` when a\n`{system, reference}` matches no staff member, client or project (an Aiwyn ID is stored as sent, without a\ncheck), `BUILD_ERROR` when a required attribute is missing, and `VALIDATION_ERROR` for a negative `units`, a\nblank `reference` in `loggedStaffId`, `clientId` or `jobId`, or an invalid `loggedDate`.\n\nReading an expense entry back (paged lookup or `GET /api/v1/expense-entries/{id}`) does not return `units`,\n`costPerUnit`, `billedPerUnit`, `billedAmount`, `writeOffAmount`, `pmsRef`, its stored `systemRef`s or\ncustom fields: they come back empty or as their defaults. The values you send are stored.\n\nCustom fields your firm defines for `ExpenseEntry` are accepted too; list them with\n`GET /api/v1/entries/schema/ExpenseEntry`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none succeeded —\nsee [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertExpenseEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "expense-001"
                    },
                    "attributes": {
                      "loggedDate": "2026-06-17T00:00:00Z",
                      "loggedStaffId": {
                        "system": "PM",
                        "reference": "12345"
                      },
                      "clientId": {
                        "system": "PM",
                        "reference": "37584"
                      },
                      "jobId": {
                        "system": "PM",
                        "reference": "AIWYN_29059"
                      },
                      "code": "TRAVEL",
                      "value": 123.45,
                      "units": 1,
                      "costPerUnit": 123.45,
                      "billedPerUnit": 123.45,
                      "billedAmount": 0,
                      "writeOffAmount": 0,
                      "billable": true,
                      "notes": "Client site travel"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All expense entries processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_ENTRY_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-entries/batch": {
      "post": {
        "tags": [
          "Expenses"
        ],
        "summary": "Lookup expense entries in pages",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Lookup expense entries in pages**\n\nReturns one page of active `ExpenseEntry` records; a deactivated entry is not listed. Records do not carry\n`units`, `costPerUnit`, `billedPerUnit`, `billedAmount`, `writeOffAmount`, `pmsRef`, stored `systemRef`s or\ncustom fields; see the upsert.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see [Time\nmanagement code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupExpenseEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/expense-entries/{id}": {
      "get": {
        "tags": [
          "Expenses"
        ],
        "summary": "Get an expense entry by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Get an expense entry by Aiwyn ID**\n\nReturns the `ExpenseEntry` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup. Only\nactive entries are returned, as in the paged lookup. An ID that belongs to no `ExpenseEntry` returns 404.\n",
        "operationId": "getExpenseEntryById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the entry, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expense entry retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "404": {
            "description": "No expense entry has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-codes": {
      "post": {
        "tags": [
          "Operational"
        ],
        "summary": "Create or update operational codes (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Create or update operational codes (upsert)**\n\nOperational codes classify non-client operational time.\n\nEvery record is saved with type `OperationalCode`, so records carry no `type`. Maximum 100 records\nper request.\n\nA record updates the code its `systemRef` names: the same `system` and `reference`, the code with\nthat Aiwyn ID when `system` is `aiwyn`, or else the code whose `pmsRef` is the `reference`. Without\na `systemRef`, it updates the code whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a\nnew code is created. Attributes left out of an update keep their values. A record with any field\nother than `systemRef` and `attributes` is rejected with 400.\nSome older operational codes appear in the lookup but aren't matched here, so sending one creates\na new operational code.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | generated | Reference in your practice management system. |\n| `code` | string | Yes | — | Code value that operational entries reference. |\n| `display` | string | Yes | — | Name shown in Aiwyn. |\n| `description` | string | No | — | Longer description. |\n| `active` | boolean | No | `true` | `false` deactivates the code. |\n\nCustom fields your firm defines for `OperationalCode` are accepted too; list them with\n`GET /api/v1/codes/schema/OperationalCode`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertOperationalCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "TRAINING"
                    },
                    "attributes": {
                      "pmsRef": "TRAINING",
                      "code": "TRAINING",
                      "display": "Internal training",
                      "active": true
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All operational codes processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_CODE_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-codes/batch": {
      "post": {
        "tags": [
          "Operational"
        ],
        "summary": "Lookup operational codes in pages",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Lookup operational codes in pages**\n\nReturns one page of `OperationalCode` records.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupOperationalCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-codes/{id}": {
      "get": {
        "tags": [
          "Operational"
        ],
        "summary": "Get an operational code by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Get an operational code by Aiwyn ID**\n\nReturns the `OperationalCode` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup.\nAn ID that belongs to no `OperationalCode` returns 404.\n",
        "operationId": "getOperationalCodeById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the code, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operational code retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "404": {
            "description": "No operational code has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-entries": {
      "post": {
        "tags": [
          "Operational"
        ],
        "summary": "Create or update operational entries (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Create or update operational entries (upsert)**\n\nEvery record is saved with type `OperationalEntry`, so records carry no `type`. Maximum 100 records per\nrequest.\n\nA record updates the entry its `systemRef` names: the same `system` and `reference`, the entry with that\nAiwyn ID when `system` is `aiwyn`, or else the entry whose `pmsRef` is the `reference`. Without a\n`systemRef`, it updates the entry whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a new entry\nis created. Attributes left out of an update keep their values. A record with any field other than\n`systemRef` and `attributes` is rejected with 400.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | generated | Reference in your practice management system. |\n| `loggedAt` | date-time | Yes | — | When the time was logged; see below. |\n| `loggedStaffId` | Aiwyn ID or `{system, reference}` | Yes | — | Staff member. |\n| `code` | string | No | — | Operational code `code`; an active code is preferred when several share it. |\n| `operationalCodeId` | integer | No | — | Aiwyn ID of the operational code; wins over `code`. |\n| `units` | number | No | `1` | Hours. |\n| `comment` | string | No | — | Comment. |\n| `internalNotes` | string | No | — | Note for your firm. |\n| `serviceLineId` | Aiwyn ID or `{system, reference}` | No | — | Service line. |\n| `status` | string | No | `DRAFT` | `DRAFT` or `SUBMITTED`. |\n| `submittedStaffId` | Aiwyn ID or `{system, reference}` | No | — | Staff member who submitted it. |\n| `submittedDate` | date-time | No | — | When it was submitted. |\n| `active` | boolean | No | `true` | `false` deactivates the entry. |\n\nSelect the operational code with `code` or `operationalCodeId`; one of them is required. `loggedAt` takes a\ndate (read as midnight), a date-time without an offset (stored as sent), or one with `Z` or an offset\n(converted to UTC).\n\nA record fails with `INACTIVE_RESOURCE` when the staff member is inactive, `CONVERSION_ERROR` for an unknown\n`code`, `UNRESOLVED_REFERENCE` when a `{system, reference}` matches no staff member, service line or\nsubmitting staff member (an Aiwyn ID is stored as sent, without a check), `BUILD_ERROR` when a required\nattribute, or both the code and its ID, are missing, and `VALIDATION_ERROR` for a negative `units` or a\nblank `reference` in `loggedStaffId`.\n\nCustom fields your firm defines for `OperationalEntry` are accepted too; list them with\n`GET /api/v1/entries/schema/OperationalEntry`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none succeeded —\nsee [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertOperationalEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "op-entry-001"
                    },
                    "attributes": {
                      "loggedAt": "2026-06-17T09:00:00Z",
                      "loggedStaffId": {
                        "system": "PM",
                        "reference": "12345"
                      },
                      "code": "TRAINING",
                      "units": 1.5,
                      "comment": "Internal training"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All operational entries processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_ENTRY_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-entries/batch": {
      "post": {
        "tags": [
          "Operational"
        ],
        "summary": "Lookup operational entries in pages",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Lookup operational entries in pages**\n\nReturns one page of active `OperationalEntry` records; a deactivated entry is not listed.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see [Time\nmanagement code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupOperationalEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/operational-entries/{id}": {
      "get": {
        "tags": [
          "Operational"
        ],
        "summary": "Get an operational entry by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Get an operational entry by Aiwyn ID**\n\nReturns the `OperationalEntry` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup.\nOnly active entries are returned, as in the paged lookup. An ID that belongs to no `OperationalEntry`\nreturns 404.\n",
        "operationId": "getOperationalEntryById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the entry, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operational entry retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "404": {
            "description": "No operational entry has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-codes": {
      "post": {
        "tags": [
          "PTO"
        ],
        "summary": "Create or update PTO codes (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Create or update PTO codes (upsert)**\n\nPTO codes classify paid time off such as vacation or sick leave.\n\nEvery record is saved with type `PtoCode`, so records carry no `type`. Maximum 100 records per request.\n\nA record updates the code its `systemRef` names: the same `system` and `reference`, the code with\nthat Aiwyn ID when `system` is `aiwyn`, or else the code whose `pmsRef` is the `reference`. Without\na `systemRef`, it updates the code whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a\nnew code is created. Attributes left out of an update keep their values. A record with any field\nother than `systemRef` and `attributes` is rejected with 400.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | generated | Reference in your practice management system. |\n| `code` | string | Yes | — | Code value that PTO entries reference. |\n| `internalNotes` | string | No | — | Notes for your firm; PTO codes have no `display`. |\n| `active` | boolean | No | `true` | `false` deactivates the code. |\n\nCustom fields your firm defines for `PtoCode` are accepted too; list them with\n`GET /api/v1/codes/schema/PtoCode`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none\nsucceeded — see [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertPtoCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "VACATION"
                    },
                    "attributes": {
                      "pmsRef": "VACATION",
                      "code": "VACATION",
                      "internalNotes": "Annual leave",
                      "active": true
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All PTO codes processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_CODE_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-codes/batch": {
      "post": {
        "tags": [
          "PTO"
        ],
        "summary": "Lookup PTO codes in pages",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Lookup PTO codes in pages**\n\nReturns one page of `PtoCode` records.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see\n[Time management code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupPtoCodes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-codes/{id}": {
      "get": {
        "tags": [
          "PTO"
        ],
        "summary": "Get a PTO code by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_CODE_R` or `TM_CODE_C`\n>\n> 📖 **Data dictionary:** [Time-management code](/reference/data-dictionary/time-management-code)\n\n**Get a PTO code by Aiwyn ID**\n\nReturns the `PtoCode` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup.\nAn ID that belongs to no `PtoCode` returns 404.\n",
        "operationId": "getPtoCodeById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the code, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "PTO code retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_CODE_R, TM_CODE_C)"
          },
          "404": {
            "description": "No PTO code has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-entries": {
      "post": {
        "tags": [
          "PTO"
        ],
        "summary": "Create or update PTO entries (upsert)",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Create or update PTO entries (upsert)**\n\nEvery record is saved with type `PtoEntry`, so records carry no `type`. Maximum 100 records per request.\n\nA record updates the entry its `systemRef` names: the same `system` and `reference`, the entry with that\nAiwyn ID when `system` is `aiwyn`, or else the entry whose `pmsRef` is the `reference`. Without a\n`systemRef`, it updates the entry whose `pmsRef` is `attributes.pmsRef`. When nothing matches, a new entry\nis created. Attributes left out of an update keep their values. A record with any field other than\n`systemRef` and `attributes` is rejected with 400.\n\n| Attribute | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `pmsRef` | string | No | generated | Reference in your practice management system. |\n| `loggedAt` | date-time | Yes | — | Day of the time off; see below. |\n| `loggedStaffId` | Aiwyn ID or `{system, reference}` | Yes | — | Staff member taking the time off. |\n| `code` | string | No | — | PTO code `code`; an active code is preferred when several share it. |\n| `ptoCodeId` | integer | No | — | Aiwyn ID of the PTO code; wins over `code`. |\n| `units` | number | No | `1` | Hours or days, as your firm records PTO. |\n| `comments` | string | No | — | Comments. |\n| `internalNotes` | string | No | — | Note for your firm. |\n| `status` | string | No | `DRAFT` | `DRAFT` or `SUBMITTED`. |\n| `submittedStaffId` | Aiwyn ID or `{system, reference}` | No | — | Staff member who submitted it. |\n| `submittedDate` | date-time | No | — | When it was submitted. |\n| `active` | boolean | No | `true` | `false` deactivates the entry. |\n\nSelect the PTO code with `code` or `ptoCodeId`; one of them is required. `loggedAt` takes a date (read as\nmidnight), a date-time without an offset (stored as sent), or one with `Z` or an offset (converted to UTC).\n\nA record fails with `INACTIVE_RESOURCE` when the staff member is inactive, `CONVERSION_ERROR` for an unknown\n`code`, `UNRESOLVED_REFERENCE` when a `{system, reference}` matches no staff member or submitting staff\nmember (an Aiwyn ID is stored as sent, without a check), `BUILD_ERROR` when a required attribute, or both\nthe code and its ID, are missing, and `VALIDATION_ERROR` for a negative `units` or a blank `reference` in\n`loggedStaffId`.\n\nCustom fields your firm defines for `PtoEntry` are accepted too; list them with\n`GET /api/v1/entries/schema/PtoEntry`.\n\nEach record succeeds or fails on its own: `200`, `207` or `422` say whether all, some or none succeeded —\nsee [Batch writes: per-record results](/reference/errors#batch-writes-per-record-results).\n",
        "operationId": "upsertPtoEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "systemRef": {
                      "system": "PM",
                      "reference": "pto-entry-001"
                    },
                    "attributes": {
                      "loggedAt": "2026-07-08T00:00:00Z",
                      "loggedStaffId": {
                        "system": "PM",
                        "reference": "12345"
                      },
                      "code": "VACATION",
                      "units": 8,
                      "comments": "Vacation"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All PTO entries processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "207": {
            "description": "Partial success - some records failed; data.records carries each record's status and error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires TM_ENTRY_C)"
          },
          "422": {
            "description": "Every record failed; data.records carries each record's error, meta.success is false",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-entries/batch": {
      "post": {
        "tags": [
          "PTO"
        ],
        "summary": "Lookup PTO entries in pages",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Lookup PTO entries in pages**\n\nReturns one page of active `PtoEntry` records; a deactivated entry is not listed.\n\nRequest body:\n`{ \"pageSize\": 25, \"page\": 0 }`\n\n`pageSize` is 1 to 100 (default 25) and `page` is a zero-based page index, not a record offset; see [Time\nmanagement code and entry lookups](/reference/pagination#time-management-code-and-entry-lookups).\n",
        "operationId": "pagedLookupPtoEntries",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pageSize": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Pagesize"
                  },
                  "page": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Page"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lookup completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "pageSize",
                        "page",
                        "returned",
                        "records"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "pageSize": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Pagesize"
                        },
                        "page": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Page"
                        },
                        "returned": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Returned"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "systemRefs",
                              "attributes"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Record type, for example `TimeCode` or `TimeEntry`."
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwyn ID of the record."
                              },
                              "systemRefs": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Every reference the record is known by, including its PM reference."
                              },
                              "attributes": {
                                "type": "object",
                                "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/pto-entries/{id}": {
      "get": {
        "tags": [
          "PTO"
        ],
        "summary": "Get a PTO entry by Aiwyn ID",
        "description": "\n> 🔐 **Required role:** `TM_ENTRY_R` or `TM_ENTRY_C`\n>\n> 📖 **Data dictionary:** [Time-management entry](/reference/data-dictionary/time-management-entry)\n\n**Get a PTO entry by Aiwyn ID**\n\nReturns the `PtoEntry` whose `aiwynId` is `id`, in the same shape as a record of the paged lookup. Only\nactive entries are returned, as in the paged lookup. An ID that belongs to no `PtoEntry` returns 404.\n",
        "operationId": "getPtoEntryById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Aiwyn ID of the entry, as returned in `aiwynId` by the upsert or the paged lookup.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "PTO entry retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "type",
                        "systemRefs",
                        "attributes"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Record type, for example `TimeCode` or `TimeEntry`."
                        },
                        "aiwynId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Aiwyn ID of the record."
                        },
                        "systemRefs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "system",
                              "reference"
                            ],
                            "properties": {
                              "system": {
                                "type": "string",
                                "description": "System"
                              },
                              "reference": {
                                "type": "string",
                                "description": "Reference"
                              }
                            }
                          },
                          "description": "Every reference the record is known by, including its PM reference."
                        },
                        "attributes": {
                          "type": "object",
                          "description": "The record's fields. Every value is a string, for example `\"true\"` for a boolean."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The ID is not a positive number"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of TM_ENTRY_R, TM_ENTRY_C)"
          },
          "404": {
            "description": "No PTO entry has this ID"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/records": {
      "post": {
        "tags": [
          "Records"
        ],
        "summary": "Create or update records (upsert)",
        "description": "\n> 🔐 **Required role:** `RECD_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Create or update records (upsert)**\n\nRecords are created if they don't exist, or updated if matched by systemRef.\n\n**Partial Success Behavior:**\n- Each record is processed independently\n- Successful records are persisted even if others fail\n- Check `summary.failed` and individual `records[].status` for failures\n- Failed records include error details in `records[].error`\n\n**Read-only and hidden custom fields:** values sent for them are ignored and the stored values are kept.\n\n**Limits:** Maximum 100 records per request.\n\n**Business Applications:**\n- Bulk record import\n- Entity synchronization\n",
        "operationId": "createOrUpdateRecords",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "type": "Client",
                    "systemRef": {
                      "system": "CCH",
                      "reference": "C-12345"
                    },
                    "attributes": {
                      "name": "Acme Corporation",
                      "email": "contact@acme.com"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Records processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires RECD_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "put": {
        "tags": [
          "Records"
        ],
        "summary": "Update records (fails if not found)",
        "description": "\n> 🔐 **Required role:** `RECD_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Update existing records only**\n\nOnly updates existing records. A record whose systemRef is not found is reported as\nfailed inside the 200 response; the request itself does not answer 404.\nThe systemRef field is required for all records in PUT requests.\n\n**Partial Success Behavior:**\n- Each record is processed independently\n- Successful records are persisted even if others fail\n- Records not found will have status `FAILED` with error code `RECORD_NOT_FOUND`\n- Check `summary.failed` and individual `records[].status` for failures\n\n**Read-only and hidden custom fields:** values sent for them are ignored and the stored values are kept.\n\n**Limits:** Maximum 100 records per request.\n\n**Business Applications:**\n- Strict update workflows\n- Guaranteed existence updates\n",
        "operationId": "updateRecords",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "type": "Client",
                    "systemRef": {
                      "system": "CCH",
                      "reference": "C-12345"
                    },
                    "attributes": {
                      "email": "updated@acme.com",
                      "phone": "555-1234"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "systemRef": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Systemref"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Attributes"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Records updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires RECD_C)"
          },
          "404": {
            "description": "Records not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "tags": [
          "Records"
        ],
        "summary": "Delete (inactivate) records",
        "description": "\n> 🔐 **Required role:** `RECD_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Delete (inactivate) records**\n\nSoft-deletes records by marking them as inactive. A record that is not found is reported\nas failed inside the 200 response; the request itself does not answer 404.\nThe systemRef field is required for all records in DELETE requests.\n\n**Partial Success Behavior:**\n- Each record is processed independently\n- Successful deletions are persisted even if others fail\n- Records not found will have status `FAILED` with error code `RECORD_NOT_FOUND`\n- Check `summary.failed` and individual `records[].status` for failures\n\n**Limits:** Maximum 100 records per request.\n\n**Business Applications:**\n- Bulk inactivation\n- Record cleanup\n",
        "operationId": "deleteRecords",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "records": [
                  {
                    "type": "Client",
                    "systemRef": {
                      "system": "CCH",
                      "reference": "C-12345"
                    }
                  },
                  {
                    "type": "Client",
                    "systemRef": {
                      "system": "aiwyn",
                      "reference": "67890"
                    }
                  }
                ]
              },
              "schema": {
                "type": "object",
                "required": [
                  "records"
                ],
                "properties": {
                  "records": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "systemRef": {
                          "type": "object",
                          "description": "Systemref"
                        }
                      }
                    },
                    "description": "Records"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Records deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "summary",
                        "records"
                      ],
                      "properties": {
                        "summary": {
                          "type": "object",
                          "description": "Summary"
                        },
                        "records": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "type",
                              "status"
                            ],
                            "properties": {
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "systemRef": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Systemref"
                              },
                              "status": {
                                "type": "string",
                                "description": "Status"
                              },
                              "aiwynId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Aiwynid"
                              },
                              "error": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "description": "Error"
                              }
                            }
                          },
                          "description": "Records"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires RECD_C)"
          },
          "404": {
            "description": "Records not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/records/types": {
      "get": {
        "tags": [
          "Records"
        ],
        "summary": "List available record types",
        "description": "\n> 🔐 **Required role:** `RECD_R` or `RECD_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**List available record types**\n\nReturns record types that can be managed via this API, with schema URLs.\n\n**Business Applications:**\n- Discover record types\n",
        "operationId": "listEntityTypes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Entity types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityTypes"
                      ],
                      "properties": {
                        "entityTypes": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "schemaUrl",
                              "isCustom"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "schemaUrl": {
                                "type": "string",
                                "description": "Schemaurl"
                              },
                              "isCustom": {
                                "type": "boolean",
                                "description": "Iscustom"
                              }
                            }
                          },
                          "description": "Entitytypes"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of RECD_R, RECD_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/records/schema/{type}": {
      "get": {
        "tags": [
          "Records"
        ],
        "summary": "Get field schema for a record type",
        "description": "\n> 🔐 **Required role:** `RECD_R` or `RECD_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Get field schema for a record type**\n\nReturns field definitions including types, validation, and foreign key relationships.\n\n**Business Applications:**\n- Dynamic form generation\n- Field validation\n- Integration mapping\n",
        "operationId": "getEntitySchema",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "description": "Record type name, built-in or custom, as listed by `GET /api/v1/records/types`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schema retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityType",
                        "fields"
                      ],
                      "properties": {
                        "entityType": {
                          "type": "string",
                          "description": "Entitytype"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid record type"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of RECD_R, RECD_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/records/custom": {
      "get": {
        "tags": [
          "Records"
        ],
        "summary": "List all custom record types",
        "description": "\n> 🔐 **Required role:** `CUSTYP_R` or `CUSTYP_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**List all custom record types**\n\nReturns all custom record type definitions for the tenant.\n\n**Query parameter:** `includeInactive` (boolean, optional, default `false`). Send\n`?includeInactive=true` to include deactivated record types.\n\n**Business Applications:**\n- Discover custom record types\n- Integration configuration\n",
        "operationId": "listCustomRecordTypes",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "includeInactive",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Record types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "entityTypes",
                        "total"
                      ],
                      "properties": {
                        "entityTypes": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "id",
                              "name",
                              "displayName",
                              "isCustom",
                              "active",
                              "fields",
                              "schemaUrl"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "description": "Id"
                              },
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "isCustom": {
                                "type": "boolean",
                                "description": "Iscustom"
                              },
                              "active": {
                                "type": "boolean",
                                "description": "Active"
                              },
                              "fields": {
                                "type": "array",
                                "items": {
                                  "type": "object"
                                },
                                "description": "Fields"
                              },
                              "recordsUrl": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Recordsurl"
                              },
                              "schemaUrl": {
                                "type": "string",
                                "description": "Schemaurl"
                              }
                            }
                          },
                          "description": "Entitytypes"
                        },
                        "total": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Total"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of CUSTYP_R, CUSTYP_C)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "post": {
        "tags": [
          "Records"
        ],
        "summary": "Create a new custom record type",
        "description": "\n> 🔐 **Required role:** `CUSTYP_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Create a new custom record type**\n\nCreates a new custom record type with the specified field schema.\nThe record type name must be unique and follow naming conventions.\n\nA name that already exists (custom or built-in, e.g. `Client`) answers **409**:\n```json\n{\n  \"error\": { \"code\": \"ERROR\", \"message\": \"Entity type 'Client' already exists\" },\n  \"meta\": { \"success\": false, \"timestamp\": \"2026-10-01T12:00:00Z\", \"version\": \"v1\" }\n}\n```\n\n**Business Applications:**\n- Define custom data structures\n- Extend system capabilities\n",
        "operationId": "createCustomRecordType",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "fields"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name"
                  },
                  "displayName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Displayname"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Description"
                  },
                  "fields": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Field name in snake_case: a lowercase letter, then lowercase letters, digits or underscores. A new name in any other form returns 400; names already on the type are kept as they are."
                        },
                        "displayName": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Displayname"
                        },
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "required": {
                          "type": "boolean",
                          "description": "Required"
                        },
                        "nullable": {
                          "type": "boolean",
                          "description": "Nullable"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "referencedEntityType": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Referencedentitytype"
                        },
                        "rank": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int32",
                          "description": "Rank"
                        }
                      }
                    },
                    "description": "Fields"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Record type created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "name",
                        "displayName",
                        "isCustom",
                        "active",
                        "fields",
                        "schemaUrl"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "name": {
                          "type": "string",
                          "description": "Name"
                        },
                        "displayName": {
                          "type": "string",
                          "description": "Displayname"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "isCustom": {
                          "type": "boolean",
                          "description": "Iscustom"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Active"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        },
                        "recordsUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Recordsurl"
                        },
                        "schemaUrl": {
                          "type": "string",
                          "description": "Schemaurl"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires CUSTYP_C)"
          },
          "409": {
            "description": "A record type with this name already exists"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/records/custom/{name}": {
      "get": {
        "tags": [
          "Records"
        ],
        "summary": "Get a custom record type by name",
        "description": "\n> 🔐 **Required role:** `CUSTYP_R` or `CUSTYP_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Get a custom record type by name**\n\nReturns the full definition of a custom record type including its field schema.\n\nA name that is unknown, or that names a built-in (non-custom) record type, answers 404.\n\n**Business Applications:**\n- View record type schema\n- Integration setup\n",
        "operationId": "getCustomRecordType",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Name of the custom record type.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Record type retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "name",
                        "displayName",
                        "isCustom",
                        "active",
                        "fields",
                        "schemaUrl"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "name": {
                          "type": "string",
                          "description": "Name"
                        },
                        "displayName": {
                          "type": "string",
                          "description": "Displayname"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "isCustom": {
                          "type": "boolean",
                          "description": "Iscustom"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Active"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        },
                        "recordsUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Recordsurl"
                        },
                        "schemaUrl": {
                          "type": "string",
                          "description": "Schemaurl"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires any of CUSTYP_R, CUSTYP_C)"
          },
          "404": {
            "description": "Record type not found, or the name is a built-in (non-custom) record type"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "put": {
        "tags": [
          "Records"
        ],
        "summary": "Update a custom record type",
        "description": "\n> 🔐 **Required role:** `CUSTYP_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Update a custom record type**\n\nUpdates an existing custom record type. Only provided fields will be updated.\nNote: Changing fields may affect existing data.\n\n`description` can be changed on its own; omit `fields` to keep the current field definitions. A type stored without field definitions needs `fields` sent with it (400 otherwise). Field names already on the type are kept as they are, even if they are not snake_case.\n\n**Business Applications:**\n- Modify record type definitions\n- Add new fields\n",
        "operationId": "updateCustomRecordType",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Name of the custom record type.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "displayName": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Displayname"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Description"
                  },
                  "fields": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Field name in snake_case: a lowercase letter, then lowercase letters, digits or underscores. A new name in any other form returns 400; names already on the type are kept as they are."
                        },
                        "displayName": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Displayname"
                        },
                        "type": {
                          "type": "string",
                          "description": "Type"
                        },
                        "required": {
                          "type": "boolean",
                          "description": "Required"
                        },
                        "nullable": {
                          "type": "boolean",
                          "description": "Nullable"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "referencedEntityType": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Referencedentitytype"
                        },
                        "rank": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int32",
                          "description": "Rank"
                        }
                      }
                    },
                    "description": "Fields"
                  },
                  "active": {
                    "type": [
                      "boolean",
                      "null"
                    ],
                    "description": "Active"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Record type updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "name",
                        "displayName",
                        "isCustom",
                        "active",
                        "fields",
                        "schemaUrl"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "name": {
                          "type": "string",
                          "description": "Name"
                        },
                        "displayName": {
                          "type": "string",
                          "description": "Displayname"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "isCustom": {
                          "type": "boolean",
                          "description": "Iscustom"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Active"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        },
                        "recordsUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Recordsurl"
                        },
                        "schemaUrl": {
                          "type": "string",
                          "description": "Schemaurl"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires CUSTYP_C)"
          },
          "404": {
            "description": "Record type not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "tags": [
          "Records"
        ],
        "summary": "Deactivate a custom record type",
        "description": "\n> 🔐 **Required role:** `CUSTYP_C`\n>\n> 📖 **Data dictionary:** [Records and custom record types](/reference/data-dictionary/custom-record)\n\n**Deactivate a custom record type**\n\nSoft-deletes a custom record type by marking it as inactive.\nExisting data is preserved but the type will no longer appear in lists.\n\n**Business Applications:**\n- Remove custom record types\n- Clean up unused definitions\n",
        "operationId": "deactivateCustomRecordType",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "name",
            "in": "path",
            "required": true,
            "description": "Name of the custom record type.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Record type deactivated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "name",
                        "displayName",
                        "isCustom",
                        "active",
                        "fields",
                        "schemaUrl"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "name": {
                          "type": "string",
                          "description": "Name"
                        },
                        "displayName": {
                          "type": "string",
                          "description": "Displayname"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "isCustom": {
                          "type": "boolean",
                          "description": "Iscustom"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Active"
                        },
                        "fields": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "name",
                              "displayName",
                              "type",
                              "required",
                              "nullable",
                              "isForeignKey",
                              "isCustomField"
                            ],
                            "properties": {
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "displayName": {
                                "type": "string",
                                "description": "Displayname"
                              },
                              "type": {
                                "type": "string",
                                "description": "Type"
                              },
                              "required": {
                                "type": "boolean",
                                "description": "Required"
                              },
                              "nullable": {
                                "type": "boolean",
                                "description": "Nullable"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "example": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Example"
                              },
                              "enumValues": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "string"
                                },
                                "description": "Enumvalues"
                              },
                              "properties": {
                                "type": [
                                  "array",
                                  "null"
                                ],
                                "items": {
                                  "type": "object"
                                },
                                "description": "Properties"
                              },
                              "isForeignKey": {
                                "type": "boolean",
                                "description": "Isforeignkey"
                              },
                              "foreignEntityType": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Foreignentitytype"
                              },
                              "isCustomField": {
                                "type": "boolean",
                                "description": "Iscustomfield"
                              }
                            }
                          },
                          "description": "Fields"
                        },
                        "recordsUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Recordsurl"
                        },
                        "schemaUrl": {
                          "type": "string",
                          "description": "Schemaurl"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires CUSTYP_C)"
          },
          "404": {
            "description": "Record type not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions/catalog": {
      "get": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Get available event types catalog",
        "description": "> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n\n**Get catalog of available event types**\n\n            Returns all entity/operation combinations that can be subscribed to.\n            Use the 'enabled' query parameter to filter by enabled status.\n\n**Business Applications:**\n- Discover available events\n- Integration planning\n",
        "operationId": "getEventSettingsCatalog",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "The catalog entries, in `data`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "entity",
                          "operation",
                          "enabled"
                        ],
                        "properties": {
                          "id": {
                            "type": [
                              "integer",
                              "null"
                            ],
                            "format": "int64"
                          },
                          "entity": {
                            "type": "string",
                            "description": "Value to send as `entityType` when creating a subscription.",
                            "example": "RequestItem"
                          },
                          "operation": {
                            "type": "string",
                            "description": "Value to send as `operation` when creating a subscription.",
                            "example": "SENT"
                          },
                          "enabled": {
                            "type": "boolean",
                            "description": "Only enabled entries can be subscribed to."
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - the request is refused for the token's tenant (see the `Tenant` header rule in the\nsecurity section). The catalog needs no Product API role: any valid bearer token can read it.\n"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions": {
      "post": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Create a webhook subscription",
        "description": "> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n\n**Create a webhook subscription for entity events**\n\n            Subscribe to receive webhook notifications when entities are created, updated, or deleted.\n            The webhook URL must use HTTPS and will receive POST requests with event data.\n\n**Business Applications:**\n- Real-time integrations\n- Event-driven workflows\n- System synchronization\n",
        "operationId": "createEventSubscription",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "entityType": "RequestItem",
                "operation": "SENT",
                "deliveryUrl": "https://example.com/webhooks/aiwyn"
              },
              "schema": {
                "type": "object",
                "required": [
                  "entityType",
                  "operation",
                  "deliveryUrl"
                ],
                "properties": {
                  "entityType": {
                    "type": "string",
                    "description": "Entity of the event, as the `entity` value of an enabled catalog entry\n(`GET /api/v1/event-subscriptions/catalog`).\n",
                    "example": "RequestItem"
                  },
                  "operation": {
                    "type": "string",
                    "description": "Operation of the event, as the `operation` value of the same catalog entry.",
                    "example": "SENT",
                    "enum": [
                      "CREATED",
                      "UPDATED",
                      "DELETED",
                      "SIGNED",
                      "EXECUTED",
                      "CANCELLED",
                      "FAILED",
                      "POSTED",
                      "APPROVED",
                      "REJECTED",
                      "COMPLETED",
                      "SENT",
                      "VIEWED",
                      "NOTIFIED",
                      "MARK_FINISHED",
                      "UNDO",
                      "MARK_NA",
                      "FILE_UPLOADED",
                      "FILE_DELETED",
                      "FILE_REPLACED",
                      "FILE_FLAGGED",
                      "FILE_ATTACHED",
                      "FILE_REMOVED",
                      "COMMENT_ADDED",
                      "DUE_DATE_ADDED",
                      "DUE_DATE_CHANGED",
                      "ASSIGNEE_ADDED",
                      "ASSIGNEE_REMOVED",
                      "REVIEWER_ADDED",
                      "REVIEWER_REMOVED",
                      "REVIEWER_CHANGED",
                      "RESTRICTED",
                      "REQUEST_REASSIGNED",
                      "CONSENT_RECORDED"
                    ]
                  },
                  "deliveryUrl": {
                    "type": "string",
                    "description": "Deliveryurl"
                  },
                  "filterExpression": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Narrows what this subscription receives. Supported values: `ownPaymentLinksOnly` (only\npayments made through quick payment links minted by the API user that owns this\nsubscription; links minted through the SafeSend application-key route have no minting\nuser and never match), `paymentLinkOnly` (payments made through any quick payment link of the\nfirm) and `allPayments` (every payment of the firm). The last two are accepted only while\nthe API user holds the `PYMT_EVNT_ALL` Product API role, and stop delivering if the firm\nrevokes it. Any other value is rejected with 400. Required for `Payment` subscriptions;\noptional for other entity types, where omitting it means every event of the entity and\noperation.\n",
                    "example": "ownPaymentLinksOnly"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Description"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Event Subscriptions created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "subscription": {
                          "type": "object",
                          "description": "Subscription"
                        },
                        "webhookSecret": {
                          "type": "string",
                          "description": "The caller's webhook signing secret. It is the same secret for every subscription of the\ncaller and can be read again with `GET /api/v1/event-subscriptions/webhook/secret`.\n"
                        },
                        "webhookSecretInstructions": {
                          "type": "string",
                          "description": "Fixed advisory text. It says the secret \"will not be shown again\"; the secret is in fact\nalso returned by `GET /api/v1/event-subscriptions/webhook/secret`.\n"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "get": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "List the caller's webhook subscriptions",
        "description": "\n> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n**List the caller's webhook subscriptions**\n\nReturns the caller's subscriptions, active and deactivated, one page at a time. The signing secret is\nnever included.\n\n**Query Parameters (all optional):**\n- `entityType` — only subscriptions for this entity (a catalog `entity` value, e.g. `RequestItem`)\n- `operation` — only subscriptions for this operation (a catalog `operation` value, e.g. `SENT`)\n- `page`, `limit` — zero-based page number and page size; see\n  [Webhook subscriptions and delivery history](/reference/pagination#webhook-subscriptions-and-delivery-history)\n\n**Response:** `data` is a page whose `content` items have the same fields as the subscription\nreturned by `PATCH /api/v1/event-subscriptions/{id}`.\n\n**Business Applications:**\n- Find subscription ids to update or deactivate\n- Audit webhook integrations\n",
        "operationId": "listEventSubscriptions",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "entityType",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "operation",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscriptions retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "content",
                        "totalElements",
                        "totalPages",
                        "currentPage",
                        "hasNext",
                        "hasPrevious"
                      ],
                      "properties": {
                        "content": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "id",
                              "entityType",
                              "operation",
                              "deliveryUrl",
                              "active",
                              "status",
                              "isInternal",
                              "eventEnabled"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "description": "Id"
                              },
                              "staffId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Staffid"
                              },
                              "entityType": {
                                "type": "string",
                                "description": "Entity of the event as a string, the catalog `entity` value (e.g. RequestItem)."
                              },
                              "operation": {
                                "type": "string",
                                "description": "Operation of the event as a string, the catalog `operation` value (e.g. SENT)."
                              },
                              "deliveryUrl": {
                                "type": "string",
                                "description": "Deliveryurl"
                              },
                              "description": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Description"
                              },
                              "filterExpression": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Filterexpression"
                              },
                              "active": {
                                "type": "boolean",
                                "description": "Whether the subscription receives deliveries; false after deactivation."
                              },
                              "status": {
                                "type": "string",
                                "description": "Not changed by deactivation, so a deactivated subscription still reports ACTIVE; use `active` instead."
                              },
                              "createdAt": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "When it was created, as Unix epoch seconds with a fractional part"
                              },
                              "updatedAt": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "When it was last updated, as Unix epoch seconds with a fractional part"
                              },
                              "isInternal": {
                                "type": "boolean",
                                "description": "Isinternal"
                              },
                              "productApiSystemUserId": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Productapisystemuserid"
                              },
                              "eventEnabled": {
                                "type": "boolean",
                                "description": "False when an admin has disabled the event; the subscription is kept but receives no deliveries."
                              }
                            }
                          },
                          "description": "Content"
                        },
                        "totalElements": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Totalelements"
                        },
                        "totalPages": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Totalpages"
                        },
                        "currentPage": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Currentpage"
                        },
                        "hasNext": {
                          "type": "boolean",
                          "description": "Hasnext"
                        },
                        "hasPrevious": {
                          "type": "boolean",
                          "description": "Hasprevious"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameters"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions/{id}": {
      "patch": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Update a webhook subscription",
        "description": "> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n\n**Update an existing webhook subscription**\n\n            Modify subscription properties such as delivery URL, filter expression, or description.\n            Only provided fields will be updated.\n\n**Business Applications:**\n- Update webhook URLs\n- Modify event filters\n",
        "operationId": "updateEventSubscription",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Event subscription id.",
            "schema": {
              "type": "integer",
              "format": "int64"
            },
            "example": 9
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "entityType": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Entity of the event, as the `entity` value of a catalog entry (`GET /api/v1/event-subscriptions/catalog`).",
                    "example": "RequestItem"
                  },
                  "operation": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Operation of the event, as the `operation` value of a catalog entry.",
                    "example": "SENT",
                    "enum": [
                      "CREATED",
                      "UPDATED",
                      "DELETED",
                      "SIGNED",
                      "EXECUTED",
                      "CANCELLED",
                      "FAILED",
                      "POSTED",
                      "APPROVED",
                      "REJECTED",
                      "COMPLETED",
                      "SENT",
                      "VIEWED",
                      "NOTIFIED",
                      "MARK_FINISHED",
                      "UNDO",
                      "MARK_NA",
                      "FILE_UPLOADED",
                      "FILE_DELETED",
                      "FILE_REPLACED",
                      "FILE_FLAGGED",
                      "FILE_ATTACHED",
                      "FILE_REMOVED",
                      "COMMENT_ADDED",
                      "DUE_DATE_ADDED",
                      "DUE_DATE_CHANGED",
                      "ASSIGNEE_ADDED",
                      "ASSIGNEE_REMOVED",
                      "REVIEWER_ADDED",
                      "REVIEWER_REMOVED",
                      "REVIEWER_CHANGED",
                      "RESTRICTED",
                      "REQUEST_REASSIGNED",
                      "CONSENT_RECORDED",
                      null
                    ]
                  },
                  "deliveryUrl": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Deliveryurl"
                  },
                  "filterExpression": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Narrows what this subscription receives. Supported values: `ownPaymentLinksOnly` (only\npayments made through quick payment links minted by the API user that owns this\nsubscription; links minted through the SafeSend application-key route have no minting\nuser and never match), `paymentLinkOnly` (payments made through any quick payment link of the\nfirm) and `allPayments` (every payment of the firm). The last two are accepted only while\nthe API user holds the `PYMT_EVNT_ALL` Product API role, and stop delivering if the firm\nrevokes it. Any other value is rejected with 400. Required for `Payment` subscriptions;\noptional for other entity types, where omitting it means every event of the entity and\noperation.\n",
                    "example": "ownPaymentLinksOnly"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Description"
                  },
                  "active": {
                    "type": [
                      "boolean",
                      "null"
                    ],
                    "description": "Active"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event Subscriptions updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "staffId",
                        "entityType",
                        "operation",
                        "deliveryUrl",
                        "description",
                        "filterExpression",
                        "active",
                        "status",
                        "createdAt",
                        "updatedAt",
                        "isInternal"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "staffId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Staffid"
                        },
                        "entityType": {
                          "type": "string",
                          "description": "Entity of the event (the catalog `entity` value).",
                          "example": "RequestItem"
                        },
                        "operation": {
                          "type": "string",
                          "description": "Operation of the event (the catalog `operation` value).",
                          "example": "SENT",
                          "enum": [
                            "CREATED",
                            "UPDATED",
                            "DELETED",
                            "SIGNED",
                            "EXECUTED",
                            "CANCELLED",
                            "FAILED",
                            "POSTED",
                            "APPROVED",
                            "REJECTED",
                            "COMPLETED",
                            "SENT",
                            "VIEWED",
                            "NOTIFIED",
                            "MARK_FINISHED",
                            "UNDO",
                            "MARK_NA",
                            "FILE_UPLOADED",
                            "FILE_DELETED",
                            "FILE_REPLACED",
                            "FILE_FLAGGED",
                            "FILE_ATTACHED",
                            "FILE_REMOVED",
                            "COMMENT_ADDED",
                            "DUE_DATE_ADDED",
                            "DUE_DATE_CHANGED",
                            "ASSIGNEE_ADDED",
                            "ASSIGNEE_REMOVED",
                            "REVIEWER_ADDED",
                            "REVIEWER_REMOVED",
                            "REVIEWER_CHANGED",
                            "RESTRICTED",
                            "REQUEST_REASSIGNED",
                            "CONSENT_RECORDED"
                          ]
                        },
                        "deliveryUrl": {
                          "type": "string",
                          "description": "Deliveryurl"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "filterExpression": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Filterexpression"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Whether the subscription receives deliveries. `false` after `DELETE /api/v1/event-subscriptions/{id}`."
                        },
                        "status": {
                          "type": "string",
                          "description": "Lifecycle status. Deactivating a subscription does not change it: a deactivated\nsubscription still reports `ACTIVE`. Use `active` to tell whether it receives deliveries.\n",
                          "example": "ACTIVE"
                        },
                        "createdAt": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "When the subscription was created, as Unix epoch seconds with a fractional part (for example `1793322409.066411`)",
                          "example": 1793322409.066411
                        },
                        "updatedAt": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "When the subscription was last updated, as Unix epoch seconds with a fractional part (for example `1793322409.066411`)",
                          "example": 1793322409.066411
                        },
                        "isInternal": {
                          "type": "boolean",
                          "description": "Isinternal"
                        },
                        "productApiSystemUserId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Product API system user that owns the subscription, when it is not owned by a staff member."
                        },
                        "eventEnabled": {
                          "type": "boolean",
                          "description": "False when an admin has disabled the event; the subscription is kept but receives no deliveries."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "404": {
            "description": "No subscription with this id belongs to the caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "meta"
                  ],
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "ERROR"
                        },
                        "message": {
                          "type": "string",
                          "example": "Subscription not found with id: 999999999"
                        },
                        "details": {}
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": false
                        },
                        "message": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Deactivate a webhook subscription",
        "description": "> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n\n**Deactivate a webhook subscription**\n\n            Soft-deletes a subscription by marking it as inactive.\n            The subscription can be reactivated later if needed.\n\n**Business Applications:**\n- Stop receiving webhooks\n- Cleanup unused subscriptions\n",
        "operationId": "deactivateEventSubscription",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Event subscription id.",
            "schema": {
              "type": "integer",
              "format": "int64"
            },
            "example": 9
          }
        ],
        "responses": {
          "200": {
            "description": "The subscription is deactivated (`active` becomes false). The body is an empty `data` object with `meta`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "description": "Always an empty object."
                    },
                    "meta": {
                      "type": "object",
                      "required": [
                        "success"
                      ],
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "example": "Event subscription deactivated successfully"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "404": {
            "description": "No active subscription with this id belongs to the caller (unknown id or already deactivated).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error",
                    "meta"
                  ],
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string",
                          "example": "ERROR"
                        },
                        "message": {
                          "type": "string",
                          "example": "Subscription with id 999999999 not found or already inactive"
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": false
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions/{id}/reactivate": {
      "post": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Reactivate a webhook subscription",
        "description": "\n> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n**Reactivate a webhook subscription**\n\nReactivates a previously deactivated subscription.\n\n**Business Applications:**\n- Restore webhook integrations\n- Resume event notifications\n",
        "operationId": "reactivateEventSubscription",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Event subscription id.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription reactivated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "entityType",
                        "operation",
                        "deliveryUrl",
                        "active",
                        "status",
                        "isInternal",
                        "eventEnabled"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "staffId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Staffid"
                        },
                        "entityType": {
                          "type": "string",
                          "description": "Entity of the event as a string, the catalog `entity` value (e.g. RequestItem)."
                        },
                        "operation": {
                          "type": "string",
                          "description": "Operation of the event as a string, the catalog `operation` value (e.g. SENT)."
                        },
                        "deliveryUrl": {
                          "type": "string",
                          "description": "Deliveryurl"
                        },
                        "description": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Description"
                        },
                        "filterExpression": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Filterexpression"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Whether the subscription receives deliveries; false after deactivation."
                        },
                        "status": {
                          "type": "string",
                          "description": "Not changed by deactivation, so a deactivated subscription still reports ACTIVE; use `active` instead."
                        },
                        "createdAt": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "When it was created, as Unix epoch seconds with a fractional part"
                        },
                        "updatedAt": {
                          "type": [
                            "number",
                            "null"
                          ],
                          "description": "When it was last updated, as Unix epoch seconds with a fractional part"
                        },
                        "isInternal": {
                          "type": "boolean",
                          "description": "Isinternal"
                        },
                        "productApiSystemUserId": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64",
                          "description": "Productapisystemuserid"
                        },
                        "eventEnabled": {
                          "type": "boolean",
                          "description": "False when an admin has disabled the event; the subscription is kept but receives no deliveries."
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Subscription filter no longer allowed"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "404": {
            "description": "Subscription not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions/{id}/deliveries": {
      "get": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Retrieve webhook delivery attempts for a subscription",
        "description": "\n> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n**Retrieve webhook delivery attempts for a subscription**\n\nReturns a paginated list of delivery attempts for webhook events for the given subscription.\nSupports filtering by HTTP status code and time range.\n\n**Query Parameters (all optional):**\n- `statusCode` — only attempts that received this HTTP status code\n- `startDate`, `endDate` (ISO-8601 date-time) — only attempts in this time range\n- `page`, `limit` — see [paging](/reference/pagination#webhook-subscriptions-and-delivery-history)\n\nA `startDate` / `endDate` that is not an ISO-8601 date-time returns 400.\n\n**Response:** `data` is a page; each `content` item is a delivery attempt `{ id, eventId, attemptNumber,\ntimestamp, statusCode, responseBody, errorMessage, deliveryUrl, deliveryTimeMs, success, createdAt }`;\n`statusCode`, `responseBody`, `errorMessage`, `deliveryTimeMs` and `createdAt` can be null.\n\n**Business Applications:**\n- Webhook troubleshooting\n- Delivery monitoring\n- Operational auditing\n",
        "operationId": "getWebhookDeliveryHistory",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Event subscription id.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "statusCode",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "startDate",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "endDate",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delivery history retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "content",
                        "totalElements",
                        "totalPages",
                        "currentPage",
                        "hasNext",
                        "hasPrevious"
                      ],
                      "properties": {
                        "content": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "id",
                              "eventId",
                              "attemptNumber",
                              "timestamp",
                              "deliveryUrl",
                              "success"
                            ],
                            "properties": {
                              "id": {
                                "type": "integer",
                                "format": "int64",
                                "description": "Id"
                              },
                              "eventId": {
                                "type": "integer",
                                "format": "int64",
                                "description": "Eventid"
                              },
                              "attemptNumber": {
                                "type": "integer",
                                "format": "int32",
                                "description": "Attemptnumber"
                              },
                              "timestamp": {
                                "type": "number",
                                "description": "When the attempt was made, as Unix epoch seconds with a fractional part."
                              },
                              "statusCode": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int32",
                                "description": "Statuscode"
                              },
                              "responseBody": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Responsebody"
                              },
                              "errorMessage": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Errormessage"
                              },
                              "deliveryUrl": {
                                "type": "string",
                                "description": "Deliveryurl"
                              },
                              "deliveryTimeMs": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Deliverytimems"
                              },
                              "success": {
                                "type": "boolean",
                                "description": "Success"
                              },
                              "createdAt": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "When the attempt was recorded, as Unix epoch seconds with a fractional part."
                              }
                            }
                          },
                          "description": "Content"
                        },
                        "totalElements": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Totalelements"
                        },
                        "totalPages": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Totalpages"
                        },
                        "currentPage": {
                          "type": "integer",
                          "format": "int32",
                          "description": "Currentpage"
                        },
                        "hasNext": {
                          "type": "boolean",
                          "description": "Hasnext"
                        },
                        "hasPrevious": {
                          "type": "boolean",
                          "description": "Hasprevious"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameters"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "404": {
            "description": "Subscription not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/event-subscriptions/webhook/secret": {
      "get": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Get webhook signing secret",
        "description": "> 🔐 **Required role:** `EVNT_SUB`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n\n**Get the webhook signing secret**\n\n            Retrieves the secret used to sign webhook payloads.\n            Use this secret to verify webhook authenticity on your server.\n            The caller has one secret for all of its subscriptions; it is the `webhookSecret` returned when a\n            subscription is created, and is created on the first call if the caller has none yet.\n\n**Business Applications:**\n- Webhook signature verification\n- Security setup\n",
        "operationId": "getSubscriptionSecret",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "The caller's webhook signing secret, in `data`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "string",
                      "description": "The webhook signing secret."
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string",
                          "example": "Webhook secret retrieved successfully"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires EVNT_SUB)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/webhook/test/generate": {
      "post": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Generate a test webhook payload and signature",
        "description": "\n> 🔐 **Required role:** `WEBHK_TST`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n**Generate a signed test webhook payload**\n\n            Generates a signature for an arbitrary JSON payload using the provided secret.\n            This is intended for debugging webhook integrations ONLY.\n\n**Business Applications:**\n- Webhook troubleshooting\n- Signature validation testing\n",
        "operationId": "generateWebhookTestPayload",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "payload": {
                  "test": true
                },
                "secret": "my-test-secret"
              },
              "schema": {
                "type": "object",
                "required": [
                  "payload",
                  "secret"
                ],
                "properties": {
                  "payload": {
                    "description": "Any JSON value to sign.",
                    "example": {
                      "test": true
                    }
                  },
                  "secret": {
                    "type": "string",
                    "description": "Secret to sign the payload with."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The payload, its signature and the secret. The body is not wrapped in `data` / `meta`.\n`signature` is `sha256=` followed by the Base64 HMAC-SHA256 of the compact JSON payload.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "payload",
                    "signature",
                    "secret"
                  ],
                  "properties": {
                    "payload": {
                      "description": "The payload from the request."
                    },
                    "signature": {
                      "type": "string",
                      "example": "sha256=Epvu8EP9JvCXSg+nVg9aTomZkJ7u3vESqWQjFs1WmkA="
                    },
                    "secret": {
                      "type": "string",
                      "description": "The secret from the request."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires WEBHK_TST)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/webhook/test/validate": {
      "post": {
        "tags": [
          "Event Subscriptions"
        ],
        "summary": "Validate a webhook signature",
        "description": "\n> 🔐 **Required role:** `WEBHK_TST`\n>\n> 📖 **Data dictionary:** [Event subscription](/reference/data-dictionary/event-subscription)\n\n**Validate a webhook signature**\n\n            Verifies that the provided signature matches the payload and secret.\n            This is intended for debugging webhook integrations ONLY.\n\n**Business Applications:**\n- Webhook troubleshooting\n- Signature validation testing\n",
        "operationId": "validateWebhookTestSignature",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "payload": {
                  "test": true
                },
                "signature": "sha256=...",
                "secret": "my-test-secret"
              },
              "schema": {
                "type": "object",
                "required": [
                  "payload",
                  "signature",
                  "secret"
                ],
                "properties": {
                  "payload": {
                    "description": "The JSON value that was signed.",
                    "example": {
                      "test": true
                    }
                  },
                  "signature": {
                    "type": "string",
                    "description": "Signature to check, `sha256=` followed by the Base64 HMAC-SHA256."
                  },
                  "secret": {
                    "type": "string",
                    "description": "Secret the payload was signed with."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The validation result, also when the signature does not match (`isValid: false`). The body is not\nwrapped in `data` / `meta`.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "isValid",
                    "payload",
                    "signature",
                    "secret"
                  ],
                  "properties": {
                    "isValid": {
                      "type": "boolean"
                    },
                    "payload": {
                      "description": "The payload from the request."
                    },
                    "signature": {
                      "type": "string",
                      "description": "The signature from the request."
                    },
                    "secret": {
                      "type": "string",
                      "description": "The secret from the request."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires WEBHK_TST)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/files": {
      "get": {
        "tags": [
          "File"
        ],
        "summary": "List files with filters and cursor pagination",
        "description": "\n> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [File](/reference/data-dictionary/file)\n\n**Retrieve a paginated list of files scoped to the tenant**\n\nReturns files across whitelisted sources: CLIENT_REQUEST, DELIVERABLE, REFERENCE_FILE, DMS_DIRECT_UPLOAD.\n\n**Optional Filters:**\n- `createdAfter` (ISO-8601) — only files created strictly after this timestamp\n- `createdBefore` (ISO-8601) — only files created strictly before this timestamp\n- `clientId` — filter by numeric client ID\n- `projectId` — filter by project/job ID\n- `ids` — filter by one or more specific file IDs (multi-value: `?ids=1&ids=2`)\n\n**Pagination:**\n- Results ordered by creation time, then id, oldest first\n- Pass `nextCursor` from a previous response as `cursor` to fetch the next page\n- `pageSize` defaults to 20, max 100 (larger values are capped at 100)\n\n**Response:** `data` is `{ items, nextCursor, hasMore }`. `nextCursor` is null when `hasMore` is false.\n\n**Fields per item** (camelCase):\n- `id` (string), `name`, `active` (always true: only active files are listed), `createdAt` (ISO-8601),\n  `updatedAt` (ISO-8601, nullable), `sizeBytes` (nullable), `path` (slash-joined folder names)\n- `downloadUrl`, `downloadUrlExpiresAt` — time-limited direct-link URL and its expiry; null unless `includeDownloadUrl=true` and the file has a DMS path or external ID. Omit this flag for metadata-only queries (pagination, search) to avoid unnecessary URL minting on every page.\n- `context` — `{ clientId, clientName, projectId, projectName, uploadedBy }`, each nullable\n\n**Note:** Invalid date formats or an invalid `cursor` return 400.\n\n**Business Applications:**\n- Retrieve all files associated with a client or project\n- Paginate through large file sets using cursor pagination\n- Filter files by upload date range\n- Fetch specific files by ID\n",
        "operationId": "listFiles",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "createdAfter",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "createdBefore",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "clientId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "clientKey",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ids",
            "in": "query",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "integer",
                "format": "int64"
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 20
            }
          },
          {
            "name": "includeDownloadUrl",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Files retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "items",
                        "hasMore"
                      ],
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": [
                              "id",
                              "name",
                              "active",
                              "createdAt",
                              "path",
                              "context"
                            ],
                            "properties": {
                              "id": {
                                "type": "string",
                                "description": "Id"
                              },
                              "name": {
                                "type": "string",
                                "description": "Name"
                              },
                              "active": {
                                "type": "boolean",
                                "description": "Whether the file is active. This list returns active files only."
                              },
                              "createdAt": {
                                "type": "string",
                                "description": "Createdat"
                              },
                              "updatedAt": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "When the file was last updated (ISO-8601)."
                              },
                              "sizeBytes": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "format": "int64",
                                "description": "Sizebytes"
                              },
                              "path": {
                                "type": "string",
                                "description": "Path"
                              },
                              "downloadUrl": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Downloadurl"
                              },
                              "downloadUrlExpiresAt": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "description": "Downloadurlexpiresat"
                              },
                              "context": {
                                "type": "object",
                                "description": "Context"
                              }
                            }
                          },
                          "description": "Items"
                        },
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Nextcursor"
                        },
                        "hasMore": {
                          "type": "boolean",
                          "description": "Hasmore"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN)"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/v1/files/{id}": {
      "get": {
        "tags": [
          "File"
        ],
        "summary": "Get file metadata by ID",
        "description": "\n> 🔐 **Required role:** `API_ADMIN`\n>\n> 📖 **Data dictionary:** [File](/reference/data-dictionary/file)\n\nA key issued in the Firm Portal also needs `FILE_R` to send `includeDownloadUrl=true`; without it the\ncall returns `403`.\n\n**Retrieve file metadata by Aiwyn ID**\n\nReturns file metadata including filename, source type, status, and optional download URL.\n\n**Query Parameters:**\n- `includeDownloadUrl` (optional, default: false) - When true, generates a time-limited signed download URL\n\n**Response:** `data` is the file:\n- `id` (number; `GET /api/v1/files` returns the same id as a string), `filename`, `fileSource`,\n  `fileStatus` (nullable), `active`, `createdAt`, `updatedAt`, `externalDmsFileId` (nullable)\n- `fileInfo` (nullable) — `{ id, size, createdByStaffId, createdByContactId, createdAt, updatedAt }`\n- `downloadUrl` — signed download URL, present only when includeDownloadUrl=true and the file has a GCS path\n\n**Note:** Download URLs are time-limited (15 minutes) and should be used promptly.\n\n**Business Applications:**\n- Retrieve file metadata for display\n- Generate download URLs for file access\n- Verify file existence and status\n",
        "operationId": "getFileById",
        "security": [
          {
            "BearerAuth": [],
            "CfAccessClientId": [],
            "CfAccessClientSecret": []
          },
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "File id.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "includeDownloadUrl",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "filename",
                        "fileSource",
                        "active"
                      ],
                      "properties": {
                        "id": {
                          "type": "integer",
                          "format": "int64",
                          "description": "Id"
                        },
                        "filename": {
                          "type": "string",
                          "description": "Filename"
                        },
                        "fileSource": {
                          "type": "string",
                          "description": "Filesource"
                        },
                        "fileStatus": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Filestatus"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Active"
                        },
                        "createdAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "description": "Createdat"
                        },
                        "updatedAt": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time",
                          "description": "Updatedat"
                        },
                        "externalDmsFileId": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Externaldmsfileid"
                        },
                        "fileInfo": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Fileinfo"
                        },
                        "downloadUrl": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Downloadurl"
                        }
                      }
                    },
                    "error": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized - Invalid or missing authentication token"
          },
          "403": {
            "description": "Forbidden - Insufficient permissions (requires API_ADMIN)"
          },
          "404": {
            "description": "File not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    }
  },
  "webhooks": {
    "event": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Event delivery",
        "operationId": "eventDelivery",
        "description": "Aiwyn sends this request to a subscription's `deliveryUrl` each time an event it subscribes to happens\n(an `entityType` and `operation` from `GET /api/v1/event-subscriptions/catalog`). One request carries one\nevent.\n\nThe same URL can also receive a `subscription.disabled` notification, which is not an event: its body is\n`{type, timestamp, tenant, subscriptionId, deliveryUrl, consecutiveFailures, reason, lastStatusCode,\nlastErrorMessage}`, it carries `X-Aiwyn-Notification-Type: subscription.disabled` and none of the\n`X-Aiwyn-Event-Id`, `X-Aiwyn-Event-Operation` or `X-Aiwyn-Delivery-Id` headers. Its `X-Signature` is\ncomputed the same way. Check `X-Aiwyn-Notification-Type` before parsing a request as an event.\n\n**Verify the signature before trusting the body.** `X-Signature` is `sha256=` followed by the Base64\nHMAC-SHA256 of the raw request body, keyed with your signing secret\n(`GET /api/v1/event-subscriptions/webhook/secret`). Compute it over the bytes you received, before\nparsing the JSON, and compare in constant time. `POST /api/v1/webhook/test/generate` and\n`POST /api/v1/webhook/test/validate` let you check your implementation.\n\n**Respond with any `2xx` within 30 seconds.** The response body is ignored.\n\n- A `5xx` response or a connection error is retried up to two more times, about a minute and then five\n  minutes later, with the same `X-Aiwyn-Event-Id` and a new `X-Aiwyn-Delivery-Id`. Any other non-`2xx`\n  response, or no response within 30 seconds, is not retried. Reconcile missed events through the API.\n- A slow endpoint may still process a timed-out request, so acknowledge first and do the work\n  afterwards.\n- The same change can be reported twice, as two events with different ids, so check whether you have\n  already handled the change (the record's current state, or `entityType`, `entityId` and `type`)\n  rather than relying on `X-Aiwyn-Event-Id` alone.\n- Deliveries are not guaranteed to arrive in event order; use `event.eventTimestamp` to order them.\n\n**Consent events** (`Engagement` `CONSENT_RECORDED`) fire once a consent document's signers have settled\non an outcome. With\n`ALL_SIGNATURES_REQUIRED`, every signer agreed (`AFFIRMATIVE`) or one declined (`NEGATIVE`). With\n`ONE_SIGNATURE_REQUIRED`, one signer agreed (`AFFIRMATIVE`) or every signer declined (`NEGATIVE`). They fire\nwhen the consent is answered, whether or not the engagement goes on to be signed. `event.data.metadata`\ncarries `engagementDocumentId`, `signatureRequirementType`, `consentStatus`, `decidedAt` and one entry per\nsigner in `signers`; `event.data.relatedEntitiesData` carries the engagement's clients, client groups and\njobs. An answer given after the outcome is settled raises no new event. A paper consent the firm records\nwhen it executes an engagement manually raises the same event, with the staff member as the actor.\n`decidedAt` and `consentProvidedAt` have no offset: portal answers are in UTC, and a paper consent carries\nthe time the firm entered. `decidedAt` is `null` for a decline recorded without a date.\n\n**File events** (`entityType` `File`) are only delivered to an `https` URL. `event.data.primaryRecord.file`\ncarries a short-lived signed `downloadUrl` (except for `DELETED`), and `event.data.metadata` is omitted.\n\n**Request item events** (`RequestItem` `SENT`, `APPROVED`, `REJECTED`) carry the item in\n`event.data.primaryRecord`. `event.data.metadata` carries the item's previous status in `status_old`, plus\n`recipients` (`id`, `name`, `email`) for `SENT` and the reviewer's `notes` for `REJECTED`.\n\n**`ClientRequest` `VIEWED`** is sent each time a staff member opens a client request in the Firm Portal.\n`event.entityId` is the client request's id. `event.data.primaryRecord` and `relatedEntitiesData` are\n`null`, so fetch the client request by that id if you need it, and don't rely on `metadata`.\n\nEvery attempt, with its status code and response, is listed by\n`GET /api/v1/event-subscriptions/{id}/deliveries`.\n",
        "security": [],
        "parameters": [
          {
            "name": "X-Signature",
            "in": "header",
            "required": true,
            "description": "`sha256=` followed by the Base64 HMAC-SHA256 of the raw body, keyed with your signing secret.",
            "schema": {
              "type": "string"
            },
            "example": "sha256=Epvu8EP9JvCXSg+nVg9aTomZkJ7u3vESqWQjFs1WmkA="
          },
          {
            "name": "X-Aiwyn-Event-Id",
            "in": "header",
            "required": true,
            "description": "The event's id, the same as `event.id`.",
            "schema": {
              "type": "string"
            },
            "example": "7001"
          },
          {
            "name": "X-Aiwyn-Event-Operation",
            "in": "header",
            "required": true,
            "description": "The event's operation, the same as `event.type`.",
            "schema": {
              "type": "string"
            },
            "example": "POSTED"
          },
          {
            "name": "X-Aiwyn-Subscription-Id",
            "in": "header",
            "required": true,
            "description": "The id of the subscription this delivery is for.",
            "schema": {
              "type": "string"
            },
            "example": "9"
          },
          {
            "name": "X-Aiwyn-Delivery-Id",
            "in": "header",
            "required": true,
            "description": "Unique per request, including a repeated delivery of the same event.",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "example": "0f6b1f7c-3c43-4c38-9a0e-0d3b8f7b2a51"
          },
          {
            "name": "X-Aiwyn-Timestamp",
            "in": "header",
            "required": true,
            "description": "When this attempt was sent (ISO 8601, UTC).",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "example": "2026-11-01T18:04:05.123Z"
          },
          {
            "name": "X-Aiwyn-Tenant",
            "in": "header",
            "required": true,
            "description": "Your firm's tenant identifier.",
            "schema": {
              "type": "string"
            },
            "example": "acmecpa"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookDelivery"
              },
              "examples": {
                "payment": {
                  "summary": "A payment is posted (primaryRecord abridged)",
                  "value": {
                    "event": {
                      "id": 7001,
                      "type": "POSTED",
                      "entityType": "Payment",
                      "entityId": "48213",
                      "eventTimestamp": "2026-11-01T18:04:03.517Z",
                      "data": {
                        "tenant": "acmecpa",
                        "primaryRecord": {
                          "paymentMethod": "card",
                          "cardType": "visa",
                          "last4": "4242",
                          "postedToBank": false,
                          "isAutomatic": false
                        },
                        "relatedEntitiesData": null,
                        "metadata": {
                          "paymentLinkMetadata": {
                            "orderRef": "INV-2026-0042"
                          }
                        }
                      }
                    },
                    "subscription": {
                      "id": 9,
                      "description": "Post payments to our ERP"
                    }
                  }
                },
                "consent": {
                  "summary": "A client declines a consent (primaryRecord and relatedEntitiesData abridged)",
                  "value": {
                    "event": {
                      "id": 7003,
                      "type": "CONSENT_RECORDED",
                      "entityType": "Engagement",
                      "entityId": "3120",
                      "eventTimestamp": "2026-11-01T18:20:00.000Z",
                      "data": {
                        "tenant": "acmecpa",
                        "primaryRecord": {
                          "id": 3120,
                          "name": "2026 Individual Tax Return",
                          "clientId": 1001,
                          "status": "SENT"
                        },
                        "relatedEntitiesData": {
                          "Client": [
                            {
                              "id": 1001,
                              "name": "Sarah Johnson"
                            }
                          ],
                          "ClientGroup": [],
                          "Job": [
                            {
                              "id": 5521,
                              "name": "2026 1040"
                            }
                          ]
                        },
                        "metadata": {
                          "engagementDocumentId": 8840,
                          "engagementDocumentTypeId": 4,
                          "signatureRequirementType": "ALL_SIGNATURES_REQUIRED",
                          "consentStatus": "NEGATIVE",
                          "decidedAt": "2026-11-01T18:19:58.402",
                          "signers": [
                            {
                              "engagementDocumentContactId": 9911,
                              "contactId": 2044,
                              "consentStatus": "NEGATIVE",
                              "consentProvidedAt": "2026-11-01T18:19:58.402"
                            }
                          ]
                        }
                      }
                    },
                    "subscription": {
                      "id": 14,
                      "description": "Write 7216 status to our workflow tool"
                    }
                  }
                },
                "file": {
                  "summary": "A file is uploaded",
                  "value": {
                    "event": {
                      "id": 7002,
                      "type": "CREATED",
                      "entityType": "File",
                      "entityId": "1024",
                      "eventTimestamp": "2026-11-01T18:10:00.000Z",
                      "data": {
                        "tenant": "acmecpa",
                        "primaryRecord": {
                          "eventType": "file.created",
                          "timestamp": "2026-11-01T18:10:00.000Z",
                          "file": {
                            "id": 1024,
                            "name": "2025-tax-return.pdf",
                            "sizeBytes": 482113,
                            "path": "Clients/Sarah Johnson/2025",
                            "clientId": 1001,
                            "clientName": "Sarah Johnson",
                            "downloadUrl": "https://storage.googleapis.com/example-bucket/2025-tax-return.pdf?X-Goog-Signature=...",
                            "downloadUrlExpiresAt": "2026-11-01T19:10:00Z"
                          }
                        },
                        "relatedEntitiesData": null
                      }
                    },
                    "subscription": {
                      "id": 12,
                      "description": "Archive client uploads"
                    }
                  }
                },
                "requestItem": {
                  "summary": "A request item is sent to the client (primaryRecord abridged)",
                  "value": {
                    "event": {
                      "id": 7004,
                      "type": "SENT",
                      "entityType": "RequestItem",
                      "entityId": "6612",
                      "eventTimestamp": "2026-11-01T18:30:00.000Z",
                      "data": {
                        "tenant": "acmecpa",
                        "primaryRecord": {
                          "id": 6612,
                          "clientRequestSectionId": 802,
                          "name": "2025 W-2 forms",
                          "status": "OPEN",
                          "dueDate": "2026-12-01"
                        },
                        "relatedEntitiesData": null,
                        "metadata": {
                          "status_old": "TO_DO",
                          "recipients": [
                            {
                              "id": 2044,
                              "name": "Sarah Johnson",
                              "email": "sarah.johnson@example.com"
                            }
                          ]
                        }
                      }
                    },
                    "subscription": {
                      "id": 15,
                      "description": "Track document requests"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Delivered. Any `2xx` status counts; the body is ignored."
          },
          "4XX": {
            "description": "Not delivered and not retried."
          },
          "5XX": {
            "description": "Not delivered and not retried."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "description": "Standard error response format",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable error message",
            "example": "pageSize must be an integer from 1 to 1000"
          },
          "code": {
            "type": "string",
            "description": "Machine-readable error code. Absent when the gateway rejects `pageSize` or `page`\nbefore the query runs; present on errors from the query itself.\n",
            "example": "validation-failed"
          },
          "details": {
            "type": "string",
            "description": "Additional error context"
          }
        }
      },
      "DraftInvoiceHistory": {
        "type": "object",
        "description": "Draft invoice history record with client and draft invoice details",
        "required": [
          "clientId",
          "invoiceId",
          "jobId",
          "client",
          "draftInvoice"
        ],
        "properties": {
          "clientId": {
            "type": "integer",
            "description": "Client identifier",
            "example": 7720
          },
          "invoiceId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Identifier of the posted invoice. Null until the draft has produced an invoice.",
            "example": 125890
          },
          "jobId": {
            "type": "integer",
            "description": "Associated job/project identifier",
            "example": 2514
          },
          "client": {
            "type": "object",
            "description": "Client summary information",
            "required": [
              "active",
              "clientRef",
              "name",
              "pmsRef"
            ],
            "properties": {
              "active": {
                "type": "boolean",
                "example": true
              },
              "clientRef": {
                "type": "string",
                "example": "TF-2024-789"
              },
              "name": {
                "type": "string",
                "example": "TechFlow Enterprises"
              },
              "pmsRef": {
                "type": "string",
                "example": "240815"
              }
            }
          },
          "draftInvoice": {
            "type": [
              "object",
              "null"
            ],
            "description": "Draft invoice metadata. Null when the history record has no draft invoice\nor the draft's AR transaction is inactive.\n",
            "required": [
              "approvedAt",
              "arTranId",
              "approverStaffId",
              "approvedByStaffId",
              "invoiceId",
              "isActive",
              "pms_invoice_number",
              "status",
              "attachTimeEntries",
              "automaticallyBillOn",
              "billAddressContactInfoId",
              "billerStaffId",
              "createdAt",
              "createdByStaffId",
              "currentAssignedStaffId",
              "deliveryMethod",
              "emailRecipients",
              "expenseLineItemStrategy",
              "invoiceDate",
              "lineItemStrategy",
              "postOn",
              "reversalReason",
              "reversedAt",
              "reversedByStaffId",
              "reviewedAt",
              "reviewedByStaffId",
              "reviewerStaffId",
              "scheduledByStaffId",
              "senderStaffId",
              "timeEntryGrouping",
              "timeEntryPageOrientation",
              "updatedAt",
              "wipUnbilledAsOf"
            ],
            "properties": {
              "approvedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "Approval timestamp. Null until the draft is approved.",
                "example": "2024-03-15T14:32:18+00:00"
              },
              "arTranId": {
                "type": "integer",
                "description": "AR transaction identifier of the draft invoice",
                "example": 125880
              },
              "approverStaffId": {
                "type": "integer",
                "example": 301
              },
              "approvedByStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Staff who approved the draft. Null until the draft is approved.",
                "example": 301
              },
              "invoiceId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the posted invoice. Null until the draft is posted.",
                "example": 125890
              },
              "isActive": {
                "type": "boolean",
                "example": true
              },
              "pms_invoice_number": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Invoice number in the practice management system. Null unless the draft was pushed to a PMS.",
                "example": null
              },
              "status": {
                "type": "string",
                "example": "APPROVED"
              },
              "attachTimeEntries": {
                "type": [
                  "boolean",
                  "null"
                ],
                "description": "Whether time entries are attached to the invoice",
                "example": false
              },
              "automaticallyBillOn": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "When the draft is scheduled to bill automatically. Null when it is not scheduled.",
                "example": null
              },
              "billAddressContactInfoId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the contact info used as the bill-to address",
                "example": 4410
              },
              "billerStaffId": {
                "type": "integer",
                "description": "Identifier of the biller staff member",
                "example": 301
              },
              "createdAt": {
                "type": "string",
                "format": "date-time",
                "description": "When the draft was created",
                "example": "2024-05-12T22:50:20.595961+00:00"
              },
              "createdByStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the staff member who created the draft",
                "example": 301
              },
              "currentAssignedStaffId": {
                "type": "integer",
                "description": "Identifier of the staff member the draft is currently assigned to",
                "example": 301
              },
              "deliveryMethod": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "How the invoice will be delivered: EMAIL, DOWNLOAD, EMAIL_AND_DOWNLOAD or POST_ONLY",
                "example": "EMAIL"
              },
              "emailRecipients": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Email recipients for the invoice",
                "example": "ap@techflow.example"
              },
              "expenseLineItemStrategy": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "How expenses are presented as line items: SINGLE_LINE, HIDE or ALL",
                "example": "HIDE"
              },
              "invoiceDate": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date",
                "description": "Invoice date to use when the draft is billed",
                "example": null
              },
              "lineItemStrategy": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "How time is presented as line items",
                "example": "JOB"
              },
              "postOn": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date",
                "description": "Date the invoice is scheduled to post",
                "example": null
              },
              "reversalReason": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Reason the draft was reversed",
                "example": null
              },
              "reversedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "When the draft was reversed",
                "example": null
              },
              "reversedByStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the staff member who reversed the draft",
                "example": null
              },
              "reviewedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "When the draft was reviewed",
                "example": "2024-03-14T10:05:00+00:00"
              },
              "reviewedByStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the staff member who reviewed the draft",
                "example": 301
              },
              "reviewerStaffId": {
                "type": "integer",
                "description": "Identifier of the reviewer staff member",
                "example": 301
              },
              "scheduledByStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Identifier of the staff member who scheduled the draft",
                "example": null
              },
              "senderStaffId": {
                "type": "integer",
                "description": "Identifier of the sender staff member",
                "example": 301
              },
              "timeEntryGrouping": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "How attached time entries are grouped",
                "example": null
              },
              "timeEntryPageOrientation": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Page orientation of attached time entries",
                "example": null
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time",
                "description": "When the draft was last updated",
                "example": "2024-05-12T22:50:20.595961+00:00"
              },
              "wipUnbilledAsOf": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time",
                "description": "Cut-off date for unbilled WIP included in the draft",
                "example": null
              }
            }
          }
        }
      },
      "DraftInvoiceHistoryListResponse": {
        "type": "object",
        "description": "Standard response format for draft invoice history endpoints",
        "required": [
          "draftInvoices",
          "total"
        ],
        "properties": {
          "draftInvoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DraftInvoiceHistory"
            }
          },
          "total": {
            "type": "object",
            "properties": {
              "aggregate": {
                "type": "object",
                "properties": {
                  "count": {
                    "type": "integer",
                    "description": "Total number of draft invoice history records matching criteria",
                    "example": 94
                  }
                }
              }
            }
          }
        }
      },
      "ClientStaffMember": {
        "type": "object",
        "description": "Staff member assigned to a client or client group (partner, manager, billing manager)",
        "required": [
          "id",
          "firstName",
          "lastName",
          "email"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 53
          },
          "firstName": {
            "type": "string",
            "example": "Allen"
          },
          "lastName": {
            "type": "string",
            "example": "Hermiston"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "example": "allen.hermiston@company.com"
          }
        }
      },
      "ClientGroup": {
        "type": "object",
        "description": "Client group record with assigned staff and office information",
        "required": [
          "id",
          "name",
          "pmsRef",
          "parentClientId",
          "primaryContactId",
          "billingContactId",
          "partnerStaffId",
          "managerStaffId",
          "officeId",
          "active",
          "isManagedByAiwyn",
          "createdAt",
          "updatedAt",
          "version",
          "customFieldValues",
          "partnerStaff",
          "managerStaff",
          "office"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique client group identifier",
            "example": 10
          },
          "name": {
            "type": "string",
            "description": "Client group name",
            "example": "Acme Corp Group"
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice Management System reference",
            "example": "GRP-001"
          },
          "parentClientId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the parent client, if any",
            "example": null
          },
          "primaryContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the primary contact",
            "example": 201
          },
          "billingContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the billing contact",
            "example": 202
          },
          "partnerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the assigned partner staff member",
            "example": 101
          },
          "managerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the assigned manager staff member",
            "example": 102
          },
          "officeId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the associated office",
            "example": 5
          },
          "active": {
            "type": "boolean",
            "description": "Whether the client group is active",
            "example": true
          },
          "isManagedByAiwyn": {
            "type": "boolean",
            "description": "Whether the client group is managed by Aiwyn",
            "example": false
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Record creation timestamp",
            "example": "2024-01-15T10:00:00.000000+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Last modification timestamp",
            "example": "2024-06-20T14:30:00.000000+00:00"
          },
          "version": {
            "type": "integer",
            "description": "Record version number",
            "example": 3
          },
          "customFieldValues": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Firm-defined custom fields for the client group, keyed by custom field code",
            "example": {
              "region": "West"
            }
          },
          "partnerStaff": {
            "description": "Assigned partner staff member; null when the group has no partner",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "managerStaff": {
            "description": "Assigned manager staff member; null when the group has no manager",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "office": {
            "type": [
              "object",
              "null"
            ],
            "description": "Associated office; null when the group has no office",
            "required": [
              "id",
              "pmsRef",
              "name"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 5
              },
              "pmsRef": {
                "type": "string",
                "example": "OFF-5"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "San Francisco"
              }
            }
          }
        }
      },
      "ClientBusinessEntityRef": {
        "type": "object",
        "description": "Business entity (entity type) classification of a client",
        "required": [
          "id",
          "name",
          "ref",
          "clientBusinessEntityType",
          "pmsRefs"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 4
          },
          "name": {
            "type": "string",
            "example": "S Corporation"
          },
          "ref": {
            "type": "string",
            "example": "SCORP"
          },
          "clientBusinessEntityType": {
            "type": "string",
            "example": "Business"
          },
          "pmsRefs": {
            "type": "string",
            "description": "Practice Management System reference of the business entity",
            "example": "SCORP"
          }
        }
      },
      "Client": {
        "type": "object",
        "description": "Client record as returned by `POST /gql/v1/clients` and `POST /gql/v1/clients/search`.\nEvery listed property is always present; foreign keys and relationships whose column\nis optional are `null` when unset.\n",
        "required": [
          "id",
          "pmsRef",
          "clientRef",
          "name",
          "active",
          "ebilling",
          "emailStatement",
          "chargeAdminFee",
          "clientContactInfoId",
          "excludeFromCollections",
          "default_billing_day",
          "prefContactId",
          "billingContactId",
          "billingClientId",
          "departmentId",
          "officeId",
          "industryId",
          "clientGroupId",
          "partnerStaffId",
          "managerStaffId",
          "staffBillingManagerId",
          "clientTypeId",
          "clientBusinessEntityId",
          "fiscalYearEndMonth",
          "fiscalYearEndDay",
          "createdAt",
          "updatedAt",
          "customFieldValues",
          "orgId",
          "clientKey",
          "updateByStaffId",
          "exclusionStatusUpdatedAt",
          "isManagedByAiwyn",
          "isCreatedByAiwyn",
          "originatingPartnerStaffId",
          "billingNotes",
          "description",
          "notes",
          "noticePeriod",
          "secondaryContactId",
          "fein",
          "status",
          "invoiceDeliveryMethod",
          "mergedInto",
          "inactivateMergedRecord",
          "department",
          "office",
          "industry",
          "clientType",
          "clientBusinessEntity",
          "entityType",
          "partnerStaff",
          "managerStaff",
          "billManager",
          "relationshipOwner"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique client identifier",
            "example": 2180
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice Management System reference",
            "example": "1155"
          },
          "clientRef": {
            "type": "string",
            "description": "External client reference number",
            "example": "41664"
          },
          "name": {
            "type": "string",
            "description": "Client full name or company name",
            "example": "Aaron Fahey"
          },
          "active": {
            "type": "boolean",
            "description": "Client active status",
            "example": true
          },
          "ebilling": {
            "type": "boolean",
            "description": "Whether the client receives electronic billing",
            "example": true
          },
          "emailStatement": {
            "type": "boolean",
            "description": "Whether statements are emailed to the client",
            "example": true
          },
          "chargeAdminFee": {
            "type": "boolean",
            "description": "Whether an administrative fee is charged to the client",
            "example": false
          },
          "clientContactInfoId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client's own contact info (address) record",
            "example": 9957
          },
          "excludeFromCollections": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the client is excluded from collections",
            "example": false
          },
          "default_billing_day": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Default day of the month on which the client is billed",
            "example": null
          },
          "prefContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the preferred contact",
            "example": 601
          },
          "billingContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the billing contact",
            "example": null
          },
          "billingClientId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client billed on this client's behalf",
            "example": null
          },
          "departmentId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client's department",
            "example": 3
          },
          "officeId": {
            "type": "integer",
            "description": "ID of the client's office",
            "example": 1
          },
          "industryId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client's industry",
            "example": null
          },
          "clientGroupId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client group the client belongs to",
            "example": null
          },
          "partnerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of assigned partner staff member; null when the client has no partner",
            "example": 53
          },
          "managerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of assigned manager staff member; null when the client has no manager",
            "example": 19
          },
          "staffBillingManagerId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the staff member who is the client's billing manager",
            "example": null
          },
          "clientTypeId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client type",
            "example": 7
          },
          "clientBusinessEntityId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client business entity (entity type)",
            "example": 4
          },
          "fiscalYearEndMonth": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Month (1-12) of the client's fiscal year end",
            "example": 12
          },
          "fiscalYearEndDay": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Day (1-31) of the client's fiscal year end",
            "example": 31
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Client record creation timestamp",
            "example": "2023-05-12T22:43:55.488054+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Last modification timestamp",
            "example": "2023-06-09T21:34:28.817274+00:00"
          },
          "customFieldValues": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom field values for the client, keyed by custom field code",
            "example": {
              "industry_niche": "Manufacturing",
              "naics_code": "333120"
            }
          },
          "orgId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the client's organization",
            "example": null
          },
          "clientKey": {
            "type": [
              "string",
              "null"
            ],
            "description": "Unique business key for the client",
            "example": "AARON-FAHEY"
          },
          "updateByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the staff member who last updated the client",
            "example": 53
          },
          "exclusionStatusUpdatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the collections exclusion setting was last changed",
            "example": "2023-05-12T22:43:55.488054+00:00"
          },
          "isManagedByAiwyn": {
            "type": "boolean",
            "description": "Whether Aiwyn manages the record's lifecycle",
            "example": false
          },
          "isCreatedByAiwyn": {
            "type": "boolean",
            "description": "Whether the record was created in Aiwyn",
            "example": false
          },
          "originatingPartnerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the staff member who is the client's originating partner",
            "example": null
          },
          "billingNotes": {
            "type": [
              "string",
              "null"
            ],
            "description": "Notes about the client's billing",
            "example": null
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "description": "Description of the client",
            "example": null
          },
          "notes": {
            "type": [
              "string",
              "null"
            ],
            "description": "Notes about the client",
            "example": null
          },
          "noticePeriod": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Notice period, in days, for ending work with the client",
            "example": null
          },
          "secondaryContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ID of the secondary contact",
            "example": null
          },
          "fein": {
            "type": [
              "string",
              "null"
            ],
            "description": "Federal Employer Identification Number",
            "example": "12-3456789"
          },
          "status": {
            "type": "string",
            "description": "Status of the client, for example ACTIVE, INACTIVE, PROSPECT or CLOSED",
            "example": "ACTIVE"
          },
          "invoiceDeliveryMethod": {
            "type": [
              "string",
              "null"
            ],
            "description": "Default delivery method for the client's invoices, one of EMAIL, DOWNLOAD, EMAIL_AND_DOWNLOAD or POST_ONLY",
            "example": "EMAIL"
          },
          "mergedInto": {
            "type": [
              "integer",
              "null"
            ],
            "description": "For a client merged into another as a duplicate, the ID of the client it was merged into.\nA merged client is always inactive; null when the client has not been merged.\n",
            "example": null
          },
          "inactivateMergedRecord": {
            "type": "boolean",
            "description": "For a merged client, whether the merge also made the client it was merged into inactive.\nNot an indicator that the client was merged; use `mergedInto` for that.\n",
            "example": false
          },
          "department": {
            "type": [
              "object",
              "null"
            ],
            "description": "Client department; null when the client has no department",
            "required": [
              "id",
              "pmsRef",
              "name"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 3
              },
              "pmsRef": {
                "type": "string",
                "example": "TAX"
              },
              "name": {
                "type": "string",
                "example": "Tax"
              }
            }
          },
          "office": {
            "type": "object",
            "description": "Client office",
            "required": [
              "id",
              "pmsRef",
              "name",
              "city",
              "stateProvince",
              "country"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 1
              },
              "pmsRef": {
                "type": "string",
                "example": "OFF-1"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "Charlotte"
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "Charlotte"
              },
              "stateProvince": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "NC"
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "US"
              }
            }
          },
          "industry": {
            "type": [
              "object",
              "null"
            ],
            "description": "Client industry; null when the client has no industry",
            "required": [
              "id",
              "name",
              "ref"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 2
              },
              "name": {
                "type": "string",
                "example": "Manufacturing"
              },
              "ref": {
                "type": "string",
                "example": "MFG"
              }
            }
          },
          "clientType": {
            "type": [
              "object",
              "null"
            ],
            "description": "Client type; null when the client has no type",
            "required": [
              "id",
              "name",
              "pmsRef"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 7
              },
              "name": {
                "type": "string",
                "example": "Individual"
              },
              "pmsRef": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "IND"
              }
            }
          },
          "clientBusinessEntity": {
            "description": "Client business entity; null when the client has none",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientBusinessEntityRef"
              },
              {
                "type": "null"
              }
            ]
          },
          "entityType": {
            "description": "Alias of `clientBusinessEntity`",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientBusinessEntityRef"
              },
              {
                "type": "null"
              }
            ]
          },
          "partnerStaff": {
            "description": "Assigned partner staff member; null when the client has no partner",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "managerStaff": {
            "description": "Assigned manager staff member; null when the client has no manager",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "billManager": {
            "description": "Staff billing manager; null when the client has none",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "relationshipOwner": {
            "description": "Alias of `partnerStaff`",
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientStaffMember"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "ClientContactInfo": {
        "type": "object",
        "description": "Client contact information details. The address, city, state, and zip_code\nfields carry the same postal-address shape defined by the reusable Address schema.\n",
        "required": [
          "id",
          "firstName",
          "lastName",
          "email",
          "phone"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique contact info identifier",
            "example": 9957
          },
          "firstName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Contact first name",
            "example": "John"
          },
          "lastName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Contact last name",
            "example": "Doe"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "description": "Contact email address",
            "example": "loree.kling@yahoo.com"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "description": "Contact phone number",
            "example": "1-555-123-4567"
          },
          "address": {
            "type": [
              "string",
              "null"
            ],
            "description": "Street address (see the Address schema)",
            "example": "123 Main Street"
          },
          "city": {
            "type": [
              "string",
              "null"
            ],
            "description": "City (see the Address schema)",
            "example": "Anytown"
          },
          "state": {
            "type": [
              "string",
              "null"
            ],
            "description": "State or province code (see the Address schema)",
            "example": "CA"
          },
          "zip_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Postal / ZIP code (see the Address schema)",
            "example": "12345"
          }
        }
      },
      "ClientDetail": {
        "description": "Client record as returned by `GET /gql/v1/client/{id}`: every `Client` property plus the\nclient's own contact info.\n",
        "allOf": [
          {
            "$ref": "#/components/schemas/Client"
          },
          {
            "type": "object",
            "required": [
              "clientContactInfo"
            ],
            "properties": {
              "clientContactInfo": {
                "description": "The client's own contact info record; null when the client has none",
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/ClientContactInfo"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        ]
      },
      "JobRecord": {
        "type": "object",
        "description": "Job row from the `job` table, as returned by the job list and by-id operations.\n",
        "required": [
          "id",
          "pmsRef",
          "jobRef",
          "name",
          "status",
          "isActive",
          "clientId",
          "deptId",
          "officeId",
          "jobTemplateId",
          "managerStaffId",
          "partnerStaffId",
          "startDate",
          "endDate",
          "dueDate",
          "targetStartDate",
          "targetedStartDate",
          "targetEndDate",
          "targetedEndDate",
          "feeStructureId",
          "feeStructureV4",
          "sysRefs",
          "createdAt",
          "updatedAt",
          "version"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique job identifier",
            "example": 5012
          },
          "pmsRef": {
            "type": "string",
            "description": "External PMS reference",
            "example": "JOB-5012"
          },
          "jobRef": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal job reference. Null when not set.",
            "example": "J-0005012"
          },
          "name": {
            "type": "string",
            "description": "Job name",
            "example": "Q1 Financial Review 2025"
          },
          "status": {
            "type": [
              "string",
              "null"
            ],
            "description": "Job status",
            "example": "ACTIVE"
          },
          "isActive": {
            "type": "boolean",
            "description": "Whether the job is active",
            "example": true
          },
          "clientId": {
            "type": "integer",
            "description": "Associated client identifier",
            "example": 1001
          },
          "deptId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated department identifier. Null when the job has no department.",
            "example": 7
          },
          "officeId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated office identifier. Null when the job has no office.",
            "example": 2
          },
          "jobTemplateId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated job template identifier. Null when the job was not created from a template.",
            "example": 300
          },
          "managerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff identifier for the job manager. Null when no manager is assigned.",
            "example": 102
          },
          "partnerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff identifier for the job partner. Null when no partner is assigned.",
            "example": 101
          },
          "startDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Job start date. Null when not set.",
            "example": "2025-01-01T00:00:00Z"
          },
          "endDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Job end date. Null when not set.",
            "example": "2025-03-31T23:59:59Z"
          },
          "dueDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Job due date (alias for endDate). Null when not set.",
            "example": "2025-03-31T23:59:59Z"
          },
          "targetStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Target start date. Null when not set.",
            "example": "2025-01-01T00:00:00Z"
          },
          "targetedStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Same value as targetStartDate. Null when not set.",
            "example": "2025-01-01T00:00:00Z"
          },
          "targetEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Target end date. Null when not set.",
            "example": "2025-03-31T23:59:59Z"
          },
          "targetedEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Same value as targetEndDate. Null when not set.",
            "example": "2025-03-31T23:59:59Z"
          },
          "feeStructureId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated fee structure identifier. Null when the job has no fee structure.",
            "example": 42
          },
          "feeStructureV4": {
            "type": [
              "object",
              "null"
            ],
            "description": "Fee structure details. Null when the job has no fee structure.",
            "properties": {
              "id": {
                "type": "integer",
                "example": 42
              },
              "type": {
                "type": "string",
                "example": "FIXED"
              },
              "amount": {
                "type": [
                  "number",
                  "null"
                ],
                "example": 5000
              },
              "active": {
                "type": "boolean",
                "example": true
              }
            }
          },
          "sysRefs": {
            "type": [
              "object",
              "null"
            ],
            "description": "System reference metadata"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Record creation timestamp",
            "example": "2025-01-02T03:04:05Z"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Last update timestamp",
            "example": "2025-01-03T10:11:12Z"
          },
          "customFieldValues": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom field values for the job, keyed by custom field code",
            "example": {
              "industry_niche": "Manufacturing",
              "naics_code": "333120"
            }
          },
          "version": {
            "type": "integer",
            "description": "Record version for optimistic concurrency",
            "example": 3
          },
          "previousJobId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Previous job in the series (job id).",
            "example": null
          },
          "jobContactInfoId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Contact info of the job (contact info id).",
            "example": null
          },
          "billable": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the job is billable to the client.",
            "example": true
          },
          "draftInvoiceId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Draft invoice of the job (the draft invoice's AR transaction id).",
            "example": null
          },
          "defaultBillingDay": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Default day of the month the job is billed.",
            "example": 1
          },
          "isManagedByAiwyn": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether Aiwyn manages the record's lifecycle.",
            "example": true
          },
          "isCreatedByAiwyn": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the record was created in Aiwyn.",
            "example": true
          },
          "serviceDescription": {
            "type": [
              "string",
              "null"
            ],
            "description": "Description of the service provided.",
            "example": "Tax: General Tax Consulting"
          },
          "extendedServiceDescription": {
            "type": [
              "string",
              "null"
            ],
            "description": "Extended description of the service provided.",
            "example": null
          },
          "billingDay": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Day of the month the job is billed, when it differs from the default.",
            "example": null
          },
          "createdByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who created the job (staff id).",
            "example": 102
          },
          "lastUpdatedByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who last updated the job (staff id).",
            "example": 102
          },
          "eFileStates": {
            "type": [
              "string",
              "null"
            ],
            "description": "States where returns for the job are filed electronically.",
            "example": "CA,NY"
          },
          "paperFileStates": {
            "type": [
              "string",
              "null"
            ],
            "description": "States where returns for the job are filed on paper.",
            "example": null
          },
          "jobType": {
            "type": [
              "string",
              "null"
            ],
            "description": "Kind of job, `JOB` or `UNAPPLIED_PROGRESS`.",
            "example": "JOB"
          },
          "overriddenPreviousJobId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Overridden previous job (job id).",
            "example": null
          },
          "estimationEnabled": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether hour estimation is enabled for the job.",
            "example": false
          },
          "estimationHours": {
            "type": [
              "number",
              "null"
            ],
            "description": "Estimated hours for the job.",
            "example": null
          },
          "jobStatusId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Firm-defined job status (job status id).",
            "example": 3
          },
          "internalNote": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal note on the job, visible only to firm staff.",
            "example": null
          },
          "nameTemplate": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pattern used to generate the job name.",
            "example": null
          },
          "primaryDeliverableTemplateId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Primary deliverable template of the job (deliverable template id).",
            "example": null
          },
          "primaryDeliverableId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Primary deliverable of the job (deliverable id).",
            "example": null
          },
          "originalTargetEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Planned end date before any extensions.",
            "example": null
          },
          "extensionCount": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Number of extensions applied to the job.",
            "example": 0
          },
          "totalTaskCount": {
            "type": "integer",
            "description": "Number of tasks on the job.",
            "example": 12
          },
          "completedTaskCount": {
            "type": "integer",
            "description": "Number of completed tasks on the job.",
            "example": 4
          },
          "criToDoCount": {
            "type": "integer",
            "description": "Number of client request items on the job that are to do.",
            "example": 2
          },
          "criOpenCount": {
            "type": "integer",
            "description": "Number of client request items on the job that are open.",
            "example": 1
          },
          "criInReviewCount": {
            "type": "integer",
            "description": "Number of client request items on the job that are in review.",
            "example": 0
          },
          "criRejectedCount": {
            "type": "integer",
            "description": "Number of client request items on the job that were rejected.",
            "example": 0
          },
          "criDoneCount": {
            "type": "integer",
            "description": "Number of client request items on the job that are done.",
            "example": 3
          },
          "rolloveredTo": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Job this one was rolled over to (job id).",
            "example": null
          },
          "rolloveredFrom": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Job this one was rolled over from (job id).",
            "example": null
          },
          "budgetedHours": {
            "type": "number",
            "description": "Hours budgeted for the job.",
            "example": 40
          },
          "projectYear": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Year the job relates to.",
            "example": 2024
          },
          "totalClientRequestCount": {
            "type": "integer",
            "description": "Number of client requests on the job.",
            "example": 2
          },
          "completedClientRequestCount": {
            "type": "integer",
            "description": "Number of completed client requests on the job.",
            "example": 1
          },
          "actualHours": {
            "type": "number",
            "description": "Hours recorded against the job.",
            "example": 12.5
          },
          "ownerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who owns the job (staff id).",
            "example": 102
          }
        }
      },
      "ContactInfoDetail": {
        "type": "object",
        "description": "Name, email, phone and address of a contact",
        "required": [
          "id",
          "pms_ref",
          "salutation",
          "firstName",
          "lastName",
          "email",
          "phone",
          "address",
          "address2",
          "city",
          "state",
          "country",
          "zip_code",
          "active"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 7001
          },
          "pms_ref": {
            "type": "string",
            "example": "C-4451"
          },
          "salutation": {
            "type": [
              "string",
              "null"
            ],
            "example": "Ms."
          },
          "firstName": {
            "type": [
              "string",
              "null"
            ],
            "example": "Jane"
          },
          "lastName": {
            "type": [
              "string",
              "null"
            ],
            "example": "Smith"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "example": "jane.smith@acme.com"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "example": "555-0123"
          },
          "address": {
            "type": [
              "string",
              "null"
            ],
            "example": "123 Main St"
          },
          "address2": {
            "type": [
              "string",
              "null"
            ],
            "example": "Suite 400"
          },
          "city": {
            "type": [
              "string",
              "null"
            ],
            "example": "Charlotte"
          },
          "state": {
            "type": [
              "string",
              "null"
            ],
            "example": "NC"
          },
          "country": {
            "type": [
              "string",
              "null"
            ],
            "example": "US"
          },
          "zip_code": {
            "type": [
              "string",
              "null"
            ],
            "example": "28202"
          },
          "active": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "Contact": {
        "type": "object",
        "description": "Contact record as returned by `POST /gql/v1/contacts`, `POST /gql/v1/contacts/search` and\n`GET /gql/v1/contact/{id}`. Field names are snake_case except the `firstName` / `lastName`\nof `contact_info`. Every listed property is always present; optional columns are `null`\nwhen unset.\n",
        "required": [
          "id",
          "pms_ref",
          "active",
          "contact_info_id",
          "office_id",
          "staff_id",
          "type",
          "fwd_email_confirmation",
          "inactivated_at",
          "created_at",
          "updated_at",
          "is_managed_by_aiwyn",
          "is_created_by_aiwyn",
          "username",
          "custom_field_values",
          "contact_info",
          "contact_clients"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 1001
          },
          "pms_ref": {
            "type": "string",
            "example": "C-4451"
          },
          "active": {
            "type": "boolean",
            "example": true
          },
          "contact_info_id": {
            "type": "integer",
            "example": 7001
          },
          "office_id": {
            "type": [
              "integer",
              "null"
            ],
            "example": 3
          },
          "staff_id": {
            "type": [
              "integer",
              "null"
            ],
            "example": null
          },
          "type": {
            "type": [
              "string",
              "null"
            ],
            "example": "Billing"
          },
          "fwd_email_confirmation": {
            "type": "boolean",
            "example": false
          },
          "inactivated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the contact was inactivated (no time zone offset); null while active",
            "example": null
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the record was created",
            "example": "2024-03-01T15:20:11.104223+00:00"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the record was last updated",
            "example": "2024-09-14T08:02:47.551092+00:00"
          },
          "is_managed_by_aiwyn": {
            "type": "boolean",
            "description": "Whether Aiwyn manages the record's lifecycle",
            "example": false
          },
          "is_created_by_aiwyn": {
            "type": "boolean",
            "description": "Whether the record was created in Aiwyn",
            "example": false
          },
          "username": {
            "type": [
              "string",
              "null"
            ],
            "description": "Client portal username of the contact; null when the contact has no portal account",
            "example": "jane.smith@acme.com"
          },
          "custom_field_values": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Firm-defined custom fields for the contact, keyed by custom field code",
            "example": null
          },
          "contact_info": {
            "$ref": "#/components/schemas/ContactInfoDetail"
          },
          "contact_clients": {
            "type": "array",
            "description": "Links between this contact and clients (active and inactive)",
            "items": {
              "type": "object",
              "required": [
                "client_id",
                "contact_id",
                "pms_ref",
                "active"
              ],
              "properties": {
                "client_id": {
                  "type": "integer",
                  "example": 2180
                },
                "contact_id": {
                  "type": "integer",
                  "example": 1001
                },
                "pms_ref": {
                  "type": "string",
                  "example": "LL-9981"
                },
                "active": {
                  "type": "boolean",
                  "example": true
                }
              }
            }
          }
        }
      },
      "ContactListResponse": {
        "type": "object",
        "description": "Response of `POST /gql/v1/contacts` and `POST /gql/v1/contacts/search`",
        "required": [
          "contacts",
          "total"
        ],
        "properties": {
          "contacts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Contact"
            }
          },
          "total": {
            "type": "object",
            "required": [
              "aggregate"
            ],
            "properties": {
              "aggregate": {
                "type": "object",
                "required": [
                  "count"
                ],
                "properties": {
                  "count": {
                    "type": "integer",
                    "description": "Number of contacts matching the request (the filtered count for search)",
                    "example": 959
                  }
                }
              }
            }
          }
        }
      },
      "EngagementJobLink": {
        "type": "object",
        "description": "Link between an engagement and one of its projects (jobs)",
        "required": [
          "id",
          "jobId",
          "jobServiceTermId",
          "engagementCustomJobServiceTermId",
          "isActive",
          "job"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "jobId": {
            "type": "integer",
            "example": 829
          },
          "jobServiceTermId": {
            "type": [
              "integer",
              "null"
            ],
            "example": null
          },
          "engagementCustomJobServiceTermId": {
            "type": [
              "integer",
              "null"
            ],
            "example": null
          },
          "isActive": {
            "type": "boolean",
            "example": true
          },
          "job": {
            "type": [
              "object",
              "null"
            ],
            "required": [
              "id",
              "name",
              "status",
              "clientId",
              "pmsRef",
              "jobRef",
              "sysRefs"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 829
              },
              "name": {
                "type": "string",
                "example": "Expatriate Tax Services"
              },
              "status": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "OPEN"
              },
              "clientId": {
                "type": "integer",
                "example": 92
              },
              "pmsRef": {
                "type": "string",
                "example": "AIWYN_829"
              },
              "jobRef": {
                "type": [
                  "string",
                  "null"
                ],
                "example": null
              },
              "sysRefs": {
                "type": [
                  "object",
                  "null"
                ],
                "example": {}
              }
            }
          }
        }
      },
      "EngagementStaffSummary": {
        "type": "object",
        "description": "Staff member referenced by an engagement",
        "required": [
          "id",
          "firstName",
          "lastName",
          "fullName",
          "pmsRef",
          "email",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 18
          },
          "firstName": {
            "type": "string",
            "example": "Robert"
          },
          "lastName": {
            "type": "string",
            "example": "Johnson"
          },
          "fullName": {
            "type": "string",
            "example": "Robert Johnson"
          },
          "pmsRef": {
            "type": "string",
            "example": "AIWYN_18"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "example": "r.johnson@company.com"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-06-08T16:26:36.875604+00:00"
          }
        }
      },
      "Engagement": {
        "type": "object",
        "description": "Engagement row from `vw_engagement`, as returned by the engagement list, search and\nby-id operations. Only active engagements are returned.\n",
        "required": [
          "id",
          "name",
          "status",
          "isActive",
          "endDt",
          "startDt",
          "fiscalYear",
          "engagementNameTemplate",
          "createdAt",
          "sentAt",
          "executedAt",
          "isStartOnAcceptance",
          "updatedAt",
          "paymentInfoType",
          "canceledAt",
          "mode",
          "addressContactInfoId",
          "originatingEngagementId",
          "clientId",
          "jobs",
          "partnerStaff",
          "managerStaff",
          "createdByStaff",
          "lastUpdatedByStaff",
          "executedByStaff",
          "renewedAt"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique engagement identifier",
            "example": 85
          },
          "name": {
            "type": "string",
            "description": "Engagement name generated from the name template",
            "example": "2026 Annual Review and Tax 52150"
          },
          "status": {
            "type": [
              "string",
              "null"
            ],
            "description": "Engagement workflow status. One of `DRAFT`, `IN_APPROVAL`, `READY_TO_SEND`, `SENT`,\n`UNDER_REVISION`, `EXECUTED`, `CANCELED` or `ARCHIVED`. While an engagement is in review,\nthe value is the name of its current workflow step (for example `Pending Review`)\ninstead of `IN_REVIEW`.\n",
            "example": "EXECUTED"
          },
          "isActive": {
            "type": "boolean",
            "example": true
          },
          "endDt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Engagement end date. Null when not set.",
            "example": "2026-12-31"
          },
          "startDt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Engagement start date. Null when not set (for example when the engagement starts on acceptance).",
            "example": "2026-01-01"
          },
          "fiscalYear": {
            "type": "integer",
            "example": 2026
          },
          "engagementNameTemplate": {
            "type": "string",
            "description": "Template the engagement name was generated from",
            "example": "{{fiscal_year.year}} {{letter_template.name}} {{client.number}}"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-06-08T16:40:09.096612+00:00"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the engagement was sent. Null until it is sent.",
            "example": "2026-06-08T16:45:00.414069+00:00"
          },
          "executedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the engagement was executed. Null until it is executed.",
            "example": "2026-06-08T16:46:48.196882+00:00"
          },
          "isStartOnAcceptance": {
            "type": "boolean",
            "example": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-06-08T16:46:48.199113+00:00"
          },
          "paymentInfoType": {
            "type": "string",
            "enum": [
              "NONE",
              "REQUIRED",
              "OPTIONAL"
            ],
            "example": "OPTIONAL"
          },
          "canceledAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the engagement was canceled. Null unless it was canceled.",
            "example": null
          },
          "mode": {
            "type": "string",
            "enum": [
              "AUTOMATIC",
              "MANUAL"
            ],
            "example": "AUTOMATIC"
          },
          "addressContactInfoId": {
            "type": [
              "integer",
              "null"
            ],
            "example": null
          },
          "originatingEngagementId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Engagement this one was renewed or copied from. Null for an original engagement.",
            "example": null
          },
          "clientId": {
            "type": "integer",
            "example": 92
          },
          "primaryContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Primary contact of the engagement (contact id).",
            "example": 311
          },
          "secondaryContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Secondary contact of the engagement (contact id). Null when none is set.",
            "example": null
          },
          "billingContactId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Billing contact of the engagement (contact id). Null when none is set.",
            "example": 311
          },
          "internalNote": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal note on the engagement, visible only to firm staff.",
            "example": null
          },
          "sourceEngagementId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Engagement this one was created from (engagement id). Null when it was not created from another engagement.",
            "example": null
          },
          "senderStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who sends the engagement (staff id).",
            "example": 102
          },
          "ccStaffIds": {
            "type": [
              "array",
              "null"
            ],
            "description": "Engagement collaborators, the staff ids copied on the engagement.",
            "items": {
              "type": "integer"
            },
            "example": [
              104,
              105
            ]
          },
          "shouldShowToClient": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the engagement is visible to the client.",
            "example": true
          },
          "enableAutomaticPayments": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether automatic payments are enabled for the engagement.",
            "example": false
          },
          "isArchived": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the engagement is archived.",
            "example": false
          },
          "reassigned": {
            "type": "boolean",
            "description": "Whether the engagement has been reassigned.",
            "example": false
          },
          "engagement": {
            "type": [
              "object",
              "null"
            ],
            "description": "Engagement columns that the engagement view does not carry.",
            "properties": {
              "pmsRef": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Identifier of the engagement in the external practice management system.",
                "example": "ENG-2026-85"
              },
              "customFieldValues": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": true,
                "description": "Firm-defined custom fields of the engagement, keyed by custom field code.",
                "example": {
                  "engagement_type": "Recurring"
                }
              }
            }
          },
          "jobs": {
            "type": "array",
            "description": "Active projects (jobs) linked to the engagement",
            "items": {
              "$ref": "#/components/schemas/EngagementJobLink"
            }
          },
          "partnerStaff": {
            "$ref": "#/components/schemas/EngagementStaffSummary"
          },
          "managerStaff": {
            "$ref": "#/components/schemas/EngagementStaffSummary"
          },
          "createdByStaff": {
            "$ref": "#/components/schemas/EngagementStaffSummary"
          },
          "lastUpdatedByStaff": {
            "$ref": "#/components/schemas/EngagementStaffSummary"
          },
          "executedByStaff": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/EngagementStaffSummary"
              },
              {
                "type": "null"
              }
            ],
            "description": "Staff member who executed the engagement. Null until it is executed by a staff member."
          },
          "renewedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the engagement was renewed. Null unless it was renewed.",
            "example": null
          }
        }
      },
      "AggregateCount": {
        "type": "object",
        "description": "Standard count aggregation",
        "properties": {
          "aggregate": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer",
                "description": "Total number of records matching criteria",
                "example": 13697
              }
            }
          }
        }
      },
      "EngagementListResponse": {
        "type": "object",
        "description": "Response of the engagement list and search operations",
        "required": [
          "engagements",
          "total"
        ],
        "properties": {
          "engagements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Engagement"
            }
          },
          "total": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "Department": {
        "type": "object",
        "description": "Department information",
        "properties": {
          "id": {
            "type": "integer",
            "example": 7
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice management system reference of the department",
            "example": "TECH"
          },
          "name": {
            "type": "string",
            "example": "Technology"
          }
        }
      },
      "StaffOffice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "pmsRef": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "stateProvince": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "StaffClassification": {
        "type": "object",
        "description": "Referenced staff classification",
        "properties": {
          "id": {
            "type": "integer",
            "example": 2
          },
          "pmsRef": {
            "type": [
              "string",
              "null"
            ],
            "example": "FT"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "example": "Full Time"
          }
        }
      },
      "StaffType": {
        "type": "object",
        "description": "Staff type classification details",
        "properties": {
          "id": {
            "type": "integer",
            "example": 11
          },
          "pmsRef": {
            "type": [
              "string",
              "null"
            ]
          },
          "display": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string",
            "example": "Senior Associate"
          },
          "rateCardStaffTypeBillingRates": {
            "type": "array",
            "description": "Billing rates configured for this role",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "StaffPermissionSet": {
        "type": "object",
        "description": "Permission set summary",
        "properties": {
          "id": {
            "type": "integer",
            "example": 3
          },
          "name": {
            "type": "string",
            "example": "Standard Manager"
          }
        }
      },
      "StaffMember": {
        "type": "object",
        "description": "Staff member basic information",
        "properties": {
          "id": {
            "type": "integer",
            "example": 53
          },
          "pmsRef": {
            "type": [
              "string",
              "null"
            ],
            "example": "A53"
          },
          "staffRef": {
            "type": [
              "string",
              "null"
            ],
            "example": "AH"
          },
          "firstName": {
            "type": "string",
            "example": "Allen"
          },
          "lastName": {
            "type": "string",
            "example": "Hermiston"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "description": "Null for staff without an email address on file.",
            "example": "allen.hermiston@company.com"
          }
        }
      },
      "StaffDirectoryRecord": {
        "type": "object",
        "description": "Staff directory record with organizational, employment, permission, and reporting relationships",
        "required": [
          "id",
          "pmsRef",
          "staffRef",
          "firstName",
          "lastName",
          "email",
          "active",
          "deptId",
          "jobTitle",
          "jobTitleId",
          "type",
          "officeId",
          "department",
          "office",
          "serviceLine",
          "subServiceLine",
          "wageType",
          "employeeType",
          "role",
          "rateCardBillingRates",
          "staffManagerId",
          "permissionSet",
          "staffSupervisor",
          "updatedAt",
          "createdAt",
          "fullName",
          "prefix",
          "startDt",
          "endDt",
          "staffPartnerId",
          "staffPaId",
          "orgId",
          "isCreatedByAiwyn",
          "isManagedByAiwyn",
          "lastUpdatedByStaffId",
          "customFieldValues"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 21
          },
          "pmsRef": {
            "type": [
              "string",
              "null"
            ],
            "example": "AIWYN_21"
          },
          "staffRef": {
            "type": [
              "string",
              "null"
            ],
            "example": "AIWYN"
          },
          "firstName": {
            "type": "string",
            "example": "Aiwyn"
          },
          "lastName": {
            "type": "string",
            "example": "User"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "description": "Null for staff without an email address on file.",
            "example": "test@aiwyn.ai"
          },
          "active": {
            "type": "boolean",
            "example": true
          },
          "deptId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "jobTitle": {
            "type": [
              "string",
              "null"
            ]
          },
          "jobTitleId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "officeId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "department": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Department"
              },
              {
                "type": "null"
              }
            ]
          },
          "office": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffOffice"
              },
              {
                "type": "null"
              }
            ]
          },
          "serviceLine": {
            "description": "Primary service line assigned to the staff member",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffClassification"
              },
              {
                "type": "null"
              }
            ]
          },
          "subServiceLine": {
            "description": "Sub-service line assigned to the staff member",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffClassification"
              },
              {
                "type": "null"
              }
            ]
          },
          "wageType": {
            "description": "Wage classification, such as salary or hourly",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffClassification"
              },
              {
                "type": "null"
              }
            ]
          },
          "employeeType": {
            "description": "Employment classification, such as full time or contractor",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffClassification"
              },
              {
                "type": "null"
              }
            ]
          },
          "role": {
            "description": "Staff role; this response field replaces the former `staffType` field",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffType"
              },
              {
                "type": "null"
              }
            ]
          },
          "permissionSet": {
            "description": "Permission set assigned directly to the staff member",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffPermissionSet"
              },
              {
                "type": "null"
              }
            ]
          },
          "staffSupervisor": {
            "description": "Staff member assigned as this person's supervisor",
            "anyOf": [
              {
                "$ref": "#/components/schemas/StaffMember"
              },
              {
                "type": "null"
              }
            ]
          },
          "staffManagerId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "rateCardBillingRates": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Timestamp of the most recent staff record update",
            "example": "2026-09-21T18:30:00Z"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "When the record was created.",
            "example": "2024-05-12T22:42:02.719873+00:00"
          },
          "fullName": {
            "type": [
              "string",
              "null"
            ],
            "description": "Full name.",
            "example": "Aiwyn User"
          },
          "prefix": {
            "type": [
              "string",
              "null"
            ],
            "description": "Name prefix.",
            "example": "Ms."
          },
          "startDt": {
            "type": [
              "string",
              "null"
            ],
            "description": "Date the staff member started at the firm, as a local date-time with no time-zone offset.",
            "example": "2024-01-08T00:00:00"
          },
          "endDt": {
            "type": [
              "string",
              "null"
            ],
            "description": "Date the staff member left the firm, as a local date-time with no time-zone offset.",
            "example": null
          },
          "staffPartnerId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff id of the partner this staff member reports to."
          },
          "staffPaId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff id of this staff member's practice administrator."
          },
          "orgId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Organization id."
          },
          "isCreatedByAiwyn": {
            "type": "boolean",
            "description": "Whether the record was created in Aiwyn."
          },
          "isManagedByAiwyn": {
            "type": "boolean",
            "description": "Whether Aiwyn manages the record's lifecycle."
          },
          "lastUpdatedByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff id of whoever last updated the record."
          },
          "customFieldValues": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Firm-defined custom fields."
          }
        }
      },
      "ProjectStaffSummary": {
        "type": "object",
        "description": "Staff member referenced by a project",
        "required": [
          "id",
          "firstName",
          "lastName",
          "email"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 102
          },
          "firstName": {
            "type": "string",
            "example": "Allen"
          },
          "lastName": {
            "type": "string",
            "example": "Hermiston"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "example": "allen.hermiston@company.com"
          }
        }
      },
      "Project": {
        "type": "object",
        "description": "Project record from `vw_job`, as returned by the project list, search and by-id\noperations. `endDate` and `dueDate` are the same value, and so are `targetStartDate` /\n`targetedStartDate` and `targetEndDate` / `targetedEndDate`.\n",
        "required": [
          "id",
          "name",
          "startDate",
          "endDate",
          "dueDate",
          "targetStartDate",
          "targetedStartDate",
          "targetEndDate",
          "targetedEndDate",
          "feeStructureId",
          "pmsRef",
          "isCreatedByAiwyn",
          "managerStaffId",
          "partnerStaffId",
          "serviceId",
          "serviceDescription",
          "extendedServiceDescription",
          "status",
          "updatedAt",
          "sysRefs",
          "feeStructureV4",
          "client",
          "projectOwner",
          "partnerStaff",
          "jobServiceLines"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 5012
          },
          "name": {
            "type": "string",
            "example": "Q1 Financial Review 2024"
          },
          "startDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Project start date. Null when not set.",
            "example": "2024-01-01T00:00:00Z"
          },
          "endDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Project end date. Null when not set.",
            "example": "2024-03-15T00:00:00Z"
          },
          "dueDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Project due date (same value as `endDate`). Null when not set.",
            "example": "2024-03-15T00:00:00Z"
          },
          "targetStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "example": "2023-12-01T00:00:00Z"
          },
          "targetedStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Same value as `targetStartDate`",
            "example": "2023-12-01T00:00:00Z"
          },
          "targetEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "example": "2024-03-31T23:59:59Z"
          },
          "targetedEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Same value as `targetEndDate`",
            "example": "2024-03-31T23:59:59Z"
          },
          "feeStructureId": {
            "type": [
              "integer",
              "null"
            ],
            "example": 42
          },
          "pmsRef": {
            "type": "string",
            "example": "JOB-2024-115"
          },
          "isCreatedByAiwyn": {
            "type": "boolean",
            "example": true
          },
          "managerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Project owner (manager) staff id. Null when no owner is assigned.",
            "example": 102
          },
          "partnerStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Partner staff id. Null when no partner is assigned.",
            "example": 101
          },
          "serviceId": {
            "type": [
              "integer",
              "null"
            ],
            "example": null
          },
          "serviceDescription": {
            "type": [
              "string",
              "null"
            ],
            "example": "Tax: General Tax Consulting"
          },
          "extendedServiceDescription": {
            "type": [
              "string",
              "null"
            ],
            "example": null
          },
          "status": {
            "type": "string",
            "description": "Project state; `OPEN` when the project has no status set",
            "example": "OPEN"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Project record creation timestamp",
            "example": "2024-01-02T09:15:00.000000+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "example": "2024-05-20T12:34:56.123456+00:00"
          },
          "customFieldValues": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom field values for the project, keyed by custom field code",
            "example": {
              "industry_niche": "Manufacturing",
              "naics_code": "333120"
            }
          },
          "sysRefs": {
            "type": [
              "object",
              "null"
            ],
            "description": "References of the project in connected systems, keyed by system"
          },
          "deptId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Department of the project (department id).",
            "example": 7
          },
          "officeId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Office of the project (office id).",
            "example": 2
          },
          "previousProjectId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Previous project in the series (project id).",
            "example": null
          },
          "projectContactInfoId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Contact info of the project (contact info id).",
            "example": null
          },
          "billable": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the project is billable to the client.",
            "example": true
          },
          "draftInvoiceId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Draft invoice of the project (the draft invoice's AR transaction id).",
            "example": null
          },
          "defaultBillingDay": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Default day of the month the project is billed.",
            "example": 1
          },
          "projectRef": {
            "type": [
              "string",
              "null"
            ],
            "description": "Reference identifier for the project.",
            "example": "J-0005012"
          },
          "isManagedByAiwyn": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether Aiwyn manages the record's lifecycle.",
            "example": true
          },
          "billingDay": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Day of the month the project is billed, when it differs from the default.",
            "example": null
          },
          "projectTemplateId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Project template the project was created from (job template id).",
            "example": 300
          },
          "isActive": {
            "type": "boolean",
            "description": "Whether the record is active.",
            "example": true
          },
          "createdByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who created the project (staff id).",
            "example": 102
          },
          "lastUpdatedByStaffId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Staff member who last updated the project (staff id).",
            "example": 102
          },
          "eFileStates": {
            "type": [
              "string",
              "null"
            ],
            "description": "States where returns for the project are filed electronically.",
            "example": "CA,NY"
          },
          "paperFileStates": {
            "type": [
              "string",
              "null"
            ],
            "description": "States where returns for the project are filed on paper.",
            "example": null
          },
          "projectType": {
            "type": [
              "string",
              "null"
            ],
            "description": "Kind of project, `JOB` or `UNAPPLIED_PROGRESS`.",
            "example": "JOB"
          },
          "overriddenPreviousProjectId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Overridden previous project (project id).",
            "example": null
          },
          "estimationEnabled": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether hour estimation is enabled for the project.",
            "example": false
          },
          "estimationHours": {
            "type": [
              "number",
              "null"
            ],
            "description": "Estimated hours for the project.",
            "example": null
          },
          "projectStatusId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Firm-defined project status (project status id).",
            "example": 3
          },
          "internalNote": {
            "type": [
              "string",
              "null"
            ],
            "description": "Internal note on the project, visible only to firm staff.",
            "example": null
          },
          "nameTemplate": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pattern used to generate the project name.",
            "example": null
          },
          "primaryDeliverableTemplateId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Primary deliverable template of the project (deliverable template id).",
            "example": null
          },
          "primaryDeliverableId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Primary deliverable of the project (deliverable id).",
            "example": null
          },
          "originalTargetEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Planned end date before any extensions.",
            "example": null
          },
          "extensionCount": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Number of extensions applied to the project.",
            "example": 0
          },
          "totalTaskCount": {
            "type": "integer",
            "description": "Number of tasks on the project.",
            "example": 12
          },
          "completedTaskCount": {
            "type": "integer",
            "description": "Number of completed tasks on the project.",
            "example": 4
          },
          "criToDoCount": {
            "type": "integer",
            "description": "Number of client request items on the project that are to do.",
            "example": 2
          },
          "criOpenCount": {
            "type": "integer",
            "description": "Number of client request items on the project that are open.",
            "example": 1
          },
          "criInReviewCount": {
            "type": "integer",
            "description": "Number of client request items on the project that are in review.",
            "example": 0
          },
          "criRejectedCount": {
            "type": "integer",
            "description": "Number of client request items on the project that were rejected.",
            "example": 0
          },
          "criDoneCount": {
            "type": "integer",
            "description": "Number of client request items on the project that are done.",
            "example": 3
          },
          "rolloveredTo": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Project this one was rolled over to (project id).",
            "example": null
          },
          "rolloveredFrom": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Project this one was rolled over from (project id).",
            "example": null
          },
          "budgetedHours": {
            "type": "number",
            "description": "Hours budgeted for the project.",
            "example": 40
          },
          "projectYear": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Year the project relates to.",
            "example": 2024
          },
          "totalClientRequestCount": {
            "type": "integer",
            "description": "Number of client requests on the project.",
            "example": 2
          },
          "completedClientRequestCount": {
            "type": "integer",
            "description": "Number of completed client requests on the project.",
            "example": 1
          },
          "actualHours": {
            "type": "number",
            "description": "Hours recorded against the project.",
            "example": 12.5
          },
          "job": {
            "type": [
              "object",
              "null"
            ],
            "description": "Project columns that the project view does not carry.",
            "properties": {
              "ownerStaffId": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Staff member who owns the project (staff id).",
                "example": 102
              }
            }
          },
          "feeStructureV4": {
            "type": [
              "object",
              "null"
            ],
            "description": "Fee structure of the project. Null when the project has none.",
            "required": [
              "id",
              "type",
              "amount",
              "active"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 1
              },
              "type": {
                "type": "string",
                "example": "FIXED"
              },
              "amount": {
                "type": [
                  "number",
                  "null"
                ],
                "example": 190
              },
              "active": {
                "type": "boolean",
                "example": true
              }
            }
          },
          "client": {
            "type": "object",
            "required": [
              "id",
              "name",
              "clientRef"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "example": 2180
              },
              "name": {
                "type": "string",
                "example": "TechFlow Enterprises"
              },
              "clientRef": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "TF-2024-789"
              }
            }
          },
          "projectOwner": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ProjectStaffSummary"
              },
              {
                "type": "null"
              }
            ],
            "description": "Project owner (the manager staff member). Null when no owner is assigned."
          },
          "partnerStaff": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ProjectStaffSummary"
              },
              {
                "type": "null"
              }
            ],
            "description": "Partner staff member. Null when no partner is assigned."
          },
          "jobServiceLines": {
            "type": "array",
            "description": "Service lines of the project",
            "items": {
              "type": "object",
              "required": [
                "id",
                "serviceLineId",
                "active",
                "serviceLine"
              ],
              "properties": {
                "id": {
                  "type": "integer",
                  "example": 1377
                },
                "serviceLineId": {
                  "type": "integer",
                  "example": 5
                },
                "active": {
                  "type": "boolean",
                  "example": true
                },
                "serviceLine": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "required": [
                    "id",
                    "name",
                    "pmsRef"
                  ],
                  "properties": {
                    "id": {
                      "type": "integer",
                      "example": 5
                    },
                    "name": {
                      "type": "string",
                      "example": "Tax"
                    },
                    "pmsRef": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "example": "AIWYN_5"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ProjectListResponse": {
        "type": "object",
        "description": "Response of the project list and search operations",
        "required": [
          "projects",
          "total"
        ],
        "properties": {
          "projects": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Project"
            }
          },
          "total": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "description": "Body of a webhook delivery. One delivery carries one event.",
        "required": [
          "event",
          "subscription"
        ],
        "properties": {
          "event": {
            "type": "object",
            "required": [
              "id",
              "type",
              "entityType",
              "entityId",
              "eventTimestamp",
              "data"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "format": "int64",
                "description": "Event id; the same on every delivery of this event, including retries. The same change can be reported as two events with different ids.",
                "example": 7001
              },
              "type": {
                "type": "string",
                "description": "The operation, as listed by the event catalog (for example `CREATED`, `UPDATED`, `POSTED`).",
                "example": "POSTED"
              },
              "entityType": {
                "type": "string",
                "description": "The entity the event is about, as listed by the event catalog.",
                "example": "Payment"
              },
              "entityId": {
                "type": "string",
                "description": "Id of that entity, as a string.",
                "example": "48213"
              },
              "eventTimestamp": {
                "type": "string",
                "format": "date-time",
                "description": "When the event happened.",
                "example": "2026-11-01T18:04:03.517Z"
              },
              "data": {
                "type": "object",
                "description": "The event's content.",
                "properties": {
                  "tenant": {
                    "type": "string",
                    "description": "Your firm's tenant identifier.",
                    "example": "acmecpa"
                  },
                  "primaryRecord": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "The entity as stored when the event fired; null for entity types whose record is not included.\nFor `File` events it is `{eventType, timestamp, file}`, where `eventType` is `file.` plus the\nlowercased operation (for example `file.created`) and `file` carries a signed `downloadUrl`\n(absent for `DELETED`) and `downloadUrlExpiresAt`.\n"
                  },
                  "relatedEntitiesData": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Related records by entity type (each a list), or null when the event has none.",
                    "additionalProperties": {
                      "type": "array",
                      "items": {}
                    }
                  },
                  "metadata": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Event-specific context. A payment made through a payment link created with `metadata` carries it\nhere as `paymentLinkMetadata`, but only on subscriptions owned by the API key or staff user that\ncreated the link; other subscriptions get the event without it. Omitted on `File` events.\n"
                  }
                }
              }
            }
          },
          "subscription": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "format": "int64",
                "description": "The subscription this delivery is for.",
                "example": 9
              },
              "description": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The subscription's description.",
                "example": "Post payments to our ERP"
              }
            }
          }
        }
      },
      "TransactionType": {
        "type": "string",
        "enum": [
          "Receipt",
          "Invoice",
          "Payment",
          "Credit",
          "Adjustment"
        ],
        "description": "Available AR transaction types"
      },
      "ClientBasic": {
        "type": "object",
        "description": "Basic client information for relationships",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "TechFlow Enterprises"
          }
        }
      },
      "CreditLabel": {
        "type": "object",
        "description": "Credit label details for categorization",
        "properties": {
          "id": {
            "type": "integer",
            "example": 3
          },
          "name": {
            "type": "string",
            "example": "Service Credit"
          },
          "description": {
            "type": "string",
            "example": "Credit for service issues or complaints"
          }
        }
      },
      "DebitLabel": {
        "type": "object",
        "description": "Debit label details for categorization",
        "properties": {
          "id": {
            "type": "integer",
            "example": 2
          },
          "name": {
            "type": "string",
            "example": "Late Fee"
          },
          "description": {
            "type": "string",
            "example": "Late payment penalty charge"
          },
          "is_active": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "InvoiceStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "POSTED",
          "PAID",
          "OVERDUE",
          "CANCELLED",
          "DRAFT"
        ],
        "description": "Available invoice statuses"
      },
      "ARTransactionBasic": {
        "type": "object",
        "description": "Basic AR transaction details for invoice relationships",
        "properties": {
          "id": {
            "type": "integer",
            "example": 125890
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice management system reference",
            "example": "240815"
          },
          "transactionDate": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
            "description": "Transaction date, as a local date-time with no time-zone offset",
            "example": "2024-03-22T05:00:00"
          },
          "amount": {
            "type": "number",
            "format": "decimal",
            "description": "Transaction amount as a decimal, USD",
            "example": 4250
          },
          "allocated": {
            "type": "number",
            "format": "decimal",
            "description": "Allocated amount as a decimal, USD",
            "example": 4250
          },
          "clientId": {
            "type": "integer",
            "description": "Client identifier",
            "example": 7720
          },
          "client": {
            "$ref": "#/components/schemas/ClientBasic"
          }
        }
      },
      "PaymentMethod": {
        "type": "string",
        "enum": [
          "CREDIT_CARD",
          "DEBIT_CARD",
          "ACH",
          "BANK_TRANSFER",
          "CHECK",
          "WIRE",
          "PAYPAL",
          "APPLE_PAY",
          "GOOGLE_PAY"
        ],
        "description": "Available payment methods"
      },
      "PaymentStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "CONFIRMED",
          "FAILED",
          "CANCELLED",
          "REFUNDED"
        ],
        "description": "Available payment statuses"
      },
      "ClientWithRef": {
        "type": "object",
        "description": "Client information with reference number",
        "properties": {
          "id": {
            "type": "integer",
            "example": 789
          },
          "name": {
            "type": "string",
            "example": "TechFlow Enterprises"
          },
          "clientRef": {
            "type": "string",
            "example": "TF-2024-789"
          }
        }
      },
      "WIPType": {
        "type": "string",
        "enum": [
          "Time",
          "Expense",
          "Fixed_Fee",
          "Disbursement"
        ],
        "description": "Available WIP types"
      },
      "Job": {
        "type": "object",
        "description": "Job information for WIP tracking",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "example": 2514
          },
          "name": {
            "type": "string",
            "example": "Q1 Financial Review 2024"
          }
        }
      },
      "PaginationRequest": {
        "type": "object",
        "description": "Limit/offset pagination for list and search endpoints. `pageSize` is a limit\nand `page` is an offset (records to skip), not a page index.\n",
        "properties": {
          "pageSize": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "default": 50,
            "description": "Limit, the number of records to return (not a page count).",
            "example": 25
          },
          "page": {
            "type": "integer",
            "minimum": 0,
            "default": 0,
            "description": "Offset, the number of records to skip. This is not a page index. To fetch the\nnext N rows after the first N, send `pageSize: N` and `page: N`. An offset\nat or beyond `total.aggregate.count` returns an empty result array.\n",
            "example": 0
          }
        }
      },
      "ARTransaction": {
        "type": "object",
        "description": "Accounts receivable transaction record",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique transaction identifier",
            "example": 125001
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice management system reference number",
            "example": "240815"
          },
          "type": {
            "allOf": [
              {
                "$ref": "#/components/schemas/TransactionType"
              }
            ],
            "description": "Transaction type classification"
          },
          "transactionDate": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
            "description": "Date when transaction occurred, as a local date-time with no time-zone offset",
            "example": "2024-02-15T05:00:00"
          },
          "amount": {
            "type": "number",
            "format": "decimal",
            "description": "Transaction amount as a decimal, USD (negative for receipts/credits)",
            "example": -1250
          },
          "allocated": {
            "type": "number",
            "format": "decimal",
            "description": "Amount allocated/applied to invoices, as a decimal, USD",
            "example": -1250
          },
          "notes": {
            "type": "string",
            "description": "Additional transaction notes or comments",
            "example": null
          },
          "clientId": {
            "type": "integer",
            "description": "Associated client identifier",
            "example": 1
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Record creation timestamp",
            "example": "2024-05-12T22:50:18.418236+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Record last update timestamp",
            "example": "2024-05-12T22:50:18.418236+00:00"
          },
          "client": {
            "$ref": "#/components/schemas/ClientBasic"
          }
        }
      },
      "AggregateCountSum": {
        "type": "object",
        "description": "Count and sum aggregation for financial data",
        "properties": {
          "aggregate": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer",
                "description": "Total number of records matching criteria",
                "example": 48
              },
              "sum": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number",
                    "format": "decimal",
                    "description": "Sum of amounts",
                    "example": -52750
                  },
                  "allocated": {
                    "type": "number",
                    "format": "decimal",
                    "description": "Sum of allocated amounts",
                    "example": -52750
                  }
                }
              }
            }
          }
        }
      },
      "Credit": {
        "type": "object",
        "description": "Credit entry with categorization",
        "properties": {
          "ar_tran_id": {
            "type": "integer",
            "description": "Associated AR transaction identifier",
            "example": 125890
          },
          "is_partial": {
            "type": "boolean",
            "description": "Whether this is a partial credit (true) or full credit (false)",
            "example": false
          },
          "credit_label_id": {
            "type": "integer",
            "description": "Reference to credit categorization label",
            "example": 3
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Credit record creation timestamp",
            "example": "2024-05-12T22:50:21.31979+00:00"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Credit record last update timestamp",
            "example": "2024-05-12T22:50:21.31979+00:00"
          },
          "creditLabel": {
            "$ref": "#/components/schemas/CreditLabel"
          }
        }
      },
      "Debit": {
        "type": "object",
        "description": "Debit entry with categorization and staff tracking",
        "properties": {
          "ar_tran_id": {
            "type": "integer",
            "description": "Associated AR transaction identifier",
            "example": 125890
          },
          "debit_label_id": {
            "type": "integer",
            "description": "Reference to debit categorization label",
            "example": 2
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Debit record creation timestamp",
            "example": "2024-05-12T22:50:21.31979+00:00"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Debit record last update timestamp",
            "example": "2024-05-12T22:50:21.31979+00:00"
          },
          "created_by_staff_id": {
            "type": "integer",
            "description": "ID of staff member who created the debit",
            "example": 15
          },
          "last_updated_by_staff_id": {
            "type": "integer",
            "description": "ID of staff member who last updated the debit",
            "example": 15
          },
          "custom_field_values": {
            "type": "object",
            "description": "Additional custom field data in JSON format",
            "example": {
              "reason": "Late payment fee",
              "approved_by": "manager"
            }
          },
          "debitLabel": {
            "$ref": "#/components/schemas/DebitLabel"
          },
          "createdByStaff": {
            "$ref": "#/components/schemas/StaffMember"
          },
          "lastUpdatedByStaff": {
            "$ref": "#/components/schemas/StaffMember"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "description": "Invoice record with AR transaction details",
        "required": [
          "arTranId",
          "invoiceNumber",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "arTranId": {
            "type": "integer",
            "description": "Associated AR transaction identifier",
            "example": 125890
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Unique invoice number for client reference",
            "example": "INV-2024-4850"
          },
          "dueDate": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
            "description": "Invoice payment due date, as a local date-time with no time-zone offset",
            "example": "2024-04-24T05:00:00"
          },
          "status": {
            "allOf": [
              {
                "$ref": "#/components/schemas/InvoiceStatus"
              }
            ],
            "description": "Current invoice status"
          },
          "tax": {
            "type": "number",
            "format": "decimal",
            "description": "Tax amount charged on invoice, as a decimal, USD",
            "example": 0
          },
          "interest": {
            "type": "number",
            "format": "decimal",
            "description": "Interest charges applied to invoice, as a decimal, USD",
            "example": 0
          },
          "description": {
            "type": "string",
            "description": "Additional invoice description or notes",
            "example": null
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Invoice record creation timestamp",
            "example": "2024-05-12T22:50:20.595961+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Invoice record last update timestamp",
            "example": "2024-05-12T22:50:20.595961+00:00"
          },
          "ar_tran": {
            "$ref": "#/components/schemas/ARTransactionBasic"
          }
        }
      },
      "Payment": {
        "type": "object",
        "description": "Payment record with security compliance",
        "required": [
          "id",
          "arTranId",
          "amount",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique payment identifier",
            "example": 45201
          },
          "arTranId": {
            "type": "integer",
            "description": "Associated AR transaction identifier",
            "example": 125890
          },
          "paymentMethod": {
            "allOf": [
              {
                "$ref": "#/components/schemas/PaymentMethod"
              }
            ],
            "description": "Payment method type"
          },
          "amount": {
            "type": "number",
            "format": "decimal",
            "description": "Payment amount as a decimal, USD",
            "example": 2750
          },
          "paymentDate": {
            "type": "string",
            "format": "date-time",
            "description": "Date when payment was processed",
            "example": "2024-03-15T14:30:22+00:00"
          },
          "confirmationDate": {
            "type": "string",
            "format": "date-time",
            "description": "Date when payment was confirmed",
            "example": "2024-03-15T14:32:18+00:00"
          },
          "status": {
            "allOf": [
              {
                "$ref": "#/components/schemas/PaymentStatus"
              }
            ],
            "description": "Current payment status"
          },
          "processorId": {
            "type": "string",
            "description": "Payment processor identifier",
            "example": "stripe"
          },
          "processorReferenceId": {
            "type": "string",
            "description": "Payment processor transaction reference",
            "example": "pi_3N1K2mL4uZ5v6w7x8y9z0a1b"
          },
          "last4Digits": {
            "type": "string",
            "description": "Last 4 digits of card (PCI compliant)",
            "example": "4242"
          },
          "cardType": {
            "type": "string",
            "description": "Credit card type",
            "example": "VISA"
          },
          "currency": {
            "type": "string",
            "description": "Payment currency code",
            "example": "USD"
          },
          "clientId": {
            "type": "integer",
            "description": "Associated client identifier",
            "example": 789
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Payment record creation timestamp",
            "example": "2024-03-15T14:30:22.123456+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Payment record last update timestamp",
            "example": "2024-03-15T14:32:18.789012+00:00"
          },
          "client": {
            "$ref": "#/components/schemas/ClientWithRef"
          },
          "ar_tran": {
            "$ref": "#/components/schemas/ARTransactionBasic"
          }
        }
      },
      "WIP": {
        "type": "object",
        "description": "Work in Progress record with financial tracking",
        "required": [
          "id",
          "wipType",
          "clientId",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique WIP record identifier",
            "example": 850321
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice management system reference",
            "example": "1789456"
          },
          "wipType": {
            "allOf": [
              {
                "$ref": "#/components/schemas/WIPType"
              }
            ],
            "description": "Type of WIP entry"
          },
          "loggedDate": {
            "type": "string",
            "format": "date-time",
            "description": "Date when WIP was logged",
            "example": "2024-01-17T05:00:00"
          },
          "wipValue": {
            "type": "number",
            "format": "decimal",
            "description": "Original WIP value recorded, as a decimal, USD",
            "example": 1250
          },
          "wipValueOutstanding": {
            "type": "number",
            "format": "decimal",
            "description": "Outstanding WIP value yet to be billed, as a decimal, USD",
            "example": 0
          },
          "billedAmount": {
            "type": "number",
            "format": "decimal",
            "description": "Amount that has been billed from this WIP, as a decimal, USD",
            "example": 1225
          },
          "writeOffAmount": {
            "type": "number",
            "format": "decimal",
            "description": "Amount written off as uncollectible, as a decimal, USD",
            "example": 25
          },
          "notes": {
            "type": "string",
            "description": "Additional notes or description for the WIP entry",
            "example": "Consultation and analysis for Q1 financial review"
          },
          "clientId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated client identifier. Null when the entry is not linked to a client.",
            "example": 1561
          },
          "jobId": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Associated job identifier. Null when the entry is not linked to a job, as is usual for an expense.",
            "example": 2514
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "WIP record creation timestamp",
            "example": "2024-05-12T23:02:33.24516+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "WIP record last update timestamp",
            "example": "2024-05-12T23:02:33.24516+00:00"
          },
          "client": {
            "$ref": "#/components/schemas/ClientBasic"
          },
          "job": {
            "$ref": "#/components/schemas/Job"
          }
        }
      },
      "WIPAggregate": {
        "type": "object",
        "description": "WIP-specific aggregation with financial summaries",
        "properties": {
          "aggregate": {
            "type": "object",
            "properties": {
              "count": {
                "type": "integer",
                "description": "Total number of WIP records",
                "example": 84
              },
              "sum": {
                "type": "object",
                "properties": {
                  "wipValue": {
                    "type": "number",
                    "format": "decimal",
                    "description": "Total WIP value",
                    "example": 24186.15
                  },
                  "billedAmount": {
                    "type": "number",
                    "format": "decimal",
                    "description": "Total billed amount",
                    "example": 19612.07
                  },
                  "wipValueOutstanding": {
                    "type": "number",
                    "format": "decimal",
                    "description": "Total outstanding WIP value",
                    "example": 125
                  }
                }
              }
            }
          }
        }
      },
      "StaffUserTask": {
        "type": "object",
        "description": "Staff user task from vw_my_task with task type and job info",
        "properties": {
          "id": {
            "type": "integer",
            "example": 88015
          },
          "taskType": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "BILLABLE"
              },
              "id": {
                "type": "integer",
                "example": 12
              },
              "display": {
                "type": "string",
                "example": "Billable Work"
              },
              "billable": {
                "type": "boolean",
                "example": true
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2024-05-10T09:10:11.000000+00:00"
              },
              "createdAt": {
                "type": "string",
                "format": "date-time",
                "example": "2023-05-10T09:10:11.000000+00:00"
              },
              "isManagedByAiwyn": {
                "type": "boolean",
                "example": true
              },
              "rate_type": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "example": 3
                  },
                  "name": {
                    "type": "string",
                    "example": "Hourly"
                  },
                  "createdAt": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2020-01-01T00:00:00+00:00"
                  },
                  "updatedAt": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2020-01-01T00:00:00+00:00"
                  }
                }
              },
              "task_type_category": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "example": 2
                  },
                  "name": {
                    "type": "string",
                    "example": "Consulting"
                  },
                  "description": {
                    "type": "string",
                    "example": "Client-facing consulting tasks"
                  },
                  "associatedTaskTypes": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "example": [
                      11,
                      12,
                      13
                    ]
                  },
                  "createdAt": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2020-01-01T00:00:00+00:00"
                  },
                  "updatedAt": {
                    "type": "string",
                    "format": "date-time",
                    "example": "2020-01-01T00:00:00+00:00"
                  }
                }
              },
              "job_templates": {
                "type": "object",
                "properties": {
                  "aggregate": {
                    "type": "object",
                    "properties": {
                      "count": {
                        "type": "integer",
                        "example": 5
                      }
                    }
                  }
                }
              }
            }
          },
          "job": {
            "type": "object",
            "description": "Project information for the task",
            "properties": {
              "id": {
                "type": "integer",
                "example": 5012
              },
              "name": {
                "type": "string",
                "example": "Q1 Financial Review 2024"
              },
              "client": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "example": 2180
                  },
                  "name": {
                    "type": "string",
                    "example": "TechFlow Enterprises"
                  },
                  "clientRef": {
                    "type": "string",
                    "example": "TF-2024-789"
                  }
                }
              }
            }
          }
        }
      },
      "Address": {
        "type": "object",
        "description": "Reusable postal address block",
        "properties": {
          "address": {
            "type": "string",
            "description": "Street address",
            "example": "123 Main Street"
          },
          "city": {
            "type": "string",
            "description": "City",
            "example": "Anytown"
          },
          "state": {
            "type": "string",
            "description": "State or province code",
            "example": "CA"
          },
          "zip_code": {
            "type": "string",
            "description": "Postal / ZIP code",
            "example": "12345"
          }
        }
      },
      "StaffComplete": {
        "type": "object",
        "description": "Complete staff record with department and type information",
        "required": [
          "id",
          "firstName",
          "lastName",
          "active",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "Unique staff identifier",
            "example": 301
          },
          "pmsRef": {
            "type": "string",
            "description": "Practice management system reference",
            "example": "2650"
          },
          "staffRef": {
            "type": "string",
            "description": "Staff reference code or initials",
            "example": "JDM"
          },
          "firstName": {
            "type": "string",
            "description": "Employee first name",
            "example": "Sarah"
          },
          "lastName": {
            "type": "string",
            "description": "Employee last name",
            "example": "Johnson"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "description": "Employee email address. Null for staff without an email address on file.",
            "example": "sarah.johnson@company.com"
          },
          "active": {
            "type": "boolean",
            "description": "Employee active status",
            "example": true
          },
          "deptId": {
            "type": "integer",
            "description": "Department identifier",
            "example": 7
          },
          "staffTypeId": {
            "type": "integer",
            "description": "Staff type classification identifier",
            "example": 11
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Staff record creation timestamp",
            "example": "2024-05-12T22:42:02.719873+00:00"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Staff record last update timestamp",
            "example": "2024-05-12T22:42:05.487898+00:00"
          },
          "department": {
            "$ref": "#/components/schemas/Department"
          },
          "staff_type": {
            "$ref": "#/components/schemas/StaffType"
          }
        }
      },
      "FilterRequest": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PaginationRequest"
          },
          {
            "type": "object",
            "properties": {
              "where": {
                "type": "object",
                "description": "Boolean expression for filtering",
                "additionalProperties": true,
                "example": {
                  "_and": [
                    {
                      "active": {
                        "_eq": true
                      }
                    },
                    {
                      "name": {
                        "_ilike": "%searchterm%"
                      }
                    }
                  ]
                }
              },
              "orderBy": {
                "type": "array",
                "description": "Array of sorting criteria",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                },
                "example": [
                  {
                    "name": "asc"
                  },
                  {
                    "createdAt": "desc"
                  }
                ]
              }
            }
          }
        ]
      },
      "ClientListResponse": {
        "type": "object",
        "description": "Response of `POST /gql/v1/clients` and `POST /gql/v1/clients/search`",
        "required": [
          "clients",
          "total"
        ],
        "properties": {
          "clients": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Client"
            }
          },
          "total": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "ARTransactionListResponse": {
        "type": "object",
        "description": "Standard response format for AR transaction endpoints",
        "properties": {
          "deid_ar_tran": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ARTransaction"
            }
          },
          "deid_ar_tran_aggregate": {
            "$ref": "#/components/schemas/AggregateCountSum"
          }
        }
      },
      "CreditListResponse": {
        "type": "object",
        "description": "Standard response format for credit endpoints",
        "properties": {
          "deid_credit": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Credit"
            }
          },
          "deid_credit_aggregate": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "DebitListResponse": {
        "type": "object",
        "description": "Standard response format for debit endpoints",
        "properties": {
          "deid_debit": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Debit"
            }
          },
          "deid_debit_aggregate": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "InvoiceListResponse": {
        "type": "object",
        "description": "Standard response format for invoice endpoints",
        "properties": {
          "deid_invoice": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Invoice"
            }
          },
          "deid_invoice_aggregate": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "PaymentListResponse": {
        "type": "object",
        "description": "Standard response format for payment endpoints",
        "properties": {
          "deid_payment": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Payment"
            }
          },
          "deid_payment_aggregate": {
            "type": "object",
            "properties": {
              "aggregate": {
                "type": "object",
                "properties": {
                  "count": {
                    "type": "integer",
                    "example": 15
                  },
                  "sum": {
                    "type": "object",
                    "properties": {
                      "amount": {
                        "type": "number",
                        "format": "decimal",
                        "description": "Total payment amount",
                        "example": 28750
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "StaffListResponse": {
        "type": "object",
        "description": "Standard response format for staff endpoints",
        "properties": {
          "staff": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StaffDirectoryRecord"
            }
          },
          "total": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      },
      "WIPListResponse": {
        "type": "object",
        "description": "Standard response format for WIP endpoints",
        "properties": {
          "deid_wip": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WIP"
            }
          },
          "deid_wip_aggregate": {
            "$ref": "#/components/schemas/WIPAggregate"
          }
        }
      },
      "EngagementStatus": {
        "type": "string",
        "enum": [
          "DRAFT",
          "IN_REVIEW",
          "IN_APPROVAL",
          "READY_TO_SEND",
          "SENT",
          "UNDER_REVISION",
          "EXECUTED",
          "CANCELED",
          "ARCHIVED"
        ],
        "description": "Stored engagement statuses. Read operations report an engagement in `IN_REVIEW` with the\nname of its current workflow step instead.\n"
      },
      "SortOrder": {
        "type": "string",
        "enum": [
          "asc",
          "desc"
        ],
        "description": "Sort order options"
      },
      "StaffUserTaskListResponse": {
        "type": "object",
        "description": "Standard response format for staff user task endpoints",
        "properties": {
          "tasks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StaffUserTask"
            }
          },
          "total": {
            "$ref": "#/components/schemas/AggregateCount"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Aiwyn-Api-Key",
        "description": "Direct JWT API key authentication (recommended).\n\nSend your long-lived JWT API key in the `X-Aiwyn-Api-Key` header:\n```\nX-Aiwyn-Api-Key: dev:eyJ...\n```\nThe server validates the key, loads your identity and permissions directly from the database,\nand sets the tenant context from the key itself. The key alone decides who you are and which tenant\nyou reach. Do not send a `Tenant` header with the key:\n- `/gql/v1/...` paths ignore it, like any other header such as `X-Tenant-ID`.\n- `/api/v1/...` paths refuse the request with `403` when a `Tenant` header is present, whatever its\n  value, even your own tenant. The error body does not name the header: on an endpoint that\n  requires a role, its message says which roles the endpoint requires (`details.reason` is\n  `INSUFFICIENT_ROLE`) even when your key has one of them. Elsewhere it reads `Access Denied`\n  (`details.reason` is `ACCESS_DENIED`). Remove the `Tenant` header before looking for a\n  permissions problem.\n\n**Note:** `refresh-token` and `revoke-token` require an `Authorization: Bearer` token and\ndo not support `X-Aiwyn-Api-Key`.\n\n**Example:**\n```bash\ncurl -X POST https://api.sandbox.aiwyn.app/gql/v1/clients \\\n     -H \"CF-Access-Client-Id: <cf-access-client-id>\" \\\n     -H \"CF-Access-Client-Secret: <cf-access-client-secret>\" \\\n     -H \"X-Aiwyn-Api-Key: dev:eyJhbGciOiJIUzUxMiJ9...\" \\\n     -H \"Content-Type: application/json\" \\\n     -d '{ \"pageSize\": 5, \"page\": 0 }'\n```\n"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Short-lived bearer token authentication.\n\nSend the bearer token in the `Authorization` header:\n```\nAuthorization: Bearer eyJ...\n```\nThe tenant is read from the token's `tenant` claim. The token alone decides who you are and which\ntenant you reach: any other header, including `Tenant` or `X-Tenant-ID`, is ignored.\n\n**Token requirements:**\n- Issued by Aiwyn, obtained via `/v1/auth/token`\n- Carries your role-based permissions and tenant context\n- Standard expiration: 1 hour (3600 seconds)\n\nRequest a new token from `/v1/auth/token` when the current one expires;\na `401` response indicates a missing or expired token.\n\n**Example:**\n```bash\ncurl --request POST 'https://api.sandbox.aiwyn.app/gql/v1/clients' \\\n  --header 'CF-Access-Client-Id: <cf-access-client-id>' \\\n  --header 'CF-Access-Client-Secret: <cf-access-client-secret>' \\\n  --header 'Authorization: Bearer <token>' \\\n  --header 'Content-Type: application/json' \\\n  --data '{ \"pageSize\": 5, \"page\": 0 }'\n```\n"
      },
      "CfAccessClientId": {
        "type": "apiKey",
        "in": "header",
        "name": "CF-Access-Client-Id",
        "description": "Cloudflare Access service token client ID issued by Aiwyn. Required on every request to Sandbox\n(`api.sandbox.aiwyn.app`) and Staging (`api.staging.aiwyn.app`), including `POST /v1/auth/token`;\nsend it with `CF-Access-Client-Secret`. Cloudflare checks it at the edge, before the API\nauthenticates the request with your Aiwyn credentials. Production does not use it.\n"
      },
      "CfAccessClientSecret": {
        "type": "apiKey",
        "in": "header",
        "name": "CF-Access-Client-Secret",
        "description": "Cloudflare Access service token client secret issued by Aiwyn. Required alongside\n`CF-Access-Client-Id` on Sandbox and Staging. Keep it server-side and out of source control.\n"
      }
    }
  }
}