openapi: 3.1.0
info:
  title: Printcore API
  version: "1.0"
  summary: Jobs, quotes, customers, files, products, inventory and webhooks for print shops on Printcore.
  description: |
    The Printcore API connects your storefronts, apps and automations to a print shop's Printcore account.
    Create jobs and quotes, keep customers and your price list in sync, attach artwork, and get a webhook
    the moment work moves through the shop.

    ## Getting started
    1. **Get a key.** In Printcore, open **Shop Settings → API & Webhooks → Generate API Key**. Pick
       *Read & Write* to create records, or *Read Only* to look things up. The key is shown once.
    2. **Make a call.** Send the key in the `X-API-Key` header:

       ```bash
       curl "https://us-central1-quickbooks-app-c5298.cloudfunctions.net/api/v1/jobs?limit=5" \
         -H "X-API-Key: pk_live_your_key_here"
       ```
    3. **Building an app for many shops?** Use [OAuth 2.0](#section/authentication) ("Connect with
       Printcore") instead of asking each shop for a key. Email help@printcore.ai to register your app.
    4. **Want to try things safely?** Ask for access to the **sandbox shop**: a Pro shop full of fake
       customers, jobs and stock that is reset regularly.

    The API is part of the **Pro**, **Studio** and **Enterprise** plans. A key or token from a shop on
    another plan gets `403 FEATURE_NOT_IN_PLAN`.

    ## Authentication
    Every request needs one of these.

    **API key** (one shop, your own integration). Send `X-API-Key: pk_live_…`. Make keys in
    **Shop Settings → API & Webhooks**. *Read Only* keys read jobs, quotes, customers, files, products and
    inventory; *Read & Write* keys can also create and change them and manage webhooks; AI keys add `use:ai`.
    Keep keys on your server, never in a web page or an app customers download.

    **OAuth 2.0** (an app that many shops connect). Authorization code with PKCE (`S256` only):
    1. Send the shop owner to `https://app.printcore.ai/oauth/authorize` with `response_type=code`, your
       `client_id`, an exact registered `redirect_uri`, the `scope`s you need (space-separated), a `state`,
       and `code_challenge` + `code_challenge_method=S256`.
    2. They sign in and choose **Allow** (shop admins and owners on Pro, Studio or Enterprise only). The browser
       comes back to `redirect_uri?code=…&state=…`. The code works once, for 10 minutes.
    3. `POST https://app.printcore.ai/oauth/token` with `grant_type=authorization_code`, the `code`,
       `redirect_uri` and `code_verifier`, authenticating with your client id and secret.
    4. Call the API with `Authorization: Bearer pca_…`. Access tokens last 1 hour. Get a new one with
       `grant_type=refresh_token`; refresh tokens (`pcr_…`) last 90 days and are replaced on every use.
       Sending an old refresh token again disconnects the app.

    The shop can disconnect your app any time in **Settings → Integrations → Connected apps**; its tokens and
    webhook subscriptions stop at once. Server metadata: `https://app.printcore.ai/.well-known/oauth-authorization-server`.

    | Scope | Lets the app |
    |---|---|
    | `read:jobs` | See jobs, job files and production steps |
    | `write:jobs` | Create and update jobs and attach files |
    | `read:quotes` | See quotes |
    | `write:quotes` | Create quotes |
    | `read:customers` | See customers and their contacts |
    | `write:customers` | Add customers |
    | `read:inventory` | See materials and stock levels |
    | `read:products` | See products and the price list |
    | `write:products` | Add and update products |
    | `manage:webhooks` | Subscribe to events (each event also needs its read scope) |
    | `write:actuals` | Record production times and material used (the **Production connector** key type) |

    `use:ai` is never offered to OAuth apps, because AI calls use the shop's own credits.

    Errors: a bad, expired or revoked token gets `401` with `code: INVALID_TOKEN`; a missing scope gets `403`
    with `code: INSUFFICIENT_SCOPE` and `requiredScope`; a shop whose plan doesn't include the API gets `403`
    with `code: FEATURE_NOT_IN_PLAN`.

    ## Requests and responses
    - Send JSON with `Content-Type: application/json`. Successful responses wrap the result in `data`.
    - Dates are ISO 8601 strings. Due dates are plain `YYYY-MM-DD`. Money is in the shop's own currency.
    - Errors return a status code and `{ "error": "message", "code": "OPTIONAL_CODE" }`. The message says what to fix.
    - A key or token only ever sees its own shop. Anything from another shop answers `404`.

    ## Paging
    List endpoints return up to `limit` records (default 25, max 100) and a `pagination` object. When
    `hasMore` is true, pass `nextCursor` as `cursor` to get the next page.

    ## Limits
    | What | Limit |
    |---|---|
    | Requests per key or connected app | 60 per minute (`429` above that) |
    | AI requests (`/v1/ai/*`) | 20 per minute |
    | Records per list page | 100 |
    | Line items per job | 50 |
    | File links per request | 20 |
    | Upload size | 2 GB per file |
    | Products per sync | 100 |
    | Webhooks per shop | 50 |
  contact:
    name: Printcore developer help
    email: help@printcore.ai
    url: https://printcore.ai/developers/
  termsOfService: https://printcore.ai/terms.html
  license:
    name: Proprietary — for use with Printcore accounts
    url: https://printcore.ai/terms.html
servers:
  - url: https://us-central1-quickbooks-app-c5298.cloudfunctions.net/api
    description: Production
security:
  - apiKey: []
  - oauth2: []
tags:
  - name: Shop
    description: The shop a key or token belongs to.
  - name: Jobs
    description: A job is an order moving through the shop. Status runs Quote → Approved → Prepress → Production → Finishing → Shipping → Invoice/Complete.
  - name: Quotes
    description: A quote is a job with status `Quote`, waiting for the shop to review and send it.
  - name: Customers
    description: The shop's customers. Link jobs to a customer with `customerId` so orders show in that customer's portal.
  - name: Job files
    description: Artwork, proofs and print-ready files on a job. Attach links you host, or upload files (up to 2 GB) straight to Printcore.
  - name: Products
    description: Keep one master price list and send it to Printcore, matched by your own SKU, so quotes match your website.
  - name: Inventory
    description: The shop's materials and stock levels.
  - name: Production actuals
    description: |
      What a RIP, cutter or printer actually did: run time, media and ink. A connector on the shop's PC (or a cloud
      integration) sends one report per machine job. Printcore reads the job number from the RIP/cutter job name
      (`1045_banner.pdf`, `#1045`, `J1045`) and adds the report to that job's matching step. Reports it can't place
      go to the shop's Unmatched inbox. Media and ink are recorded as reported; nothing is priced from them.
  - name: Webhooks
    description: |
      Subscribe to events (REST hooks). Each subscription gets a signing secret, shown once.
      Every delivery is a JSON `POST` signed with HMAC-SHA256 of the exact body in `X-Printcore-Signature`.
      The payload's `id` is the same on every retry, so a receiver can ignore repeats. Reply with any 2xx within
      10 seconds. A failed delivery is retried after 1 min, 5 min, 30 min, 2 h, 6 h and 12 h (7 tries, about 21 hours).
      After 10 events in a row fail, the subscription is switched off. Disconnecting an app or revoking a key
      switches off the subscriptions it made.

      Check the signature over the raw body, before parsing it:

      ```js
      // Express: app.post('/printcore', express.raw({ type: 'application/json' }), handler)
      const expected = crypto.createHmac('sha256', process.env.PRINTCORE_WEBHOOK_SECRET)
        .update(req.body)                        // the raw bytes, exactly as sent
        .digest('hex');
      const given = req.get('X-Printcore-Signature') || '';
      const ok = given.length === expected.length &&
        crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
      if (!ok) return res.status(401).send('Bad signature');
      const event = JSON.parse(req.body);        // event.id, event.type, event.data
      ```
  - name: AI
    description: AI helpers. They use the shop's AI credits, so they need the `use:ai` permission, which is only on shop-made API keys (never offered to OAuth apps).
  - name: OAuth
    description: The OAuth 2.0 endpoints, served from `https://app.printcore.ai`. See [Authentication](#section/authentication).

paths:
  /v1/me:
    get:
      tags: [Shop]
      operationId: getMe
      summary: Who am I connected to?
      description: The shop this key or token belongs to. Needs no extra permission, so it is a good first call to check a connection.
      x-scopes: []
      security: [{ apiKey: [] }, { oauth2: [] }]
      responses:
        '200':
          description: The shop.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      shopId: { type: string }
                      shopName: { type: string }
                      authType: { type: string, enum: [api_key, oauth] }
                      app: { type: [string, 'null'], description: 'The connected app, for OAuth tokens.' }
                      scopes: { type: array, items: { type: string } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }

  # ── Jobs ──────────────────────────────────────────────────────────────────
  /v1/jobs:
    get:
      tags: [Jobs]
      operationId: listJobs
      summary: List jobs
      description: Newest first.
      x-scopes: [read:jobs]
      security: [{ apiKey: [] }, { oauth2: [read:jobs] }]
      parameters:
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
        - name: status
          in: query
          description: Only jobs with this status, for example `Production`.
          schema: { $ref: '#/components/schemas/JobStatus' }
      responses:
        '200':
          description: A page of jobs.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: '#/components/schemas/Job' } }
                  pagination: { $ref: '#/components/schemas/Pagination' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '429': { $ref: '#/components/responses/TooManyRequests' }
    post:
      tags: [Jobs]
      operationId: createJob
      summary: Create a job
      description: Creates a job and gives it the shop's next job number. Prices you send are stored as given.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/JobCreate' }
            example:
              projectName: Trade Show Banner
              customerId: cus_8f2k
              status: Approved
              dueDate: '2026-12-12'
              lineItems:
                - description: 4x8 Banner
                  quantity: 2
                  unitPrice: 85
                  material: 13oz Vinyl
                  specifications: [{ label: Finishing, value: Hem & grommets }]
      responses:
        '201':
          description: The new job.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Job' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/jobs/{id}:
    parameters:
      - $ref: '#/components/parameters/id'
    get:
      tags: [Jobs]
      operationId: getJob
      summary: Get a job
      description: One job with its line items.
      x-scopes: [read:jobs]
      security: [{ apiKey: [] }, { oauth2: [read:jobs] }]
      responses:
        '200':
          description: The job.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Job' } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
    patch:
      tags: [Jobs]
      operationId: updateJob
      summary: Update a job
      description: Only the fields you send change.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              minProperties: 1
              properties:
                projectName: { type: string, maxLength: 200 }
                customerName: { type: string }
                customerId: { type: [string, 'null'], description: 'A Printcore customer id, or null to unlink.' }
                status: { $ref: '#/components/schemas/JobStatus' }
                dueDate: { type: [string, 'null'], format: date }
                notes: { type: string, maxLength: 5000 }
      responses:
        '200':
          description: The fields that changed.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: object, properties: { id: { type: string } }, additionalProperties: true } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }

  # ── Job files ─────────────────────────────────────────────────────────────
  /v1/jobs/{id}/files:
    parameters:
      - $ref: '#/components/parameters/id'
    get:
      tags: [Job files]
      operationId: listJobFiles
      summary: List a job's files
      description: Every file on the job, each with a working link. `stored` is true when Printcore holds the file, false for a link to somewhere else.
      x-scopes: [read:jobs]
      security: [{ apiKey: [] }, { oauth2: [read:jobs] }]
      responses:
        '200':
          description: The job's files.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/JobFile' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
    post:
      tags: [Job files]
      operationId: attachJobFileLinks
      summary: Attach file links
      description: Attach links to files you host. The link must stay reachable. Up to 20 per request; links already on the job are skipped.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/FileLink'
                - type: object
                  required: [files]
                  properties:
                    files: { type: array, maxItems: 20, items: { $ref: '#/components/schemas/FileLink' } }
            example:
              files: [{ url: 'https://files.example.com/proof-v2.pdf', name: Proof v2.pdf }]
      responses:
        '201':
          description: What was added.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      added: { type: array, items: { $ref: '#/components/schemas/JobFile' } }
                      skipped: { type: integer, description: Links that were already on the job. }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /v1/jobs/{id}/files/uploads:
    parameters:
      - $ref: '#/components/parameters/id'
    post:
      tags: [Job files]
      operationId: startJobFileUpload
      summary: Start an upload
      description: |
        Step 1 of 3. You get an `uploadUrl` that is valid for 15 minutes.
        Step 2: send the file's bytes to `uploadUrl` with the given `method` and `headers` (no API key on that request).
        Step 3: call `complete`. Accepted types include PDF, AI, EPS, SVG, PNG, JPG, TIFF, PSD, INDD, CDR, DXF, ZIP and Office files.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, size, contentType]
              properties:
                name: { type: string, example: Banner print-ready.pdf }
                size: { type: integer, description: 'Size in bytes, up to 2 GB.' }
                contentType: { type: string, example: application/pdf }
      responses:
        '201':
          description: Where to send the file.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      uploadId: { type: string }
                      uploadUrl: { type: string, format: uri }
                      method: { type: string, example: PUT }
                      headers: { type: object, additionalProperties: { type: string } }
                      expiresAt: { type: string, format: date-time }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/jobs/{id}/files/uploads/{uploadId}/complete:
    parameters:
      - $ref: '#/components/parameters/id'
      - name: uploadId
        in: path
        required: true
        schema: { type: string }
    post:
      tags: [Job files]
      operationId: completeJobFileUpload
      summary: Finish an upload
      description: Printcore checks the file and adds it to the job. Calling it again is safe and returns the same file.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      responses:
        '201':
          description: The file on the job.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: object, properties: { file: { $ref: '#/components/schemas/JobFile' } } } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }

  # ── Quotes ────────────────────────────────────────────────────────────────
  /v1/quotes:
    post:
      tags: [Quotes]
      operationId: createQuote
      summary: Create a quote
      description: |
        Creates a job in Quote status for the shop to review and send. Nothing is sent to the customer.

        **Lines are priced by the shop's own Quote Builder calculators**, the same as `POST /v1/estimate`. Describe each
        line (`type`, `material`, size in inches, `quantity`, `sides`, `finishing`). Any price you send is ignored, and
        the reply's `warnings` says so.

        A line the calculators can't price is saved at $0, with `needsPricing: true` and a "Needs pricing"
        specification naming what's missing. The quote then gets `pricingStatus: needs_review`, for the shop to finish
        in the app. To price lines without creating anything, use `POST /v1/estimate`.

        Changed 2026-11-28: before, quote lines used the caller's `unitPrice`. `POST /v1/jobs` still does.
      x-scopes: [write:quotes]
      security: [{ apiKey: [] }, { oauth2: [write:quotes] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/QuoteCreate' }
            example:
              projectName: Open house yard signs
              customerId: cus_123
              lineItems:
                - { description: 18x24 yard signs, type: wide, material: 4mm Coroplast, width: 18, height: 24, quantity: 50, sides: double }
      responses:
        '201':
          description: The new quote, with its calculator pricing.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { $ref: '#/components/schemas/Job' }
                  pricing:
                    type: object
                    properties:
                      source: { type: string, const: calculator }
                      currency: { type: string }
                      subtotal: { type: number }
                      linesNeedingPricing: { type: integer }
                  warnings: { type: array, items: { type: string } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '503': { $ref: '#/components/responses/PricingUnavailable' }

  /v1/quote-requests:
    post:
      tags: [Quotes]
      operationId: createQuoteRequest
      summary: Send a quote request
      description: |
        Puts a customer's request in the shop's **AI Quote inbox**, exactly like a forwarded email. The shop's team
        reviews it there, and the AI Quote wizard prices it with the shop's own calculators before anything is sent
        to the customer. You never set prices here. The shop is notified as usual.

        Send `externalId` (your own id for the request, such as a form response id) to make retries safe: a second
        call with the same `externalId` returns the first request with `200` and `duplicate: true`.
      x-scopes: [write:quotes]
      security: [{ apiKey: [] }, { oauth2: [write:quotes] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/QuoteRequestCreate' }
            example:
              customer: { name: Jordan Blake, email: jordan@example.com, company: Acme Outdoor Events }
              projectName: Festival banners
              description: Two vinyl banners for the festival entrance, full color one side.
              quantity: '2'
              size: 3 x 8 ft
              material: 13oz vinyl
              dueDate: '2026-12-12'
              fileUrls: ['https://files.example.com/festival-logo.pdf']
              externalId: form-response-8812
      responses:
        '201':
          description: The request is in the inbox.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/QuoteRequest' } } }
        '200':
          description: Already received (same `externalId`); the first request is returned.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { $ref: '#/components/schemas/QuoteRequest' }
                  duplicate: { type: boolean, const: true }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/estimate:
    post:
      tags: [Quotes]
      operationId: estimate
      summary: Price lines with the shop's calculators
      description: |
        Prices line items with the shop's **own Quote Builder calculators**: its inventory, pricing settings, product
        presets, equipment, finishing templates and specialty rate cards (wraps, channel letters, cut vinyl,
        booklets). The answer matches the AI Quote wizard's estimate for the same lines.

        You describe the work; the shop's calculators set the price. Any price you send is ignored. Only sell prices
        come back, never the shop's costs or margins. Nothing is saved: this is an estimate, not a quote.

        A line that can't be priced comes back with `priced: false` and a short `reason` (for example
        `needs material` or `needs size`), so you can ask for the missing detail and try again. Up to 50 lines.

        **Apparel & promo** (`type: apparel`, for shops that switched it on): name the item from the shop's catalog by
        `productId` or `style` (a style number or name such as `Gildan 5000` or `hoodie`), plus `color`, `sizes`
        (or a total `quantity`) and `decoration`. All apparel lines in one request are priced together, so a print
        shared across garments prices at the combined quantity with one setup, the same as in the app. What the price
        assumed (for example a total with no size breakdown) comes back in `assumptions`.
      x-scopes: [read:quotes, write:quotes]
      security: [{ apiKey: [] }, { oauth2: [read:quotes] }, { oauth2: [write:quotes] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/EstimateRequest' }
            example:
              items:
                - { description: 18x24 yard signs, type: wide, material: Coroplast White, thickness: 4mm, width: 18, height: 24, quantity: 50, sides: double, finishing: [shape cut] }
                - { description: Postcards, type: digital, material: 14pt Gloss Cover, width: 4, height: 6, quantity: 500, sides: double }
                - { description: Storefront letters, type: channel_letter, quantity: 1, details: { letterText: OPEN, letterHeight: 12, illumination: non_lit } }
                - { description: Staff tees, type: apparel, style: Gildan 5000, color: black, sizes: { M: 12, L: 12, XL: 6 }, decoration: { method: screen, location: full front, colors: 2 } }
      responses:
        '200':
          description: The estimate.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Estimate' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '503': { $ref: '#/components/responses/PricingUnavailable' }
  /v1/actuals:
    post:
      tags: [Production actuals]
      operationId: recordActuals
      summary: Report what a machine did
      description: |
        Send one machine report, or up to 50 as `{ "actuals": [...] }`. Printcore matches each to a job from the
        job number in `jobName` (or `jobNumber`, if you know it) and to the job's step for that `operation`
        (print, cut, laminate, mount). If it can't tell which job, the report waits in the shop's Unmatched inbox.

        Give every report an `externalId` (the RIP's own job id): sending the same report again then does nothing
        and answers `200` with `duplicate: true`, so a connector can safely retry. A batch is checked first and saved
        whole or not at all. Shops with in-house production only.
      x-scopes: [write:actuals]
      security: [{ apiKey: [] }, { oauth2: [write:actuals] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/ActualRequest'
                - type: object
                  required: [actuals]
                  properties:
                    actuals: { type: array, minItems: 1, maxItems: 50, items: { $ref: '#/components/schemas/ActualRequest' } }
            example:
              source: onyx
              externalId: 'onyx-88412'
              deviceId: HP Latex 3100
              operation: print
              jobName: 1045_banner_36x72.pdf
              startedAt: '2026-12-01T14:02:10Z'
              endedAt: '2026-12-01T14:19:40Z'
              mediaUsed: { value: 18.4, unit: sqft }
              inkUsed: [{ color: cyan, ml: 6.2 }, { color: magenta, ml: 5.8 }, { color: yellow, ml: 4.1 }, { color: black, ml: 3.9 }]
      responses:
        '200':
          description: Already received (`duplicate` is true), or a batch — one result per report, in order, plus a summary.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - $ref: '#/components/schemas/ActualResult'
                      - { type: array, items: { $ref: '#/components/schemas/ActualResult' } }
                  summary:
                    type: object
                    properties:
                      received: { type: integer }
                      duplicates: { type: integer }
                      matched: { type: integer, description: New reports placed on a job (duplicates not counted again). }
                      unmatched: { type: integer, description: New reports waiting in the Unmatched inbox. }
        '201':
          description: Saved.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/ActualResult' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/jobs/{id}/actuals:
    parameters:
      - $ref: '#/components/parameters/id'
    post:
      tags: [Production actuals]
      operationId: recordJobActuals
      summary: Report what a machine did on a known job
      description: Same as `POST /v1/actuals`, for a job you already know (the job's `id`). The job number in the name is not needed.
      x-scopes: [write:actuals]
      security: [{ apiKey: [] }, { oauth2: [write:actuals] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ActualRequest' }
            example: { source: icut, externalId: 'ipc-2291', deviceId: Kongsberg C60, operation: cut, startedAt: '2026-12-01T15:00:00Z', endedAt: '2026-12-01T15:06:30Z', cutLengthM: 42.5 }
      responses:
        '200':
          description: Already received (`duplicate` is true).
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/ActualResult' } } }
        '201':
          description: Saved.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/ActualResult' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/jobs/{id}/notes:
    parameters:
      - $ref: '#/components/parameters/id'
    post:
      tags: [Jobs]
      operationId: addJobNote
      summary: Add a note to a job
      description: An internal note, shown to the shop's team in the job's notes (never to the customer), signed with your app's name.
      x-scopes: [write:jobs]
      security: [{ apiKey: [] }, { oauth2: [write:jobs] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [body]
              properties:
                body: { type: string, maxLength: 5000, description: The note text. }
            example: { body: 'Customer called: they want the banners by Thursday if possible.' }
      responses:
        '201':
          description: The note.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      id: { type: string }
                      jobId: { type: string }
                      jobNumber: { type: [string, integer, 'null'] }
                      authorName: { type: string }
                      body: { type: string }
                      createdAt: { type: string, format: date-time }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }

  # ── Customers ─────────────────────────────────────────────────────────────
  /v1/customers:
    get:
      tags: [Customers]
      operationId: listCustomers
      summary: List or find customers
      description: With `email`, returns the customers whose email (or one of whose contacts' email) matches, ignoring case. Otherwise a page of customers.
      x-scopes: [read:customers]
      security: [{ apiKey: [] }, { oauth2: [read:customers] }]
      parameters:
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
        - name: email
          in: query
          description: Find by email address.
          schema: { type: string, format: email }
      responses:
        '200':
          description: A page of customers.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: '#/components/schemas/Customer' } }
                  pagination: { $ref: '#/components/schemas/Pagination' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
    post:
      tags: [Customers]
      operationId: createCustomer
      summary: Create a customer
      description: Create the customer first, then pass its id as `customerId` when you create jobs, so their orders show in their portal.
      x-scopes: [write:customers]
      security: [{ apiKey: [] }, { oauth2: [write:customers] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/CustomerCreate' }
      responses:
        '201':
          description: The new customer.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Customer' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/customers/{id}:
    parameters:
      - $ref: '#/components/parameters/id'
    get:
      tags: [Customers]
      operationId: getCustomer
      summary: Get a customer
      x-scopes: [read:customers]
      security: [{ apiKey: [] }, { oauth2: [read:customers] }]
      responses:
        '200':
          description: The customer.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Customer' } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }

  # ── Inventory ─────────────────────────────────────────────────────────────
  /v1/inventory:
    get:
      tags: [Inventory]
      operationId: listInventory
      summary: List inventory
      description: The shop's materials and stock.
      x-scopes: [read:inventory]
      security: [{ apiKey: [] }, { oauth2: [read:inventory] }]
      parameters:
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses:
        '200':
          description: A page of inventory items.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: '#/components/schemas/InventoryItem' } }
                  pagination: { $ref: '#/components/schemas/Pagination' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }

  # ── Products ──────────────────────────────────────────────────────────────
  /v1/categories:
    get:
      tags: [Products]
      operationId: listCategories
      summary: List product categories
      description: Category names to use in a product's `category`, such as Wide Format or Digital Press. Needs `read:products` or `read:inventory`.
      x-scopes: [read:products, read:inventory]
      security: [{ apiKey: [] }, { oauth2: [read:products] }, { oauth2: [read:inventory] }]
      responses:
        '200':
          description: The categories.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: array, items: { type: object, additionalProperties: true } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/products:
    get:
      tags: [Products]
      operationId: listProducts
      summary: List products
      description: Needs `read:products` or `read:inventory`.
      x-scopes: [read:products, read:inventory]
      security: [{ apiKey: [] }, { oauth2: [read:products] }, { oauth2: [read:inventory] }]
      parameters:
        - name: sku
          in: query
          schema: { type: string }
        - name: active
          in: query
          schema: { type: string, enum: ['true', 'false'] }
      responses:
        '200':
          description: The products.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/Product' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/products/{id}:
    parameters:
      - $ref: '#/components/parameters/id'
    get:
      tags: [Products]
      operationId: getProduct
      summary: Get a product
      x-scopes: [read:products, read:inventory]
      security: [{ apiKey: [] }, { oauth2: [read:products] }, { oauth2: [read:inventory] }]
      responses:
        '200':
          description: The product.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/Product' } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
    patch:
      tags: [Products]
      operationId: updateProduct
      summary: Update a product by id
      description: 'Use this to give products built in Printcore your SKUs: `{ "sku": "BC-STD" }`.'
      x-scopes: [write:products]
      security: [{ apiKey: [] }, { oauth2: [write:products] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ProductInput' }
      responses:
        '200':
          description: The result for this product.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/ProductSyncResult' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/products/sku/{sku}:
    parameters:
      - name: sku
        in: path
        required: true
        schema: { type: string }
    put:
      tags: [Products]
      operationId: upsertProductBySku
      summary: Create or update a product by SKU
      description: Same fields as a sync row. A `sku` in the body must match the one in the URL.
      x-scopes: [write:products]
      security: [{ apiKey: [] }, { oauth2: [write:products] }]
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ProductInput' }
      responses:
        '200':
          description: The result for this product.
          content:
            application/json:
              schema: { type: object, properties: { data: { $ref: '#/components/schemas/ProductSyncResult' } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /v1/products/sync:
    post:
      tags: [Products]
      operationId: syncProducts
      summary: Sync many products
      description: |
        Create and update up to 100 products in one request. Start with `"dryRun": true` to see what would change;
        nothing is saved until you send it without `dryRun`. New products need `sku`, `name`, `category` and `price`.
        `"deactivateMissing": true` switches off API-managed products missing from your list (never deletes them).
      x-scopes: [write:products]
      security: [{ apiKey: [] }, { oauth2: [write:products] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [products]
              properties:
                dryRun: { type: boolean, default: false }
                deactivateMissing: { type: boolean, default: false }
                products: { type: array, maxItems: 100, items: { $ref: '#/components/schemas/ProductInput' } }
      responses:
        '200':
          description: What changed (or would change, on a dry run).
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      dryRun: { type: boolean }
                      summary: { type: object, additionalProperties: { type: integer } }
                      results: { type: array, items: { $ref: '#/components/schemas/ProductSyncResult' } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }

  # ── Webhooks (REST hooks) ─────────────────────────────────────────────────
  /v1/webhooks:
    get:
      tags: [Webhooks]
      operationId: listWebhooks
      summary: List your subscriptions
      description: Only the subscriptions this key or app made. The secret is never returned.
      x-scopes: [manage:webhooks]
      security: [{ apiKey: [] }, { oauth2: [manage:webhooks] }]
      responses:
        '200':
          description: The subscriptions.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: '#/components/schemas/WebhookSubscription' } }
                  availableEvents: { type: array, items: { $ref: '#/components/schemas/EventType' } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
    post:
      tags: [Webhooks]
      operationId: subscribeWebhook
      summary: Subscribe to events
      description: |
        Each event also needs the permission that reads what it carries: `quote.*` and `quote_request.*` need `read:quotes`;
        `job.*`, `proof.*`, `order.*`, `payment.*` and `shipment.*` need `read:jobs`; `customer.*` needs
        `read:customers`; `inventory.*` needs `read:inventory`. The URL must be public `https`.
        Several subscriptions to the same event can exist side by side.
      x-scopes: [manage:webhooks]
      security: [{ apiKey: [] }, { oauth2: [manage:webhooks] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: Send `url` + `events`, or Zapier's `target_url` + `event`.
              properties:
                url: { type: string, format: uri }
                target_url: { type: string, format: uri }
                events: { type: array, minItems: 1, items: { $ref: '#/components/schemas/EventType' } }
                event: { $ref: '#/components/schemas/EventType' }
                description: { type: string, maxLength: 500 }
            example: { url: 'https://hooks.example.com/printcore', events: [quote.created, payment.received] }
      responses:
        '201':
          description: The subscription and its signing secret (shown once).
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/WebhookSubscription'
                  - type: object
                    properties:
                      secret: { type: string, example: whsec_3f9a… }
                      message: { type: string }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
  /v1/webhooks/{id}:
    parameters:
      - $ref: '#/components/parameters/id'
    delete:
      tags: [Webhooks]
      operationId: unsubscribeWebhook
      summary: Unsubscribe
      description: Only a subscription this key or app made can be deleted; anything else answers 404.
      x-scopes: [manage:webhooks]
      security: [{ apiKey: [] }, { oauth2: [manage:webhooks] }]
      responses:
        '200':
          description: Deleted.
          content:
            application/json:
              schema: { type: object, properties: { success: { type: boolean }, id: { type: string } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/webhooks/samples/{event}:
    parameters:
      - name: event
        in: path
        required: true
        schema: { $ref: '#/components/schemas/EventType' }
    get:
      tags: [Webhooks]
      operationId: webhookSamples
      summary: Sample events
      description: |
        The shop's latest 3 real records, built exactly like a live delivery (ids start `evt_sample_`). When the
        shop has none yet, one placeholder marked `sample: true`. Also needs the event's read permission.
      x-scopes: [manage:webhooks]
      security: [{ apiKey: [] }, { oauth2: [manage:webhooks] }]
      responses:
        '200':
          description: Sample events.
          content:
            application/json:
              schema: { type: object, properties: { data: { type: array, items: { $ref: '#/components/schemas/WebhookEvent' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }

  # ── AI ────────────────────────────────────────────────────────────────────
  /v1/ai/parse-email:
    post:
      tags: [AI]
      operationId: aiParseEmail
      summary: Read a customer email into quote fields
      description: Turns a customer's email into customer, project and line-item fields. It does not price anything.
      x-scopes: [use:ai]
      security: [{ apiKey: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [emailText]
              properties:
                emailText: { type: string, maxLength: 50000 }
                emailSubject: { type: string, maxLength: 500 }
      responses:
        '200':
          description: The fields found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      customer: { type: object, additionalProperties: true }
                      project: { type: object, additionalProperties: true }
                      lineItems: { type: array, items: { type: object, additionalProperties: true } }
                      parseConfidence: { type: integer, minimum: 0, maximum: 100 }
                      metadata: { type: object, additionalProperties: true }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '429': { $ref: '#/components/responses/TooManyRequests' }
  /v1/ai/chat:
    post:
      tags: [AI]
      operationId: aiChat
      summary: Ask the AI model
      x-scopes: [use:ai]
      security: [{ apiKey: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [messages]
              properties:
                messages:
                  type: array
                  description: Up to 100,000 characters in total.
                  items:
                    type: object
                    required: [role, content]
                    properties:
                      role: { type: string, enum: [user, assistant] }
                      content: { type: string }
                system: { type: string, maxLength: 5000 }
                max_tokens: { type: integer, minimum: 1, maximum: 4096, default: 1500 }
                model: { type: string, description: Optional. Only the allowed fast model is accepted. }
      responses:
        '200':
          description: The model's reply.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      content: { type: array, items: { type: object, additionalProperties: true } }
                      model: { type: string }
                      usage: { type: object, additionalProperties: true }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '429': { $ref: '#/components/responses/TooManyRequests' }
  /v1/ai/proof-check:
    post:
      tags: [AI]
      operationId: aiProofCheck
      summary: Check artwork files against the job
      description: Up to 10 files. Send each as `base64`, or point to a file already in Printcore with `url` or `storagePath`.
      x-scopes: [use:ai]
      security: [{ apiKey: [] }]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [jobId, files]
              properties:
                jobId: { type: string }
                files:
                  type: array
                  minItems: 1
                  maxItems: 10
                  items:
                    type: object
                    properties:
                      name: { type: string }
                      type: { type: string }
                      base64: { type: string }
                      url: { type: string }
                      storagePath: { type: string }
                jobSpecs:
                  type: object
                  properties:
                    width: { type: number }
                    height: { type: number }
                    material: { type: string }
                    quantity: { type: number }
      responses:
        '200':
          description: The findings.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      results:
                        type: array
                        items:
                          type: object
                          properties:
                            severity: { type: string, enum: [error, warning, info, pass] }
                            category: { type: string }
                            message: { type: string }
                          additionalProperties: true
                      checkedAt: { type: string, format: date-time }
                      filesAnalyzed: { type: integer }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/TooManyRequests' }
  /v1/ai/pricing-analysis:
    get:
      tags: [AI]
      operationId: aiPricingAnalysis
      summary: Analyze the shop's pricing history
      x-scopes: [use:ai]
      security: [{ apiKey: [] }]
      parameters:
        - name: siteId
          in: query
          description: Only this location, for shops with several.
          schema: { type: string }
      responses:
        '200':
          description: Pricing patterns by product.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      confidence: { type: number }
                      productPricing: { type: array, items: { type: object, additionalProperties: true } }
                      metadata: { type: object, additionalProperties: true }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '429': { $ref: '#/components/responses/TooManyRequests' }

  # ── OAuth (served from app.printcore.ai) ──────────────────────────────────
  /.well-known/oauth-authorization-server:
    servers: [{ url: 'https://app.printcore.ai' }]
    get:
      tags: [OAuth]
      operationId: oauthMetadata
      summary: Authorization server metadata (RFC 8414)
      security: []
      responses:
        '200':
          description: Endpoints, supported grants and scopes.
          content:
            application/json:
              schema: { type: object, additionalProperties: true }
  /oauth/authorize:
    servers: [{ url: 'https://app.printcore.ai' }]
    get:
      tags: [OAuth]
      operationId: oauthAuthorize
      summary: Ask a shop to connect your app
      description: |
        Send the shop owner's browser here. They sign in, see your app's name and the permissions you asked for,
        and choose Allow or Deny. Only a shop admin or owner on a Pro, Studio or Enterprise plan can allow.
        On Allow, the browser returns to `redirect_uri?code=…&state=…&iss=https://app.printcore.ai`; on Deny, with
        `error=access_denied`. Every response carries `iss` (RFC 9207).

        Tokens are for one service (RFC 8707). Leave out `resource` (or send `https://app.printcore.ai`) for this
        REST API. AI assistants send `resource=https://mcp.printcore.ai/mcp` to get a token for Printcore's MCP server,
        and those tokens don't work on `/v1`. AI assistants may use a client metadata document URL as `client_id`
        (Claude and ChatGPT do).
      security: []
      parameters:
        - { name: response_type, in: query, required: true, schema: { type: string, enum: [code] } }
        - { name: client_id, in: query, required: true, schema: { type: string } }
        - { name: redirect_uri, in: query, required: true, description: Must exactly match a registered URI., schema: { type: string, format: uri } }
        - { name: scope, in: query, required: true, description: 'Space-separated, e.g. `read:jobs manage:webhooks`.', schema: { type: string } }
        - { name: state, in: query, required: true, schema: { type: string } }
        - { name: code_challenge, in: query, required: true, description: 'BASE64URL(SHA256(code_verifier)).', schema: { type: string } }
        - { name: code_challenge_method, in: query, required: true, schema: { type: string, enum: [S256] } }
        - { name: resource, in: query, required: false, description: 'Which Printcore service the token is for (RFC 8707). Omit for the REST API; `https://mcp.printcore.ai/mcp` for the MCP server.', schema: { type: string, format: uri } }
      responses:
        '302':
          description: To the consent page.
  /oauth/token:
    servers: [{ url: 'https://app.printcore.ai' }]
    post:
      tags: [OAuth]
      operationId: oauthToken
      summary: Get or refresh tokens
      description: |
        Exchange the code (with the PKCE `code_verifier`), or a refresh token. Access tokens (`pca_…`) last 1 hour;
        refresh tokens (`pcr_…`) last 90 days and are replaced on every use. Using an old refresh token again
        disconnects the app. Authenticate with HTTP Basic (client id + secret) or `client_id`/`client_secret` in the
        form; public clients send only `client_id`.
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required: [grant_type]
              properties:
                grant_type: { type: string, enum: [authorization_code, refresh_token] }
                code: { type: string }
                redirect_uri: { type: string }
                code_verifier: { type: string }
                resource: { type: string, description: 'If sent, must name the same service as the authorization request (else `invalid_target`).' }
                refresh_token: { type: string }
                scope: { type: string, description: 'On refresh, ask for fewer scopes (never more).' }
                client_id: { type: string }
                client_secret: { type: string }
      responses:
        '200':
          description: Tokens.
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token: { type: string, example: pca_… }
                  token_type: { type: string, enum: [Bearer] }
                  expires_in: { type: integer, example: 3600 }
                  refresh_token: { type: string, example: pcr_… }
                  scope: { type: string }
        '400':
          description: '`invalid_grant`, `invalid_request`, `invalid_scope` or `unsupported_grant_type`.'
          content:
            application/json:
              schema: { $ref: '#/components/schemas/OAuthError' }
        '401':
          description: '`invalid_client`.'
          content:
            application/json:
              schema: { $ref: '#/components/schemas/OAuthError' }
  /oauth/revoke:
    servers: [{ url: 'https://app.printcore.ai' }]
    post:
      tags: [OAuth]
      operationId: oauthRevoke
      summary: Revoke a token (RFC 7009)
      description: Revoking a refresh token disconnects the app from the shop.
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required: [token]
              properties:
                token: { type: string }
                token_type_hint: { type: string, enum: [access_token, refresh_token] }
                client_id: { type: string }
                client_secret: { type: string }
      responses:
        '200': { description: Done (also when the token was already invalid). }
        '401':
          description: '`invalid_client`.'
          content:
            application/json:
              schema: { $ref: '#/components/schemas/OAuthError' }

# ── Webhook deliveries (what Printcore sends to you) ─────────────────────────
webhooks:
  quote_request.received:
    post:
      operationId: quoteRequestReceivedEvent
      summary: quote_request.received
      description: 'A quote request landed in the AI Quote inbox (email, voice call, customer portal, Quote Assistant or the API). Spam and empty calls are never sent.'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: quote_request.received }
                    data: { $ref: '#/components/schemas/QuoteRequestEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  quote.created:
    post:
      operationId: quoteCreatedEvent
      summary: quote.created
      description: 'A quote was created'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: quote.created }
                    data: { $ref: '#/components/schemas/QuoteEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  quote.sent:
    post:
      operationId: quoteSentEvent
      summary: quote.sent
      description: 'A quote was emailed to the customer (every send)'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: quote.sent }
                    data: { $ref: '#/components/schemas/QuoteEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  quote.viewed:
    post:
      operationId: quoteViewedEvent
      summary: quote.viewed
      description: 'The customer opened a quote for the first time'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: quote.viewed }
                    data: { $ref: '#/components/schemas/QuoteEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  quote.approved:
    post:
      operationId: quoteApprovedEvent
      summary: quote.approved
      description: 'A quote was approved'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: quote.approved }
                    data: { $ref: '#/components/schemas/QuoteEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.created:
    post:
      operationId: jobCreatedEvent
      summary: job.created
      description: 'A job was created'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.created }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.updated:
    post:
      operationId: jobUpdatedEvent
      summary: job.updated
      description: 'A job''s details changed'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.updated }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.status_changed:
    post:
      operationId: jobStatusChangedEvent
      summary: job.status_changed
      description: 'A job moved to a new status'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.status_changed }
                    data: { $ref: '#/components/schemas/JobStatusEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.step_started:
    post:
      operationId: jobStepStartedEvent
      summary: job.step_started
      description: 'A production step started (resuming a paused step does not count)'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.step_started }
                    data: { $ref: '#/components/schemas/StepEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.step_completed:
    post:
      operationId: jobStepCompletedEvent
      summary: job.step_completed
      description: 'A production step was completed'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.step_completed }
                    data: { $ref: '#/components/schemas/StepEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  job.deleted:
    post:
      operationId: jobDeletedEvent
      summary: job.deleted
      description: 'A job was deleted'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: job.deleted }
                    data: { $ref: '#/components/schemas/JobDeletedEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  proof.approved:
    post:
      operationId: proofApprovedEvent
      summary: proof.approved
      description: 'The customer approved a proof'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: proof.approved }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  proof.revision_requested:
    post:
      operationId: proofRevisionRequestedEvent
      summary: proof.revision_requested
      description: 'The customer asked for changes to a proof'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: proof.revision_requested }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  payment.received:
    post:
      operationId: paymentReceivedEvent
      summary: payment.received
      description: 'A payment came in (card, ACH or recorded by hand; sent once per payment)'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: payment.received }
                    data: { $ref: '#/components/schemas/PaymentEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  shipment.created:
    post:
      operationId: shipmentCreatedEvent
      summary: shipment.created
      description: 'A shipping label was bought (one event per new label)'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: shipment.created }
                    data: { $ref: '#/components/schemas/ShipmentEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  order.shipped:
    post:
      operationId: orderShippedEvent
      summary: order.shipped
      description: 'A job moved to Shipping'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: order.shipped }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  order.completed:
    post:
      operationId: orderCompletedEvent
      summary: order.completed
      description: 'A job moved to Invoice/Complete'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: order.completed }
                    data: { $ref: '#/components/schemas/JobEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  customer.created:
    post:
      operationId: customerCreatedEvent
      summary: customer.created
      description: 'A customer was added'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: customer.created }
                    data: { $ref: '#/components/schemas/CustomerEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  customer.updated:
    post:
      operationId: customerUpdatedEvent
      summary: customer.updated
      description: 'A customer''s details changed'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: customer.updated }
                    data: { $ref: '#/components/schemas/CustomerEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }
  inventory.low_stock:
    post:
      operationId: inventoryLowStockEvent
      summary: inventory.low_stock
      description: 'A material dropped to its reorder level (sent once per drop)'
      tags: [Webhooks]
      parameters:
        - $ref: '#/components/parameters/SignatureHeader'
        - $ref: '#/components/parameters/EventHeader'
        - $ref: '#/components/parameters/EventIdHeader'
        - $ref: '#/components/parameters/AttemptHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/WebhookEvent'
                - type: object
                  properties:
                    type: { const: inventory.low_stock }
                    data: { $ref: '#/components/schemas/LowStockEventData' }
      responses:
        '200': { $ref: '#/components/responses/WebhookAck' }
        '400': { description: Any non-2xx reply (or no reply in 10 s) is retried. }

components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: |
        A key made in **Shop Settings → API & Webhooks**. It belongs to one shop. *Read Only* keys can read jobs,
        quotes, customers, files, products and inventory; *Read & Write* keys can also create and change them and
        manage webhooks. AI keys add `use:ai`. Keep keys on your server, never in a web page or app customers download.
    oauth2:
      type: oauth2
      description: |
        "Connect with Printcore" for apps used by many shops (authorization code with PKCE `S256`). Send the token as
        `Authorization: Bearer pca_…`. Email help@printcore.ai to register an app and get a client id.
        A revoked or expired token gets `401 INVALID_TOKEN`; a token without a needed scope gets `403 INSUFFICIENT_SCOPE`.
      flows:
        authorizationCode:
          authorizationUrl: https://app.printcore.ai/oauth/authorize
          tokenUrl: https://app.printcore.ai/oauth/token
          refreshUrl: https://app.printcore.ai/oauth/token
          scopes:
            read:jobs: See your jobs and their status
            write:jobs: Create and update jobs
            read:quotes: See your quotes
            write:quotes: Create quotes
            read:customers: See your customers and their contacts
            write:customers: Add and update customers
            read:inventory: See your materials and stock levels
            read:products: See your products and price templates
            write:products: Add and update products
            manage:webhooks: Get notified when things change in Printcore
            write:actuals: Record production times and material used on jobs

  parameters:
    id:
      name: id
      in: path
      required: true
      schema: { type: string }
    limit:
      name: limit
      in: query
      description: Records per page (1–100).
      schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
    SignatureHeader:
      name: X-Printcore-Signature
      in: header
      required: true
      description: HMAC-SHA256 (hex) of the exact request body, keyed with the subscription's signing secret.
      schema: { type: string }
    EventHeader:
      name: X-Printcore-Event
      in: header
      required: true
      schema: { $ref: '#/components/schemas/EventType' }
    EventIdHeader:
      name: X-Printcore-Event-Id
      in: header
      required: true
      description: Same as the payload's `id`.
      schema: { type: string }
    AttemptHeader:
      name: X-Printcore-Attempt
      in: header
      description: 1 on the first try, up to 7.
      schema: { type: integer }
    cursor:
      name: cursor
      in: query
      description: The `nextCursor` from the previous page.
      schema: { type: string }

  responses:
    BadRequest:
      description: Something in the request is missing or invalid. The message names it.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Unauthorized:
      description: Missing, wrong, revoked or expired key or token (`INVALID_TOKEN` for OAuth).
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Forbidden:
      description: The key or token doesn't have the permission (`INSUFFICIENT_SCOPE`, with `requiredScope`), or the shop's plan doesn't include the API (`FEATURE_NOT_IN_PLAN`).
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    NotFound:
      description: Not found, or it belongs to another shop.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    Conflict:
      description: Can't be done in the current state (for example, finishing an upload before sending the file, or the webhook limit).
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    PricingUnavailable:
      description: The shop's pricing settings couldn't be loaded (`PRICING_UNAVAILABLE`). Try again shortly.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }
    WebhookAck:
      description: Any 2xx within 10 seconds counts as delivered. Anything else is retried.
    TooManyRequests:
      description: Too many requests. Wait a minute and retry.
      content:
        application/json:
          schema: { $ref: '#/components/schemas/Error' }

  schemas:
    ActualRequest:
      type: object
      required: [source, deviceId, operation, endedAt]
      properties:
        source: { type: string, pattern: '^[a-z0-9_.-]{2,40}$', description: 'Where the report comes from: `onyx`, `icut`, `printos`, `fiery`, ...' }
        externalId: { type: string, maxLength: 200, description: "The source's own id for this job. Same id twice = stored once." }
        deviceId: { type: string, maxLength: 100, description: 'The machine''s name or serial, as the source knows it. The shop maps each device to a Printcore station once.' }
        deviceName: { type: string, maxLength: 100 }
        operation: { type: string, enum: [print, cut, laminate, mount, rip, other] }
        jobName: { type: string, maxLength: 300, description: The RIP / cutter job or file name. Printcore reads the job number from it. }
        jobNumber: { type: string, maxLength: 20, description: 'The Printcore job number, if the source knows it. Wins over the name.' }
        startedAt: { type: string, format: date-time }
        endedAt: { type: string, format: date-time }
        runMinutes: { type: number, minimum: 0, maximum: 1440, description: Machine run time. Worked out from startedAt/endedAt when left out. }
        mediaUsed:
          type: object
          required: [value, unit]
          properties:
            value: { type: number, minimum: 0 }
            unit: { type: string, enum: [sqft, sqm, lm, ft, in, sheets] }
        inkUsed:
          type: array
          maxItems: 16
          items:
            type: object
            required: [color, ml]
            properties:
              color: { type: string, maxLength: 30 }
              ml: { type: number, minimum: 0 }
        cutLengthM: { type: number, minimum: 0, description: Total cut length in metres. }
        copies: { type: number, minimum: 0 }
        raw: { description: "The source's original record, kept for troubleshooting (up to 16 KB)." }
    ActualResult:
      type: object
      properties:
        id: { type: string }
        status: { type: string, enum: [matched, unmatched, ignored] }
        duplicate: { type: boolean }
        jobId: { type: [string, 'null'] }
        jobNumber: { type: [string, 'null'] }
        operationId: { type: [string, 'null'], description: The step the report was added to (null if the job has no step of that kind yet). }
        reason: { type: [string, 'null'], enum: [no_job_number, ambiguous, job_not_found, null], description: 'Why an unmatched report couldn''t be placed.' }
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string, description: 'What went wrong, in plain words.' }
        code:
          type: string
          description: A stable code for some errors.
          examples: [INVALID_TOKEN, INSUFFICIENT_SCOPE, FEATURE_NOT_IN_PLAN, VALIDATION_ERROR, NOT_FOUND, LIMIT_REACHED]
        requiredScope:
          description: With INSUFFICIENT_SCOPE, the permission(s) needed.
          oneOf: [{ type: string }, { type: array, items: { type: string } }]
    OAuthError:
      type: object
      properties:
        error: { type: string, examples: [invalid_grant, invalid_client, invalid_request, invalid_scope] }
        error_description: { type: string }
    Pagination:
      type: object
      properties:
        count: { type: integer }
        hasMore: { type: boolean }
        nextCursor: { type: [string, 'null'] }
    JobStatus:
      type: string
      enum: [Quote, Approved, Prepress, Production, Finishing, Shipping, Invoice/Complete, Completed, Archived]
    LineItemInput:
      type: object
      properties:
        description: { type: string }
        quantity: { type: number }
        unitPrice: { type: number }
        material: { type: string }
        specifications:
          type: array
          maxItems: 30
          items:
            type: object
            properties:
              label: { type: string }
              value: { type: string }
    QuoteCreate:
      type: object
      required: [projectName]
      properties:
        projectName: { type: string, maxLength: 200 }
        customerId: { type: string, description: A Printcore customer id. Links the job to that customer and fills in the name. }
        customerName: { type: string, description: "Display name, if you don't send customerId." }
        dueDate: { type: string, format: date }
        notes: { type: string, maxLength: 5000 }
        lineItems:
          type: array
          maxItems: 50
          description: Priced by the shop's calculators. Same fields as an estimate line, plus `name` and `specifications`.
          items:
            allOf:
              - $ref: '#/components/schemas/EstimateLineInput'
              - type: object
                properties:
                  name: { type: string }
                  specifications: { type: array, maxItems: 30, items: { type: object, properties: { label: { type: string }, value: { type: string } } } }
    JobCreate:
      type: object
      required: [projectName]
      properties:
        projectName: { type: string, maxLength: 200 }
        customerId: { type: string, description: A Printcore customer id. Links the job to that customer and fills in the name. }
        customerName: { type: string, description: "Display name, if you don't send customerId." }
        dueDate: { type: string, format: date }
        notes: { type: string, maxLength: 5000 }
        status: { $ref: '#/components/schemas/JobStatus' }
        lineItems: { type: array, maxItems: 50, description: 'Stored at the prices you send (a job is often an order already sold).', items: { $ref: '#/components/schemas/LineItemInput' } }
    Job:
      type: object
      description: A job. Shops add their own fields over time, so expect more properties than listed.
      additionalProperties: true
      properties:
        id: { type: string }
        jobNumber: { oneOf: [{ type: integer }, { type: string }] }
        projectName: { type: string }
        customerName: { type: string }
        customerId: { type: [string, 'null'] }
        status: { $ref: '#/components/schemas/JobStatus' }
        dueDate: { type: [string, 'null'], format: date }
        notes: { type: string }
        totalPrice: { type: number, description: Including tax. }
        lineItems: { type: array, items: { type: object, additionalProperties: true } }
        quoteSentAt: { type: [string, 'null'], format: date-time }
        quoteViewedAt: { type: [string, 'null'], format: date-time }
        portalStatus: { type: [string, 'null'] }
        createdTime: { type: string, format: date-time }
        updatedAt: { type: string, format: date-time }
    CustomerCreate:
      type: object
      required: [name]
      properties:
        name: { type: string }
        email: { type: string, format: email }
        phone: { type: string }
        company: { type: string }
        notes: { type: string }
        address:
          oneOf:
            - type: string
            - type: object
              properties:
                line1: { type: string }
                line2: { type: string }
                city: { type: string }
                state: { type: string }
                zip: { type: string }
    Customer:
      type: object
      additionalProperties: true
      properties:
        id: { type: string }
        name: { type: string }
        email: { type: string }
        phone: { type: string }
        company: { type: string }
        address: { oneOf: [{ type: string }, { type: object, additionalProperties: true }] }
        contacts: { type: array, items: { type: object, additionalProperties: true } }
        createdAt: { type: string, format: date-time }
    InventoryItem:
      type: object
      additionalProperties: true
      properties:
        id: { type: string }
        name: { type: string }
        type: { type: string }
        thickness: { type: string }
        currentStock: { type: number }
        minStock: { type: number }
        reorderThreshold: { type: number }
        unit: { type: string }
        width: { type: number }
        height: { type: number }
        rollLength: { type: number }
    JobFile:
      type: object
      properties:
        index: { type: integer }
        name: { type: string }
        url: { type: string, format: uri }
        stored: { type: boolean }
        uploadedAt: { type: string, format: date-time }
        source: { type: string, example: api }
        size: { type: integer }
        type: { type: string }
    FileLink:
      type: object
      required: [url]
      properties:
        url: { type: string, format: uri }
        name: { type: string }
    ProductOption:
      type: object
      properties:
        key: { type: string }
        label: { type: string }
        type: { type: string, enum: [choice, number, text, advanced] }
        priceType: { type: string, enum: [per_unit, percent] }
        default: { type: string }
        pricePerEach: { type: number }
        choices:
          type: array
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  label: { type: string }
                  price: { type: number }
    ProductInput:
      type: object
      properties:
        sku: { type: string }
        name: { type: string }
        description: { type: string }
        category: { type: string, description: A name from GET /v1/categories. }
        active: { type: boolean }
        price: { type: number, description: Price per piece. }
        cost: { type: number, description: What it costs the shop. Never shown to customers. }
        setupFee: { type: number }
        minimumCharge: { type: number }
        quantityBreaks:
          type: array
          items:
            type: object
            properties:
              minQuantity: { type: integer }
              price: { type: number }
              setupFee: { type: number }
        breaksApplyToOptions: { type: boolean }
        options: { type: array, items: { $ref: '#/components/schemas/ProductOption' } }
    Product:
      allOf:
        - $ref: '#/components/schemas/ProductInput'
        - type: object
          properties:
            id: { type: string }
            managedByApi: { type: boolean }
            updatedAt: { type: string, format: date-time }
    ProductSyncResult:
      type: object
      additionalProperties: true
      properties:
        index: { type: integer }
        sku: { type: string }
        action: { type: string, enum: [create, update, unchanged, deactivate, error] }
        changes: { type: array, items: { type: object, properties: { field: { type: string }, from: {}, to: {} } } }
        error: { type: string }
    WebhookSubscription:
      type: object
      properties:
        id: { type: string }
        url: { type: string, format: uri }
        events: { type: array, items: { $ref: '#/components/schemas/EventType' } }
        status: { type: string, enum: [active, paused, disabled] }
        description: { type: string }
        createdAt: { type: [string, 'null'], format: date-time }
    EventType:
      type: string
      enum:
        - quote_request.received
        - quote.created
        - quote.sent
        - quote.viewed
        - quote.approved
        - job.created
        - job.updated
        - job.status_changed
        - job.step_started
        - job.step_completed
        - job.deleted
        - proof.approved
        - proof.revision_requested
        - payment.received
        - shipment.created
        - order.shipped
        - order.completed
        - customer.created
        - customer.updated
        - inventory.low_stock
    WebhookEvent:
      type: object
      description: Every event has this shape. `event`, `version` and `timestamp` repeat `type` and `createdAt` for older receivers.
      required: [id, type, createdAt, tenantId, data]
      properties:
        id: { type: string, description: Same on every retry of this event. Use it to ignore repeats., example: evt_5c1f… }
        type: { $ref: '#/components/schemas/EventType' }
        createdAt: { type: string, format: date-time }
        tenantId: { type: string, description: The shop. }
        data: { type: object, additionalProperties: true }
        event: { type: string }
        version: { type: string, const: '1' }
        timestamp: { type: string, format: date-time }
        sample: { type: boolean, description: Only on placeholder samples. }
    EstimateRequest:
      type: object
      required: [items]
      properties:
        items:
          type: array
          minItems: 1
          maxItems: 50
          items: { $ref: '#/components/schemas/EstimateLineInput' }
    EstimateLineInput:
      type: object
      description: What the line is. Sizes are in inches. Leave out what you don't know; the reply says what's missing.
      properties:
        description: { type: string, maxLength: 500 }
        type:
          type: string
          enum: [wide, digital, cut_vinyl, vehicle_wrap, channel_letter, booklet, apparel]
          description: Which calculator. Friendly names such as `wide format`, `banner`, `vinyl`, `wrap` or `merch` also work.
        quantity: { type: integer, minimum: 1, maximum: 1000000 }
        width: { type: number, exclusiveMinimum: 0, description: Inches. }
        height: { type: number, exclusiveMinimum: 0, description: Inches. }
        material: { type: string, description: 'Matched to the shop''s inventory by name; give `thickness` when names repeat.' }
        materialId: { type: string, description: 'An inventory id from `GET /v1/inventory` (exact).' }
        thickness: { type: string, examples: ['4mm', '.060"', 14pt] }
        sides: { type: string, description: '`single` or `double`.' }
        finishing: { type: array, maxItems: 10, items: { type: string }, examples: [[grommets, shape cut]] }
        format: { type: string, enum: [flat, booklet], description: Digital only. }
        pages: { type: integer, minimum: 1, description: Booklets. }
        productId: { type: string, description: 'Price as one of the shop''s product presets (`GET /v1/products`). For `apparel`, the item''s id in the shop''s apparel catalog.' }
        details: { $ref: '#/components/schemas/EstimateDetails' }
        style: { type: string, maxLength: 120, description: 'Apparel only: a style number or name from the shop''s catalog (`5000`, `Gildan 5000`, `hoodie`); the best match is used. Give this or `productId`.' }
        color: { type: string, maxLength: 60, description: 'Apparel only: the garment color, matched to the colors the item comes in.' }
        sizes:
          type: object
          description: 'Apparel only: pieces per size. Without it, `quantity` is priced at the item''s base size.'
          additionalProperties: { type: integer, minimum: 0, maximum: 1000000 }
          examples: [{ M: 12, L: 12, XL: 6 }]
        decoration:
          type: object
          description: 'Apparel only: how it is decorated. The method must be one the shop allows on the item; otherwise its default is used and `assumptions` says so.'
          properties:
            method: { type: string, examples: [screen, embroidery, dtf, dtg] }
            location: { type: string, examples: [full front, left chest] }
            locations: { type: array, maxItems: 6, items: { type: string }, description: 'Several locations, one print each.' }
            colors: { type: integer, minimum: 1, description: Ink colors (screen print). }
            stitches: { type: integer, minimum: 1, description: Stitch count (embroidery). }
            widthIn: { type: number, exclusiveMinimum: 0, description: Print width in inches (DTF / heat transfer). }
    EstimateDetails:
      type: object
      description: Extra details the specialty calculators use.
      properties:
        vehicle: { type: object, properties: { year: { type: string }, make: { type: string }, model: { type: string } } }
        vehicleClassId: { type: string }
        coverageType: { type: string, enum: [full, partial, spot] }
        wrapType: { type: string, enum: [printed, color_change] }
        letterText: { type: string }
        letterCount: { type: integer }
        letterHeight: { type: number, description: Inches. }
        illumination: { type: string, enum: [lit, non_lit, halo] }
        colors: { type: array, items: { type: string } }
        installed: { type: boolean }
        transferTape: { type: boolean }
        weeding: { type: string, examples: [simple, moderate, complex] }
        lamination: { type: string, examples: [none, gloss, matte] }
        binding: { type: string, enum: [saddle_stitch, perfect_bound, spiral, corner_staple] }
        coverStock: { type: string }
        interiorStock: { type: string }
    Estimate:
      type: object
      properties:
        currency: { type: string, examples: [USD] }
        total: { type: number, description: Sum of the priced lines. }
        unpricedCount: { type: integer }
        lines: { type: array, items: { $ref: '#/components/schemas/EstimateLine' } }
        note: { type: string }
    EstimateLine:
      type: object
      properties:
        index: { type: integer }
        description: { type: string }
        type: { type: [string, 'null'] }
        quantity: { type: [integer, 'null'] }
        priced: { type: boolean }
        price: { type: [number, 'null'], description: Line total (sell price). }
        unitPrice: { type: [number, 'null'] }
        calculator: { type: string, examples: [Wide format, Digital press, Product preset, Vehicle wrap, Apparel & promo] }
        material: { type: object, properties: { id: { type: string }, name: { type: string }, thickness: { type: string } } }
        product: { type: object, properties: { id: { type: string }, name: { type: string } } }
        setupFee: { type: number, description: Included in `price`. }
        finishing:
          type: array
          description: Finishing included in `price`.
          items:
            type: object
            properties:
              name: { type: string }
              requested: { type: string }
              quantity: { type: number }
              unit: { type: string, enum: [unit, sq ft, linear ft] }
              price: { type: number }
        finishingNotPriced: { type: array, items: { type: string }, description: Finishing the shop has no price for. }
        reason: { type: string, description: 'Why the line wasn''t priced, e.g. `needs material`.' }
        assumptions: { type: array, items: { type: string }, description: 'Apparel: what the price assumed, e.g. `no size breakdown — priced as 24 × S`.' }
    QuoteRequestCreate:
      type: object
      required: [description]
      description: Give the customer's `name` or `email` (or both), nested in `customer` or as top-level fields.
      properties:
        customer:
          type: object
          properties:
            name: { type: string }
            email: { type: string, format: email }
            phone: { type: string }
            company: { type: string }
        name: { type: string, description: Same as customer.name. }
        email: { type: string, format: email, description: Same as customer.email. }
        phone: { type: string }
        company: { type: string }
        projectName: { type: string, maxLength: 200 }
        description: { type: string, maxLength: 5000, description: What the customer wants made. }
        quantity: { type: string }
        size: { type: string }
        material: { type: string }
        dueDate: { type: string, description: 'When they need it, ideally YYYY-MM-DD.' }
        notes: { type: string, maxLength: 5000 }
        fileUrls:
          description: Up to 10 links to artwork (an array, or one string with links separated by spaces or commas).
          oneOf: [{ type: array, maxItems: 10, items: { type: string, format: uri } }, { type: string }]
        externalId: { type: string, maxLength: 200, description: Your id for this request; makes retries safe. }
    QuoteRequest:
      type: object
      properties:
        id: { type: string }
        status: { type: string, examples: [new] }
        source: { type: string, const: api }
        from: { type: string }
        fromName: { type: string }
        subject: { type: string }
        receivedAt: { type: string, format: date-time }
        reviewUrl: { type: string, format: uri, description: Where the shop reviews it in Printcore. }
    QuoteRequestEventData:
      type: object
      properties:
        requestId: { type: string }
        source: { type: string, enum: [email, voice, portal, assistant, api] }
        sourceApp: { type: [string, 'null'], description: 'The app that sent it, for API requests.' }
        from: { type: [string, 'null'], description: 'The customer''s email, when known.' }
        fromName: { type: [string, 'null'] }
        phone: { type: [string, 'null'], description: 'Caller ID, for voice requests.' }
        subject: { type: [string, 'null'] }
        summary: { type: [string, 'null'] }
        text: { type: string, description: 'The request as written (up to 5,000 characters).' }
        fileLinks: { type: array, items: { type: string } }
        attachmentCount: { type: integer }
        receivedAt: { type: [string, 'null'], format: date-time }
        reviewUrl: { type: string, format: uri }
    QuoteEventData:
      type: object
      properties:
        jobId: { type: string }
        quoteId: { type: string, description: Same as jobId. }
        sentAt: { type: string, format: date-time, description: quote.sent only. }
        viewedAt: { type: string, format: date-time, description: quote.viewed only. }
        source: { type: [string, 'null'], description: "quote.created only. Where the quote came from: widget (the shop's website quote widget), api, or null for quotes made in the app." }
        job: { $ref: '#/components/schemas/Job' }
    JobEventData:
      type: object
      properties:
        jobId: { type: string }
        job: { $ref: '#/components/schemas/Job' }
    JobStatusEventData:
      type: object
      properties:
        jobId: { type: string }
        previousStatus: { type: [string, 'null'] }
        newStatus: { type: string }
        job: { $ref: '#/components/schemas/Job' }
    JobDeletedEventData:
      type: object
      properties:
        jobId: { type: string }
        jobNumber: { type: [string, integer, 'null'] }
        status: { type: [string, 'null'] }
    StepEventData:
      type: object
      properties:
        jobId: { type: [string, 'null'] }
        operationId: { type: string }
        step:
          type: object
          additionalProperties: true
          properties:
            id: { type: string }
            type: { type: string, example: print_wide }
            status: { type: string, example: completed }
    PaymentEventData:
      type: object
      properties:
        jobId: { type: [string, 'null'] }
        paymentId: { type: string }
        payment:
          type: object
          properties:
            id: { type: string }
            amount: { type: number }
            method: { type: [string, 'null'], examples: [card, ach, check, cash, other] }
            kind: { type: [string, 'null'], examples: [balance, deposit, manual] }
            status: { type: string }
            note: { type: [string, 'null'] }
            succeededAt: { type: [string, 'null'], format: date-time }
            createdAt: { type: [string, 'null'], format: date-time }
    ShipmentEventData:
      type: object
      properties:
        jobId: { type: string }
        shipment:
          type: object
          properties:
            id: { type: string }
            carrier: { type: [string, 'null'] }
            service: { type: [string, 'null'] }
            trackingNumber: { type: [string, 'null'] }
            trackingNumbers: { type: array, items: { type: string } }
            boxes: { type: integer }
            shipTo: { type: [object, 'null'], additionalProperties: true }
            createdAt: { type: [string, 'null'], format: date-time }
        job: { $ref: '#/components/schemas/Job' }
    CustomerEventData:
      type: object
      properties:
        customerId: { type: string }
        customer: { $ref: '#/components/schemas/Customer' }
    LowStockEventData:
      type: object
      properties:
        inventoryId: { type: string }
        currentStock: { type: number }
        threshold: { type: number }
        item: { $ref: '#/components/schemas/InventoryItem' }
