{
  "openapi": "3.1.0",
  "info": {
    "title": "ReportGeneratorTool API",
    "version": "1.0.0",
    "description": "# Welcome to the ReportGeneratorTool API\n\nGenerate temperature-report PDFs, monitor report jobs, download completed reports and manage email delivery.\nThis reference defines the v1 API contract and includes request models, response examples and runnable client snippets.\n\n## Servers and authentication\n\n{% tabs %}\n{% tab title=\"Production\" %}\n**Base URL**\n`https://api.reportgenerator.example.com`\n{% endtab %}\n{% tab title=\"Staging\" %}\n**Base URL**\n`https://api.staging.reportgenerator.example.com`\n{% endtab %}\n{% endtabs %}\n\n### Authentication\n\nSend `Authorization: Bearer YOUR_API_KEY` on /v1 requests.\nUse a workspace API key issued by your administrator.\nResources are scoped to that workspace.\nA resource outside the workspace returns 404; a disallowed action returns 403.\n\nPortal credentials in `client` authenticate to the device portal and are separate from the API key.\nThey are not included in job responses.\n\n## Getting started\n\n{% stepper %}\n{% step %}\n## Obtain a workspace API key\nRequest a key and your API base URL from your administrator.\n{% endstep %}\n{% step %}\n## Create a report job\nCall POST /v1/report-jobs with portal details, one device, a UTC date range and recipients.\nSend a fresh Idempotency-Key for each intended job.\nThe contract returns 202 Accepted and a Location header identifying the job.\n{% endstep %}\n{% step %}\n## Poll the job\nCall GET /v1/report-jobs/{jobId} every five seconds until succeeded, failed or cancelled.\nHonor Retry-After when supplied.\n{% endstep %}\n{% step %}\n## Download the PDF\nUse reportId with GET /v1/reports/{reportId}/download.\nThe response contains PDF bytes.\nInitial generation also sends the report by email.\n{% endstep %}\n{% endstepper %}\n\n## Requests and lifecycle\n\n### Validation\nUse JSON and keep request bodies within 256 KiB.\nSupply exactly one device per job and 1 to 20 unique email recipients.\nUse UTC RFC 3339 timestamps ending in Z, with fromDate before toDate and at most 31 days per request.\nThresholds must be finite numbers with min less than max.\nPortal and logo URLs must use supported HTTPS hosts.\nPrivate-network destinations and redirects to them are rejected.\n\n### Job states\nJobs move from queued to running, then succeeded or failed.\nCancellation moves an active job through cancelling to cancelled.\nCancellation is best effort and cannot recall an email already submitted.\nSucceeded means the PDF is persisted and the initial email is accepted by the provider; it does not confirm inbox delivery.\nIf the PDF exists but email fails, the job contains failed status, reportId and a sanitized error so callers can download and retry delivery.\n\n### Idempotency\nSend Idempotency-Key on job creation and email retry.\nKeys contain 8 to 128 letters, digits, periods, underscores or hyphens.\nKeys are scoped by workspace and operation for 24 hours.\nThe same key and body replay the original accepted status, body and resource headers.\nA changed body with the same key returns 409 idempotency_conflict.\n\n### Limits and retention\nThe contract allows 60 requests per minute per workspace and five queued or active jobs.\nDownloads count toward the request rate.\nLimit responses use 429 and Retry-After.\nJob metadata, delivery metadata and PDFs have a 30-day retention period.\nExpired PDFs return 410 while metadata remains; lookups return 404 after metadata is purged.\nList cursors last 15 minutes and are bound to the workspace, endpoint and filters.\nInvalid or expired cursors return 400 invalid_cursor.\nLists sort newest first by createdAt and then by ID.\n\n## Error responses\n\n/v1 errors use a consistent envelope:\n\n```json\n{\"error\":{\"code\":\"validation_error\",\"message\":\"The request contains invalid fields.\",\"requestId\":\"req_example_001\",\"details\":[{\"field\":\"toDate\",\"message\":\"Must be later than fromDate.\"}]}}\n```\n\n| Status | Meaning |\n| --- | --- |\n| 400 | Invalid JSON, query or cursor |\n| 401 | Missing or invalid API key |\n| 403 | Insufficient permission |\n| 404 | Resource not found in this workspace |\n| 409 | Invalid state or idempotency conflict |\n| 410 | Report expired |\n| 413 | Body exceeds 256 KiB |\n| 415 | Unsupported content type |\n| 422 | Semantic validation failed |\n| 429 | Rate or concurrency limit |\n| 500 | Unexpected failure |\n| 503 | Temporary dependency failure |\n\nX-Request-Id identifies the response and appears in the error body.\nRetry-After gives the wait in seconds for 429 and 503.\nRetry job creation or delivery with the same idempotency key and unchanged body.\n\n## Legacy orchestration API\n\nThe legacy starter accepts GET and POST at /api/orchestrators/{orchestratorName}.\nUse report-automation as the orchestration name.\nBoth methods read a JSON body and start work; GET does not retrieve an existing report.\nThe starter returns the Durable Functions check-status response, whose management URLs should be used to inspect the instance.\nThe v1 request schemas and error envelope apply to /v1 operations.\nLegacy activity validation and runtime responses are documented separately in the legacy endpoint descriptions.\n"
  },
  "tags": [
    {
      "name": "reporting",
      "x-page-title": "Reporting",
      "x-page-icon": "file-lines"
    },
    {
      "name": "jobs",
      "x-parent": "reporting",
      "x-page-title": "Report jobs",
      "x-page-icon": "list-check"
    },
    {
      "name": "reports",
      "x-parent": "reporting",
      "x-page-title": "Reports",
      "x-page-icon": "file-pdf"
    },
    {
      "name": "delivery",
      "x-parent": "reporting",
      "x-page-title": "Email delivery",
      "x-page-icon": "envelope"
    }
  ],
  "paths": {
    "/v1/report-jobs": {
      "post": {
        "tags": [
          "jobs"
        ],
        "operationId": "CreateReportJob",
        "summary": "Create a report job",
        "description": "Validate before queueing one report. Initial processing includes PDF generation and email delivery.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request POST 'https://api.staging.reportgenerator.example.com/v1/report-jobs' \\\n  --header 'Authorization: Bearer YOUR_API_KEY' \\\n  --header 'Content-Type: application/json' \\\n  --header 'Idempotency-Key: example-action-001' \\\n  --data '{\"client\":{\"name\":\"Example Client\",\"username\":\"PORTAL_USERNAME\",\"password\":\"PORTAL_PASSWORD\",\"logo\":\"https://assets.example.invalid/logo.png\"},\"url\":\"https://portal.example.invalid/login\",\"devices\":[{\"device_id\":\"DEVICE-001\",\"temp_threshold\":{\"min\":2,\"max\":8}}],\"fromDate\":\"2026-09-01T00:00:00Z\",\"toDate\":\"2026-10-01T00:00:00Z\",\"sentTo\":[\"recipient@example.invalid\"]}'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/report-jobs', {\n  method: 'POST',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\",\n  \"Content-Type\": \"application/json\",\n  \"Idempotency-Key\": \"example-action-001\"\n},\n  body: JSON.stringify({\n  \"client\": {\n    \"name\": \"Example Client\",\n    \"username\": \"PORTAL_USERNAME\",\n    \"password\": \"PORTAL_PASSWORD\",\n    \"logo\": \"https://assets.example.invalid/logo.png\"\n  },\n  \"url\": \"https://portal.example.invalid/login\",\n  \"devices\": [\n    {\n      \"device_id\": \"DEVICE-001\",\n      \"temp_threshold\": {\n        \"min\": 2,\n        \"max\": 8\n      }\n    }\n  ],\n  \"fromDate\": \"2026-09-01T00:00:00Z\",\n  \"toDate\": \"2026-10-01T00:00:00Z\",\n  \"sentTo\": [\n    \"recipient@example.invalid\"\n  ]\n}),\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.post(\n    \"https://api.staging.reportgenerator.example.com/v1/report-jobs\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\",\"Content-Type\":\"application/json\",\"Idempotency-Key\":\"example-action-001\"},\n    json={\"client\":{\"name\":\"Example Client\",\"username\":\"PORTAL_USERNAME\",\"password\":\"PORTAL_PASSWORD\",\"logo\":\"https://assets.example.invalid/logo.png\"},\"url\":\"https://portal.example.invalid/login\",\"devices\":[{\"device_id\":\"DEVICE-001\",\"temp_threshold\":{\"min\":2,\"max\":8}}],\"fromDate\":\"2026-09-01T00:00:00Z\",\"toDate\":\"2026-10-01T00:00:00Z\",\"sentTo\":[\"recipient@example.invalid\"]},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateReportJobRequest"
              },
              "example": {
                "client": {
                  "name": "Example Client",
                  "username": "PORTAL_USERNAME",
                  "password": "PORTAL_PASSWORD",
                  "logo": "https://assets.example.invalid/logo.png"
                },
                "url": "https://portal.example.invalid/login",
                "devices": [
                  {
                    "device_id": "DEVICE-001",
                    "temp_threshold": {
                      "min": 2,
                      "max": 8
                    }
                  }
                ],
                "fromDate": "2026-09-01T00:00:00Z",
                "toDate": "2026-10-01T00:00:00Z",
                "sentTo": [
                  "recipient@example.invalid"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "schema": {
                  "type": "string"
                },
                "description": "Relative URL /v1/report-jobs/{jobId}."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportJob"
                },
                "example": {
                  "id": "job_example_001",
                  "status": "queued",
                  "createdAt": "2026-10-01T00:00:00Z",
                  "updatedAt": "2026-10-01T00:00:00Z",
                  "reportId": null,
                  "error": null
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "415": {
            "$ref": "#/components/responses/Error415"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      },
      "get": {
        "tags": [
          "jobs"
        ],
        "operationId": "ListReportJobs",
        "summary": "List report jobs",
        "description": "List this workspace's jobs newest first. Keep filters unchanged when using a cursor.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/report-jobs' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/report-jobs', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/report-jobs\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "queued",
                "running",
                "cancelling",
                "succeeded",
                "failed",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of jobs.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportJobList"
                },
                "example": {
                  "data": [
                    {
                      "id": "job_example_001",
                      "status": "succeeded",
                      "createdAt": "2026-10-01T00:00:00Z",
                      "updatedAt": "2026-10-01T00:02:00Z",
                      "reportId": "rpt_example_001",
                      "error": null
                    }
                  ],
                  "nextCursor": null
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/report-jobs/{jobId}": {
      "get": {
        "tags": [
          "jobs"
        ],
        "operationId": "GetReportJob",
        "summary": "Get job status",
        "description": "Poll every five seconds until succeeded, failed or cancelled. Email failure can leave an available reportId.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current job state.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportJob"
                },
                "example": {
                  "id": "job_example_001",
                  "status": "succeeded",
                  "createdAt": "2026-10-01T00:00:00Z",
                  "updatedAt": "2026-10-01T00:02:00Z",
                  "reportId": "rpt_example_001",
                  "error": null
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/report-jobs/{jobId}/cancel": {
      "post": {
        "tags": [
          "jobs"
        ],
        "operationId": "CancelReportJob",
        "summary": "Request cancellation",
        "description": "Accept queued or running jobs. Repeating for cancelling or cancelled returns the current state. Succeeded or failed returns 409. Cannot recall submitted email.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request POST 'https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001/cancel' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001/cancel', {\n  method: 'POST',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.post(\n    \"https://api.staging.reportgenerator.example.com/v1/report-jobs/job_example_001/cancel\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Already cancelled.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportJob"
                },
                "example": {
                  "id": "job_example_001",
                  "status": "cancelled",
                  "createdAt": "2026-10-01T00:00:00Z",
                  "updatedAt": "2026-10-01T00:02:00Z",
                  "reportId": null,
                  "error": null
                }
              }
            }
          },
          "202": {
            "description": "Cancellation pending.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportJob"
                },
                "example": {
                  "id": "job_example_001",
                  "status": "cancelling",
                  "createdAt": "2026-10-01T00:00:00Z",
                  "updatedAt": "2026-10-01T00:02:00Z",
                  "reportId": null,
                  "error": null
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/reports": {
      "get": {
        "tags": [
          "reports"
        ],
        "operationId": "ListReports",
        "summary": "List reports",
        "description": "List report metadata for this workspace, including retained metadata for expired PDFs.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/reports' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/reports', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/reports\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of reports.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportList"
                },
                "example": {
                  "data": [
                    {
                      "id": "rpt_example_001",
                      "jobId": "job_example_001",
                      "deviceId": "DEVICE-001",
                      "filename": "Example-Client-report.pdf",
                      "createdAt": "2026-10-01T00:02:00Z",
                      "expiresAt": "2026-10-31T00:02:00Z",
                      "deliveryStatus": "sent"
                    }
                  ],
                  "nextCursor": null
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/reports/{reportId}": {
      "get": {
        "tags": [
          "reports"
        ],
        "operationId": "GetReport",
        "summary": "Get report metadata",
        "description": "Read metadata, expiry and latest delivery status. Metadata remains readable after PDF expiry until purged.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Report metadata.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                },
                "example": {
                  "id": "rpt_example_001",
                  "jobId": "job_example_001",
                  "deviceId": "DEVICE-001",
                  "filename": "Example-Client-report.pdf",
                  "createdAt": "2026-10-01T00:02:00Z",
                  "expiresAt": "2026-10-31T00:02:00Z",
                  "deliveryStatus": "sent"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/reports/{reportId}/download": {
      "get": {
        "tags": [
          "reports"
        ],
        "operationId": "DownloadReport",
        "summary": "Download report PDF",
        "description": "Stream PDF bytes after workspace authorization. Expired PDFs return 410 while metadata remains retained.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/download' \\\n  --header 'Authorization: Bearer YOUR_API_KEY' \\\n  --output report.pdf"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/download', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconst pdf = await response.arrayBuffer();"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/download\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nwith open(\"report.pdf\", \"wb\") as report_file:\n    report_file.write(response.content)"
          }
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "PDF bytes.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                },
                "example": "attachment; filename=\"Example-Client-report.pdf\""
              },
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "example": "private, no-store"
              }
            },
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "410": {
            "$ref": "#/components/responses/Error410"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/reports/{reportId}/email-deliveries": {
      "post": {
        "tags": [
          "delivery"
        ],
        "operationId": "CreateEmailDelivery",
        "summary": "Send report again",
        "description": "Queue another email using an existing unexpired PDF. A fresh idempotency key intentionally sends a new message; a replay does not.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request POST 'https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/email-deliveries' \\\n  --header 'Authorization: Bearer YOUR_API_KEY' \\\n  --header 'Content-Type: application/json' \\\n  --header 'Idempotency-Key: example-action-001' \\\n  --data '{\"sentTo\":[\"recipient@example.invalid\"]}'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/email-deliveries', {\n  method: 'POST',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\",\n  \"Content-Type\": \"application/json\",\n  \"Idempotency-Key\": \"example-action-001\"\n},\n  body: JSON.stringify({\n  \"sentTo\": [\n    \"recipient@example.invalid\"\n  ]\n}),\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.post(\n    \"https://api.staging.reportgenerator.example.com/v1/reports/rpt_example_001/email-deliveries\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\",\"Content-Type\":\"application/json\",\"Idempotency-Key\":\"example-action-001\"},\n    json={\"sentTo\":[\"recipient@example.invalid\"]},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmailDeliveryRequest"
              },
              "example": {
                "sentTo": [
                  "recipient@example.invalid"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Delivery queued.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "schema": {
                  "type": "string"
                },
                "description": "Relative URL /v1/email-deliveries/{deliveryId}."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailDelivery"
                },
                "example": {
                  "id": "dlv_example_001",
                  "reportId": "rpt_example_001",
                  "status": "queued",
                  "createdAt": "2026-10-01T00:02:00Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "410": {
            "$ref": "#/components/responses/Error410"
          },
          "413": {
            "$ref": "#/components/responses/Error413"
          },
          "415": {
            "$ref": "#/components/responses/Error415"
          },
          "422": {
            "$ref": "#/components/responses/Error422"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/v1/email-deliveries/{deliveryId}": {
      "get": {
        "tags": [
          "delivery"
        ],
        "operationId": "GetEmailDelivery",
        "summary": "Get delivery status",
        "description": "Poll every five seconds. Sent means provider acceptance, not confirmed inbox delivery. Retain delivery metadata for 30 days.",
        "security": [
          {
            "WorkspaceApiKey": []
          }
        ],
        "x-hideTryItPanel": false,
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "CLI",
            "source": "curl --request GET 'https://api.staging.reportgenerator.example.com/v1/email-deliveries/dlv_example_001' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"
          },
          {
            "lang": "JavaScript",
            "label": "Fetch",
            "source": "const response = await fetch('https://api.staging.reportgenerator.example.com/v1/email-deliveries/dlv_example_001', {\n  method: 'GET',\n  headers: {\n  \"Authorization\": \"Bearer YOUR_API_KEY\"\n},\n});\nif (!response.ok) throw new Error(`HTTP ${response.status}`);\nconsole.log(await response.json());"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "import requests\n\nresponse = requests.get(\n    \"https://api.staging.reportgenerator.example.com/v1/email-deliveries/dlv_example_001\",\n    headers={\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nresponse.raise_for_status()\nprint(response.json())"
          }
        ],
        "parameters": [
          {
            "name": "deliveryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current delivery state.",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailDelivery"
                },
                "example": {
                  "id": "dlv_example_001",
                  "reportId": "rpt_example_001",
                  "status": "sent",
                  "createdAt": "2026-10-01T00:02:00Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "403": {
            "$ref": "#/components/responses/Error403"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "500": {
            "$ref": "#/components/responses/Error500"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorDetail": {
        "type": "object",
        "required": [
          "field",
          "message"
        ],
        "properties": {
          "field": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "requestId"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string"
              },
              "details": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ErrorDetail"
                }
              }
            }
          }
        }
      },
      "JobError": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "portal_login_failed",
              "portal_unavailable",
              "report_generation_failed",
              "email_delivery_failed",
              "internal_error"
            ]
          },
          "message": {
            "type": "string",
            "description": "Sanitized worker error."
          }
        }
      },
      "ReportJob": {
        "type": "object",
        "required": [
          "id",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "cancelling",
              "succeeded",
              "failed",
              "cancelled"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "reportId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Set after the PDF is stored, including when initial email subsequently fails."
          },
          "error": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/JobError"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "Report": {
        "type": "object",
        "required": [
          "id",
          "jobId",
          "deviceId",
          "filename",
          "createdAt",
          "expiresAt",
          "deliveryStatus"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "jobId": {
            "type": "string"
          },
          "deviceId": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryStatus": {
            "type": "string",
            "enum": [
              "pending",
              "sent",
              "failed"
            ]
          }
        }
      },
      "Client": {
        "type": "object",
        "required": [
          "name",
          "username",
          "password"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "username": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "password": {
            "type": "string",
            "format": "password",
            "writeOnly": true,
            "minLength": 1,
            "maxLength": 4096
          },
          "logo": {
            "type": "string",
            "description": "Optional HTTPS logo on an approved host.",
            "format": "uri",
            "pattern": "^https://"
          }
        },
        "additionalProperties": false
      },
      "TemperatureThreshold": {
        "type": "object",
        "required": [
          "min",
          "max"
        ],
        "properties": {
          "min": {
            "type": "number",
            "description": "Inclusive low threshold in degrees Celsius; less than max."
          },
          "max": {
            "type": "number",
            "description": "Inclusive high threshold in degrees Celsius; greater than min."
          }
        },
        "additionalProperties": false
      },
      "ReportDevice": {
        "type": "object",
        "required": [
          "device_id",
          "temp_threshold"
        ],
        "properties": {
          "device_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "temp_threshold": {
            "$ref": "#/components/schemas/TemperatureThreshold"
          }
        },
        "additionalProperties": false
      },
      "CreateReportJobRequest": {
        "type": "object",
        "required": [
          "client",
          "url",
          "devices",
          "fromDate",
          "toDate",
          "sentTo"
        ],
        "properties": {
          "client": {
            "$ref": "#/components/schemas/Client"
          },
          "url": {
            "type": "string",
            "description": "Allowlisted HTTPS portal URL.",
            "format": "uri",
            "pattern": "^https://"
          },
          "devices": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "$ref": "#/components/schemas/ReportDevice"
            }
          },
          "fromDate": {
            "type": "string",
            "description": "UTC RFC 3339 timestamp ending in Z.",
            "format": "date-time",
            "pattern": "Z$"
          },
          "toDate": {
            "type": "string",
            "description": "Later than fromDate and within 31 days.",
            "format": "date-time",
            "pattern": "Z$"
          },
          "sentTo": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "email"
            }
          }
        },
        "additionalProperties": false
      },
      "EmailDeliveryRequest": {
        "type": "object",
        "required": [
          "sentTo"
        ],
        "properties": {
          "sentTo": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "email"
            }
          }
        },
        "additionalProperties": false
      },
      "EmailDelivery": {
        "type": "object",
        "required": [
          "id",
          "reportId",
          "status",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "reportId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sending",
              "sent",
              "failed"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/JobError"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "ReportJobList": {
        "type": "object",
        "required": [
          "data",
          "nextCursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReportJob"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ReportList": {
        "type": "object",
        "required": [
          "data",
          "nextCursor"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Report"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "Required key for 24-hour deduplication. A changed body with the same key returns 409.",
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9._-]+$"
        },
        "example": "example-action-001"
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 20
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "description": "Opaque cursor, scoped to the workspace and filters; expires in 15 minutes.",
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "Error400": {
        "description": "Invalid JSON, query parameter or cursor.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "bad_request",
                "message": "Invalid JSON, query parameter or cursor.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error401": {
        "description": "Missing or invalid workspace API key.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthorized",
                "message": "Missing or invalid workspace API key.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error403": {
        "description": "Insufficient permission.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "Insufficient permission.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error404": {
        "description": "Resource not found in this workspace.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Resource not found in this workspace.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error409": {
        "description": "Resource state or idempotency conflict.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "conflict",
                "message": "Resource state or idempotency conflict.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error410": {
        "description": "Report PDF has expired.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "report_expired",
                "message": "Report PDF has expired.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error413": {
        "description": "Request exceeds 256 KiB.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "payload_too_large",
                "message": "Request exceeds 256 KiB.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error415": {
        "description": "Use application/json.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unsupported_media_type",
                "message": "Use application/json.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error422": {
        "description": "The request contains invalid fields.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "validation_error",
                "message": "The request contains invalid fields.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error429": {
        "description": "Workspace rate or concurrency limit reached.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          },
          "Retry-After": {
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Seconds to wait before retrying."
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Workspace rate or concurrency limit reached.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error500": {
        "description": "Unexpected service failure.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "internal_error",
                "message": "Unexpected service failure.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      },
      "Error503": {
        "description": "Temporary dependency failure.",
        "headers": {
          "X-Request-Id": {
            "schema": {
              "type": "string"
            }
          },
          "Retry-After": {
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Seconds to wait before retrying."
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "service_unavailable",
                "message": "Temporary dependency failure.",
                "requestId": "req_example_001"
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "WorkspaceApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Workspace API key issued by your administrator."
      }
    }
  },
  "x-source-repository": "TQKNG/automation",
  "x-source-branch": "main",
  "x-source-commit": "27045ec413f88cd2227ab08e18ec76db3e8e3d34",
  "servers": [
    {
      "url": "https://api.reportgenerator.example.com",
      "description": "Production example"
    },
    {
      "url": "https://api.staging.reportgenerator.example.com",
      "description": "Staging example"
    }
  ]
}