> ## Documentation Index
> Fetch the complete documentation index at: https://docs.watchdog.no/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a purchase order

> Returns the purchase order with its lines and current commercial revision. A linked agreement the caller cannot see is returned as restricted.



## OpenAPI

````yaml /openapi.json get /v1/purchase-orders/{id}
openapi: 3.1.0
info:
  title: Watchdog API
  version: 1.0.0
  description: >-
    The Watchdog API is served from https://api.watchdog.no. Request bodies are
    limited to 2 MiB unless an endpoint says otherwise. Files are uploaded
    directly to storage, not through the API.
servers:
  - url: https://api.watchdog.no
    description: Watchdog API
security: []
paths:
  /v1/purchase-orders/{id}:
    get:
      tags:
        - Purchase orders
      summary: Get a purchase order
      description: >-
        Returns the purchase order with its lines and current commercial
        revision. A linked agreement the caller cannot see is returned as
        restricted.
      operationId: getPurchaseOrder
      parameters:
        - name: X-Organization-Id
          in: header
          required: false
          schema:
            type: string
          description: >-
            The organization to act in. Required for personal API keys; list the
            organizations you can access with GET /v1/organizations.
        - name: fields
          in: query
          required: false
          schema:
            type: array
            items:
              type: string
          style: form
          explode: false
          description: >-
            Return only these fields; use dots for nested fields, such as
            approvers.user_id. id is always returned. Fields: company_id, id,
            number, title, status, awaiting_approval, approvers, archived,
            supplier, buyer, owner_user_id, agreement, currency_code,
            commitment_basis, totals, billing, revision, open_alert_count,
            valid_until, origin, source, from_import, created_at, updated_at,
            lifecycle, emails, status_reason, owner, invoice_approvers,
            amount_limit, unordered_charges, unordered_charges_limit,
            scope_description, issued_date, valid_from, delivery_date, delivery,
            buyer_reference, sales_order_reference, contract_reference,
            project_reference, dimension_values, note_to_supplier,
            internal_note, budget, billing_review, invoice_checks, line_items,
            push_targets, latest_push, push_readiness, to_fill,
            sent_to_supplier, supplier_revision, placement, approval,
            approval_required, opened_at, closed_at, cancelled_at, archived_at,
            import, proposed_revision, supplier_reply.
        - schema:
            type: string
            format: uuid
          required: true
          name: id
          in: path
      responses:
        '200':
          description: The purchase order.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PurchaseOrder'
        '400':
          description: >-
            The request is invalid. details lists up to 20 field errors. Request
            bodies are limited to 2 MiB.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
          content:
            application/json:
              example:
                error:
                  code: validation_error
                  message: >-
                    The request is invalid. details lists up to 20 field errors.
                    Request bodies are limited to 2 MiB.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_validation_error'
        '401':
          description: The bearer token is missing or invalid.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
            WWW-Authenticate:
              schema:
                type: string
              required: false
              description: Bearer authentication challenge, when supplied.
          content:
            application/json:
              example:
                error:
                  code: invalid_token
                  message: The bearer token is missing or invalid.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_invalid_token'
        '403':
          description: >-
            Access denied. The error code says why: forbidden, token_disabled,
            organization_required, insufficient_role or mfa_required.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
          content:
            application/json:
              example:
                error:
                  code: forbidden
                  message: >-
                    Access denied. The error code says why: forbidden,
                    token_disabled, organization_required, insufficient_role or
                    mfa_required.
                  request_id: req_example
              schema:
                $ref: >-
                  #/components/schemas/Error_forbidden_token_disabled_organization_required_insufficient_role_mfa_required
        '404':
          description: The resource does not exist in the current organization.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
          content:
            application/json:
              example:
                error:
                  code: not_found
                  message: The resource does not exist in the current organization.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_not_found'
        '429':
          description: Too many requests. Wait for the Retry-After delay before retrying.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
            Retry-After:
              schema:
                type: string
                example: '60'
              required: true
              description: Seconds to wait before retrying the request.
          content:
            application/json:
              example:
                error:
                  code: rate_limit_exceeded
                  message: >-
                    Too many requests. Wait for the Retry-After delay before
                    retrying.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_rate_limit_exceeded'
        '500':
          description: >-
            Unexpected server failure. Include the request ID when contacting
            support.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
          content:
            application/json:
              example:
                error:
                  code: internal_error
                  message: >-
                    Unexpected server failure. Include the request ID when
                    contacting support.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_internal_error'
        '503':
          description: >-
            Temporarily unavailable. Retry after the Retry-After delay, when
            provided.
          headers:
            X-Request-Id:
              schema:
                type: string
              required: true
              description: >-
                Request ID, also included in error bodies. Include it when
                contacting support.
            Cache-Control:
              schema:
                type: string
                enum:
                  - private, no-store
                  - private, no-store, no-transform
              required: false
              description: API responses are private and must not be cached.
            X-RateLimit-Limit:
              schema:
                type: string
                example: '500'
              required: false
              description: >-
                Requests allowed per minute for this credential, or failed API
                key attempts allowed per minute from this IP address.
            Retry-After:
              schema:
                type: string
                example: '60'
              required: true
              description: Seconds to wait before retrying the request.
          content:
            application/json:
              example:
                error:
                  code: service_unavailable
                  message: >-
                    Temporarily unavailable. Retry after the Retry-After delay,
                    when provided.
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_service_unavailable'
      security:
        - ApiKeyBearer: []
components:
  schemas:
    PurchaseOrder:
      type: object
      properties:
        company_id:
          type: string
          format: uuid
          description: >-
            The company that places the order. Its buyer is the company's own
            recipient, unless an imported order names another.
        id:
          type: string
          format: uuid
        number:
          type:
            - string
            - 'null'
        title:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - draft
            - open
            - closed
            - cancelled
          description: >-
            closed means closed for invoicing, set by a person; it is not
            derived from an ERP receipt status. Waiting for approval is not a
            status: see awaiting_approval.
        awaiting_approval:
          type: boolean
          description: >-
            The order has an approval request pending: a draft opens once
            approved; on an opened order it decides the proposed revision, while
            the current revision stays in force and can be sent and pushed.
        approvers:
          type: array
          items:
            type: object
            properties:
              user_id:
                type: string
                minLength: 1
                maxLength: 200
                pattern: ^[A-Za-z0-9_-]+$
              first_name:
                type:
                  - string
                  - 'null'
              last_name:
                type:
                  - string
                  - 'null'
              email:
                type:
                  - string
                  - 'null'
            required:
              - user_id
              - first_name
              - last_name
              - email
          description: >-
            The people the pending approval request waits for, in the order they
            were added; empty when none is pending. Teams it waits for are on
            approval.approver_teams. Who decided an earlier request is on
            approval.
        archived:
          type: boolean
        supplier:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              format: uuid
            name:
              type: string
            organization_number:
              type:
                - string
                - 'null'
          required:
            - id
            - name
            - organization_number
        buyer:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              format: uuid
            name:
              type: string
            organization_number:
              type:
                - string
                - 'null'
          required:
            - id
            - name
            - organization_number
          description: 'A recipient: the legal entity that placed the order.'
        owner_user_id:
          type:
            - string
            - 'null'
          minLength: 1
          maxLength: 200
          pattern: ^[A-Za-z0-9_-]+$
        agreement:
          type:
            - object
            - 'null'
          properties:
            id:
              type:
                - string
                - 'null'
              format: uuid
            title:
              type:
                - string
                - 'null'
            origin:
              type: string
              enum:
                - manual
                - automatic
            restricted:
              type: boolean
              description: >-
                True when the caller cannot see the agreement; id and title are
                then null.
          required:
            - id
            - title
            - origin
            - restricted
        currency_code:
          type:
            - string
            - 'null'
        commitment_basis:
          type: string
          enum:
            - lines
            - amount_limit
          description: >-
            lines: the order commits to its active lines. amount_limit: it
            commits to amount_limit for the scope in scope_description; its
            lines are price references.
        totals:
          type: object
          properties:
            lines_excluding_vat:
              type: string
              pattern: ^-?\d+(?:\.\d+)?$
              description: Active lines, excluding VAT.
            commitment:
              type:
                - string
                - 'null'
              pattern: ^-?\d+(?:\.\d+)?$
              description: >-
                Active lines for a lines order, amount_limit for an amount-limit
                order.
            expected:
              type:
                - string
                - 'null'
              pattern: ^-?\d+(?:\.\d+)?$
              description: >-
                What the order is expected to cost, excluding VAT: the budget,
                when set, while a lines order has no active lines; otherwise
                commitment.
          required:
            - lines_excluding_vat
            - commitment
            - expected
        billing:
          $ref: '#/components/schemas/PurchaseOrderBilling'
        revision:
          type:
            - integer
            - 'null'
          description: The current commercial revision; null for a draft.
        open_alert_count:
          type: integer
          minimum: 0
          description: >-
            Visible, live alerts from checking the order's invoices against it:
            neither dismissed, skipped nor credited.
        valid_until:
          type:
            - string
            - 'null'
        origin:
          type: string
          enum:
            - native
            - imported
          description: >-
            Where the order was born and is edited: `native` in Watchdog,
            `imported` in the ERP in `source`.
        source:
          $ref: '#/components/schemas/PurchaseOrderSource'
        from_import:
          type: boolean
          description: >-
            Drafted from documents through createPurchaseOrderImport; import has
            the details.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        lifecycle:
          $ref: '#/components/schemas/PurchaseOrderLifecycle'
        emails:
          type: object
          properties:
            message:
              type: boolean
              description: A message to the supplier can be sent.
            price_request:
              type: boolean
              description: 'A price request can be sent: a draft.'
            order:
              type: boolean
              description: 'The order can be sent by email: an open order.'
          required:
            - message
            - price_request
            - order
          description: >-
            Which emails the order may send its supplier, as the send endpoints
            enforce them. None for an imported or archived order; messages also
            after it is closed or cancelled.
        status_reason:
          type:
            - string
            - 'null'
        owner:
          type:
            - object
            - 'null'
          properties:
            user_id:
              type: string
              minLength: 1
              maxLength: 200
              pattern: ^[A-Za-z0-9_-]+$
            first_name:
              type:
                - string
                - 'null'
            last_name:
              type:
                - string
                - 'null'
            email:
              type:
                - string
                - 'null'
          required:
            - user_id
            - first_name
            - last_name
            - email
        invoice_approvers:
          $ref: '#/components/schemas/PurchaseOrderInvoiceApprovers'
        amount_limit:
          type:
            - string
            - 'null'
          pattern: ^-?\d+(?:\.\d+)?$
          description: Excluding VAT.
        unordered_charges:
          type: string
          enum:
            - flag
            - accept
          description: >-
            Invoice lines the order's lines don't cover, like freight: flag
            raises an unordered_charge alert, accept accepts them up to
            unordered_charges_limit.
        unordered_charges_limit:
          type:
            - string
            - 'null'
          pattern: ^-?\d+(?:\.\d+)?$
          description: >-
            Set only with accept: the most accepted across the order's invoices,
            excluding VAT; null accepts them all.
        scope_description:
          type:
            - string
            - 'null'
        issued_date:
          type:
            - string
            - 'null'
        valid_from:
          type:
            - string
            - 'null'
        delivery_date:
          type:
            - string
            - 'null'
          description: When the goods or service are expected. Needed to push the order.
        delivery:
          $ref: '#/components/schemas/PurchaseOrderDelivery'
        buyer_reference:
          type:
            - string
            - 'null'
          description: >-
            While a draft, empty or still the owner's name, it follows the
            owner's name. A reference a person writes stays.
        sales_order_reference:
          type:
            - string
            - 'null'
          description: The supplier's order or confirmation number (Peppol SalesOrderID).
        contract_reference:
          type:
            - string
            - 'null'
          description: >-
            While a draft, empty or still the linked agreement's number, it
            follows the agreement's number.
        project_reference:
          type:
            - string
            - 'null'
          description: >-
            While a draft, empty or still the code of the order's project (its
            value of a project dimension), it follows that code.
        dimension_values:
          type: array
          items:
            type: object
            properties:
              dimension_id:
                type: string
                format: uuid
              dimension_name:
                type: string
              dimension_kind:
                type: string
                enum:
                  - department
                  - project
                  - custom
                description: >-
                  The dimension's kind: a project's value fills the order's
                  project reference.
              id:
                type: string
                format: uuid
              name:
                type: string
              usable:
                type: boolean
                description: >-
                  Active and still in the chart of accounts; a line keeps a code
                  that went.
              code:
                type:
                  - string
                  - 'null'
            required:
              - dimension_id
              - dimension_name
              - dimension_kind
              - id
              - name
              - usable
              - code
          description: >-
            Where the order's cost is booked, in its company: each line takes
            these, except where it holds its own value for that dimension, and
            invoices billing the order take them as coding suggestions. Not part
            of the terms, so revisions leave it out.
        note_to_supplier:
          type:
            - string
            - 'null'
          description: >-
            Free text for the supplier, printed on the order (Peppol Order
            Note).
        internal_note:
          type:
            - string
            - 'null'
        budget:
          type:
            - string
            - 'null'
          pattern: ^-?\d+(?:\.\d+)?$
          description: >-
            Excluding VAT, internal: what the organization expects to spend.
            Never printed, sent or pushed.
        billing_review:
          $ref: '#/components/schemas/PurchaseOrderBillingReview'
        invoice_checks:
          type: object
          properties:
            checked:
              type: integer
              minimum: 0
              description: Accepted invoices with a completed check.
          required:
            - checked
          description: >-
            Checks of the accepted invoices against this order, counted over
            every invoice like billing.
        line_items:
          type: array
          items:
            $ref: '#/components/schemas/PurchaseOrderLine'
        push_targets:
          type: array
          items:
            $ref: '#/components/schemas/PurchaseOrderPushTarget'
          description: >-
            Connections a native order can be pushed to; empty once the ERP
            holds it, and for imported orders.
        latest_push:
          $ref: '#/components/schemas/PurchaseOrderLatestPush'
        push_readiness:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
              field:
                type: string
              message:
                type: string
            required:
              - code
              - field
              - message
          description: >-
            What the order is missing before it can be pushed; empty when it is
            ready.
        to_fill:
          type: array
          items:
            $ref: '#/components/schemas/PurchaseOrderToFill'
          description: >-
            What an order made in Watchdog should still get: each dimension the
            organization requires that a draft does not carry yet (opening needs
            it), then the agreements that may cover it, while it links none.
            Fill each, or ask the person. Empty when nothing is missing, and for
            orders synced from an accounting system.
        sent_to_supplier:
          $ref: '#/components/schemas/PurchaseOrderSentToSupplier'
        supplier_revision:
          type:
            - integer
            - 'null'
          description: >-
            The latest revision whose terms the supplier has, or may have: sent
            through Watchdog or marked as sent outside it (sendPurchaseOrder),
            made by accepting the supplier's own proposal, or revision 1 of an
            order they confirmed before it opened. Null when they have none.
        placement:
          type: string
          enum:
            - watchdog
            - external
          description: >-
            watchdog: placed through Watchdog, with its approval and send.
            external: ordered outside Watchdog (a web shop, the phone) and
            recorded here; it needed no order approval and is not sent.
        approval:
          $ref: '#/components/schemas/PurchaseOrderApproval'
        approval_required:
          type: boolean
          description: >-
            A draft that an approval rule for orders matches: opening it asks
            for approval instead. False for opened and imported orders.
        opened_at:
          type:
            - string
            - 'null'
          format: date-time
        closed_at:
          type:
            - string
            - 'null'
          format: date-time
        cancelled_at:
          type:
            - string
            - 'null'
          format: date-time
        archived_at:
          type:
            - string
            - 'null'
          format: date-time
        import:
          $ref: '#/components/schemas/PurchaseOrderImportState'
        proposed_revision:
          $ref: '#/components/schemas/PurchaseOrderProposedRevision'
        supplier_reply:
          $ref: '#/components/schemas/PurchaseOrderSupplierReply'
      required:
        - company_id
        - id
        - number
        - title
        - status
        - awaiting_approval
        - approvers
        - archived
        - supplier
        - buyer
        - owner_user_id
        - agreement
        - currency_code
        - commitment_basis
        - totals
        - billing
        - revision
        - open_alert_count
        - valid_until
        - origin
        - source
        - from_import
        - created_at
        - updated_at
        - lifecycle
        - emails
        - status_reason
        - owner
        - invoice_approvers
        - amount_limit
        - unordered_charges
        - unordered_charges_limit
        - scope_description
        - issued_date
        - valid_from
        - delivery_date
        - delivery
        - buyer_reference
        - sales_order_reference
        - contract_reference
        - project_reference
        - dimension_values
        - note_to_supplier
        - internal_note
        - budget
        - billing_review
        - invoice_checks
        - line_items
        - push_targets
        - latest_push
        - push_readiness
        - to_fill
        - sent_to_supplier
        - supplier_revision
        - placement
        - approval
        - approval_required
        - opened_at
        - closed_at
        - cancelled_at
        - archived_at
        - import
        - proposed_revision
        - supplier_reply
    Error_validation_error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - validation_error
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_invalid_token:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - invalid_token
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_forbidden_token_disabled_organization_required_insufficient_role_mfa_required:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - forbidden
                - token_disabled
                - organization_required
                - insufficient_role
                - mfa_required
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_not_found:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - not_found
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_rate_limit_exceeded:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - rate_limit_exceeded
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_internal_error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - internal_error
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    Error_service_unavailable:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - service_unavailable
            message:
              type: string
            request_id:
              type: string
            description:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                  field:
                    type: string
                  message:
                    type: string
                required:
                  - code
                  - field
                  - message
              maxItems: 20
            workflow_run_id:
              type: string
              format: uuid
            import_id:
              type: string
              format: uuid
            existing_party:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - supplier
                    - recipient
                id:
                  type: string
                  format: uuid
              required:
                - type
                - id
          required:
            - code
            - message
            - request_id
      required:
        - error
    PurchaseOrderBilling:
      type: object
      properties:
        linked_invoices:
          type: integer
          minimum: 0
        billed:
          type: string
        remaining:
          type:
            - string
            - 'null'
        excess:
          type:
            - string
            - 'null'
        authoritative:
          type: boolean
        coverage:
          type: object
          properties:
            pending_suggestions:
              type: integer
              minimum: 0
            unsupported_credits:
              type: integer
              minimum: 0
            incompatible_invoices:
              type: integer
              minimum: 0
            invalid_invoices:
              type: integer
              minimum: 0
            unassigned_invoices:
              type: integer
              minimum: 0
            reconciliation_pending:
              type: boolean
          required:
            - pending_suggestions
            - unsupported_credits
            - incompatible_invoices
            - invalid_invoices
            - unassigned_invoices
            - reconciliation_pending
        untied:
          type:
            - object
            - 'null'
          properties:
            lines:
              type: integer
              minimum: 0
            amount:
              type: string
          required:
            - lines
            - amount
      required:
        - linked_invoices
        - billed
        - remaining
        - excess
        - authoritative
        - coverage
        - untied
    PurchaseOrderSource:
      type:
        - object
        - 'null'
      properties:
        system:
          type: string
          description: >-
            The other system: an ERP, such as tripletex, or the name the creator
            gave.
        id:
          type: string
          description: That system's own ID for the order.
        number:
          type:
            - string
            - 'null'
          description: >-
            That system's number for the order; for a pushed order, the one the
            ERP assigned. Invoices citing it match the order.
        channel:
          type: string
          enum:
            - integration
            - api
          description: >-
            `integration`: a connection imports or pushes the order and keeps
            the fields below. `api`: linked when the order was created; nothing
            syncs it.
        status:
          type:
            - string
            - 'null'
          description: That system's own status for the order, as given.
        refreshed_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the ERP and Watchdog last agreed on the order; null while a
            push is unfinished.
        synced_revision:
          type:
            - integer
            - 'null'
          description: >-
            The revision the ERP verifiably holds; null while a push is
            unfinished.
        pending:
          type: boolean
          description: >-
            A native order's current revision is not in the ERP yet: never
            pushed, or amended since.
      required:
        - system
        - id
        - number
        - channel
        - status
        - refreshed_at
        - synced_revision
        - pending
      description: >-
        The order's ERP. An imported order's terms, lines and cancellation
        change there and the next sync brings them in; a native order is pushed
        there and its copy follows Watchdog.
    PurchaseOrderLifecycle:
      type: object
      properties:
        status:
          type: string
          enum:
            - draft
            - awaiting_approval
            - open
            - closed
            - cancelled
          description: >-
            Where the order is in its life: its status, except that a draft with
            an approval request pending reads awaiting_approval. An open order
            whose proposed revision waits for approval stays open. Read-only;
            set the order's status through PATCH.
        blockers:
          type: array
          items:
            type: string
            enum:
              - archived
              - no_number
              - no_supplier
              - no_buyer
              - no_currency
              - no_lines
              - negative_total
              - no_amount_limit
              - no_scope
              - no_required_dimension
          description: >-
            What opening the order would be refused for, as PATCH with status
            open refuses it: archived (restore it first), then what it is
            missing (no_required_dimension: a dimension the organization
            requires on orders, settings.purchase_order_required_dimensions).
            Only for draft and awaiting_approval, empty otherwise. A number
            another order took is found only when it opens.
        next_action:
          type:
            - object
            - 'null'
          properties:
            kind:
              type: string
              enum:
                - restore
                - record_ordered
                - approve
                - await_approval
                - decide_proposal
                - ask_price
                - await_supplier
                - request_approval
                - open
                - open_and_send
                - send
                - close
              description: >-
                restore: unarchive it. record_ordered: save an order placed
                outside Watchdog as ordered. approve: decide its approval
                request. await_approval: its approvers decide. decide_proposal:
                accept or reject the proposed revision. ask_price: ask the
                supplier for a price. await_supplier: the supplier has not
                answered the price request. request_approval: open it, which
                asks for approval. open: open it; the supplier already confirmed
                it. open_and_send: open it and send it to the supplier. send:
                send the current revision to the supplier. close: it is invoiced
                to its value.
            mine:
              type: boolean
              description: Whether the caller may take this step.
            waiting_on:
              type: array
              items:
                type: string
              description: >-
                User IDs of whoever else the step waits on, for await_approval;
                empty otherwise.
            disabled_by:
              type: array
              items:
                type: string
                enum:
                  - archived
                  - no_number
                  - no_supplier
                  - no_buyer
                  - no_currency
                  - no_lines
                  - negative_total
                  - no_amount_limit
                  - no_scope
                  - no_required_dimension
              description: >-
                What must be fixed before the step can be taken; empty when it
                can be now.
          required:
            - kind
            - mine
            - waiting_on
            - disabled_by
          description: >-
            The order's one next step. Null when nothing waits, and always for
            an imported order, which its accounting system decides.
      required:
        - status
        - blockers
        - next_action
    PurchaseOrderInvoiceApprovers:
      type: object
      properties:
        people:
          type: array
          items:
            type: object
            properties:
              user_id:
                type: string
                minLength: 1
                maxLength: 200
                pattern: ^[A-Za-z0-9_-]+$
              first_name:
                type:
                  - string
                  - 'null'
              last_name:
                type:
                  - string
                  - 'null'
              email:
                type:
                  - string
                  - 'null'
              step:
                type: integer
                exclusiveMinimum: 0
                description: >-
                  The approver's step, from 1. Steps set only the order in which
                  the invoice's approvers are asked; the invoice is approved at
                  the organization's number of approvals, however many steps
                  there are.
            required:
              - user_id
              - first_name
              - last_name
              - email
              - step
        teams:
          type: array
          items:
            type: object
            properties:
              team_id:
                type: string
                format: uuid
              name:
                type: string
              step:
                type: integer
                exclusiveMinimum: 0
                description: >-
                  The approver's step, from 1. Steps set only the order in which
                  the invoice's approvers are asked; the invoice is approved at
                  the organization's number of approvals, however many steps
                  there are.
            required:
              - team_id
              - name
              - step
      required:
        - people
        - teams
      description: >-
        Who approves the invoices matched to the order, by step and then in the
        order they were added; not approval.approvers, who approve the order
        itself. An invoice that bills the order gets them in their steps once
        Watchdog has read and checked it, in place of the approval rules'
        approvers. Set with updatePurchaseOrder invoice_approvers.
    PurchaseOrderDelivery:
      type:
        - object
        - 'null'
      properties:
        name:
          type:
            - string
            - 'null'
          description: Who receives the delivery (Peppol DeliveryParty name).
        address:
          type: object
          properties:
            street:
              type:
                - string
                - 'null'
            postal_code:
              type:
                - string
                - 'null'
            city:
              type:
                - string
                - 'null'
            country_code:
              type:
                - string
                - 'null'
              description: ISO 3166-1 alpha-2.
          required:
            - street
            - postal_code
            - city
            - country_code
          description: Peppol Delivery/DeliveryLocation/Address.
      required:
        - name
        - address
      description: >-
        Where to deliver. Null delivers to the buyer's own address. Changing it
        on an opened order records a revision.
    PurchaseOrderBillingReview:
      type: object
      properties:
        amount_status:
          type: string
          enum:
            - unknown
            - not_invoiced
            - partial
            - at_value
            - over
        single_invoice:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              format: uuid
            number:
              type:
                - string
                - 'null'
          required:
            - id
            - number
        quantity:
          type: object
          properties:
            single_invoice_id:
              type:
                - string
                - 'null'
              format: uuid
            lines:
              type: integer
              minimum: 0
            invoices:
              type: integer
              minimum: 0
            amount:
              type:
                - string
                - 'null'
          required:
            - single_invoice_id
            - lines
            - invoices
            - amount
        received:
          type: object
          properties:
            single_invoice_id:
              type:
                - string
                - 'null'
              format: uuid
            lines:
              type: integer
              minimum: 0
            invoices:
              type: integer
              minimum: 0
            amount:
              type:
                - string
                - 'null'
          required:
            - single_invoice_id
            - lines
            - invoices
            - amount
          description: >-
            Invoiced within the order but above what was received, on orders
            that record receipts.
        unit_price:
          type: object
          properties:
            single_invoice_id:
              type:
                - string
                - 'null'
              format: uuid
            lines:
              type: integer
              minimum: 0
            invoices:
              type: integer
              minimum: 0
            amount:
              type:
                - string
                - 'null'
          required:
            - single_invoice_id
            - lines
            - invoices
            - amount
        vat_rate:
          type: object
          properties:
            single_invoice_id:
              type:
                - string
                - 'null'
              format: uuid
            lines:
              type: integer
              minimum: 0
            invoices:
              type: integer
              minimum: 0
            amount:
              type:
                - string
                - 'null'
          required:
            - single_invoice_id
            - lines
            - invoices
            - amount
          description: Invoiced at a higher VAT rate than the order line states.
        unmatched:
          type: object
          properties:
            single_invoice_id:
              type:
                - string
                - 'null'
              format: uuid
            lines:
              type: integer
              minimum: 0
            invoices:
              type: integer
              minimum: 0
            amount:
              type:
                - string
                - 'null'
          required:
            - single_invoice_id
            - lines
            - invoices
            - amount
        lines:
          type: array
          items:
            type: object
            properties:
              purchase_order_line_id:
                type: string
                format: uuid
              codes:
                type: array
                items:
                  type: string
                  enum:
                    - quantity
                    - received
                    - unit_price
                    - vat_rate
            required:
              - purchase_order_line_id
              - codes
          description: >-
            Order lines with an unresolved quantity, receipt, unit price or VAT
            rate finding, by the same predicates as the categories. A grouped
            invoice line names every order line it covers.
      required:
        - amount_status
        - single_invoice
        - quantity
        - received
        - unit_price
        - vat_rate
        - unmatched
        - lines
      description: >-
        Visible unresolved billing findings. Single invoice is exposed only when
        exactly one live accepted invoice exists and is accessible.
    PurchaseOrderLine:
      type: object
      properties:
        id:
          type: string
          format: uuid
        billed_amount:
          type: string
        invoice_summary:
          type:
            - object
            - 'null'
          properties:
            invoices:
              type: integer
              minimum: 0
            unit_price_min:
              type:
                - string
                - 'null'
            unit_price_max:
              type:
                - string
                - 'null'
            unit_price_difference:
              type:
                - string
                - 'null'
            price_difference_invoices:
              type:
                - integer
                - 'null'
              minimum: 0
            grouped_invoice_lines:
              type: array
              items:
                type: object
                properties:
                  invoice_id:
                    type: string
                    format: uuid
                  invoice_number:
                    type:
                      - string
                      - 'null'
                  invoice_item_id:
                    type: string
                    format: uuid
                  line_number:
                    type: integer
                  description:
                    type:
                      - string
                      - 'null'
                  purchase_order_line_ids:
                    type: array
                    items:
                      type: string
                      format: uuid
                    description: >-
                      Every order line the invoice line bills, this one
                      included.
                required:
                  - invoice_id
                  - invoice_number
                  - invoice_item_id
                  - line_number
                  - description
                  - purchase_order_line_ids
              description: >-
                Invoice lines that bill this line as part of a group, together
                with other lines of the order.
          required:
            - invoices
            - unit_price_min
            - unit_price_max
            - unit_price_difference
            - price_difference_invoices
            - grouped_invoice_lines
          description: >-
            Accepted invoices allocated to this line. Null if any invoice is
            restricted. Effective unit prices include line adjustments; a
            grouped invoice line counts what it bills this line. Null when units
            or quantities cannot be compared.
        invoice_check:
          type:
            - string
            - 'null'
          enum:
            - clean
            - findings
            - incomplete
            - null
          description: >-
            The purchase-order check's verdict on the accepted invoices that
            bill this line: findings when an open quantity or unit price finding
            names the line; clean when every one was checked completely without
            one; incomplete otherwise. Null when no accepted invoice bills the
            line, the line is cancelled, or an invoice is restricted.
        billed_quantity:
          type:
            - string
            - 'null'
        quantity_complete:
          type: boolean
        billed_unit:
          type:
            - string
            - 'null'
          description: >-
            The unit billed_quantity is in: the Peppol code, or the unit as
            written when it has none. A line without a unit takes the unit its
            billed invoice lines share.
        line_reference:
          type: string
          description: >-
            The line identifier as the supplier sees it (Peppol LineItem/ID).
            Never reused once the order is opened; lines are listed in their
            display order. Invoice lines are never matched on it.
        item:
          type: object
          properties:
            name:
              type: string
            description:
              type:
                - string
                - 'null'
            product_code:
              type:
                - string
                - 'null'
              description: The seller's article number.
            buyer_product_code:
              type:
                - string
                - 'null'
              description: The buyer's own article number.
          required:
            - name
            - description
            - product_code
            - buyer_product_code
        quantity:
          type: string
          pattern: ^-?\d+(?:\.\d+)?$
        unit:
          type:
            - string
            - 'null'
          description: As written, such as pcs or hours.
        unit_price:
          type: string
          pattern: ^-?\d+(?:\.\d+)?$
          description: >-
            The agreed net price per unit after the line's own discounts,
            excluding VAT. Zero or below on an allowance, zero or above on a
            charge.
        total_excluding_vat:
          type: string
          pattern: ^-?\d+(?:\.\d+)?$
          description: quantity × unit_price.
        vat_rate:
          type:
            - string
            - 'null'
          pattern: ^-?\d+(?:\.\d+)?$
          description: >-
            The VAT rate the supplier is to charge, as a fraction: 0.25 is 25 %.
            Null when the order states none. A term: an invoice line billing the
            line at a higher rate is a vat_rate finding.
        kind:
          type: string
          enum:
            - item
            - allowance
            - charge
          description: >-
            Peppol: item for goods or services; allowance for a discount and
            charge for a fee, freight or surcharge the document lists on its
            own. Neither names the lines it applies to, and neither is spread
            over them.
        gross_unit_price:
          type:
            - string
            - 'null'
          pattern: ^-?\d+(?:\.\d+)?$
          description: >-
            Peppol Price/AllowanceCharge/BaseAmount: the price per unit printed
            before the line's own discount, for display only; unit_price is the
            binding net price. Only on an item. Not part of the terms, so
            revisions leave it out.
        status:
          type: string
          enum:
            - active
            - cancelled
          description: >-
            A line removed from an opened order is cancelled; it keeps its ID
            and number.
        agreement_item_id:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            The agreement price the line was ordered from; null when it has none
            or you cannot see its agreement. Not part of the terms, so revisions
            leave it out.
        source_line_id:
          type:
            - string
            - 'null'
          description: >-
            The line's ID in the order's other system (source): the ERP's on an
            imported or pushed order, the caller's on a linked one. Not part of
            the terms, so revisions leave it out.
        coding:
          type:
            - object
            - 'null'
          properties:
            account:
              type:
                - object
                - 'null'
              properties:
                id:
                  type: string
                  format: uuid
                name:
                  type: string
                usable:
                  type: boolean
                  description: >-
                    Active and still in the chart of accounts; a line keeps a
                    code that went.
                number:
                  type:
                    - string
                    - 'null'
              required:
                - id
                - name
                - usable
                - number
            vat_code:
              type:
                - object
                - 'null'
              properties:
                id:
                  type: string
                  format: uuid
                name:
                  type: string
                usable:
                  type: boolean
                  description: >-
                    Active and still in the chart of accounts; a line keeps a
                    code that went.
                code:
                  type:
                    - string
                    - 'null'
                rate:
                  type:
                    - string
                    - 'null'
                  pattern: ^-?\d+(?:\.\d+)?$
              required:
                - id
                - name
                - usable
                - code
                - rate
            dimension_values:
              type: array
              items:
                type: object
                properties:
                  dimension_id:
                    type: string
                    format: uuid
                  dimension_name:
                    type: string
                  dimension_kind:
                    type: string
                    enum:
                      - department
                      - project
                      - custom
                    description: >-
                      The dimension's kind: a project's value fills the order's
                      project reference.
                  id:
                    type: string
                    format: uuid
                  name:
                    type: string
                  usable:
                    type: boolean
                    description: >-
                      Active and still in the chart of accounts; a line keeps a
                      code that went.
                  code:
                    type:
                      - string
                      - 'null'
                required:
                  - dimension_id
                  - dimension_name
                  - dimension_kind
                  - id
                  - name
                  - usable
                  - code
          required:
            - account
            - vat_code
            - dimension_values
          description: >-
            Where the line's cost is booked; null when it is not coded. An
            invoice line matched to the order line takes it as its coding
            suggestion. Not part of the terms, so revisions leave it out.
        received:
          type:
            - object
            - 'null'
          properties:
            quantity:
              type: string
              pattern: ^-?\d+(?:\.\d+)?$
              description: Everything received on the line, in `unit`.
            unit:
              type:
                - string
                - 'null'
              description: >-
                The unit the quantity counts, as written: the line's when it was
                recorded, unless receiving gave another.
            last_received_on:
              type: string
              format: date
              description: When the received quantity last changed.
          required:
            - quantity
            - unit
            - last_received_on
          description: >-
            Goods received on the line (recordPurchaseOrderReceipts); null until
            a total is recorded. Invoices billing more than was received are
            flagged on orders that record goods received, while the received
            unit agrees with the line's.
      required:
        - id
        - line_reference
        - item
        - quantity
        - unit
        - unit_price
        - total_excluding_vat
        - vat_rate
        - kind
        - status
    PurchaseOrderPushTarget:
      type: object
      properties:
        integration_id:
          type: string
          format: uuid
        integration_name:
          type: string
        system:
          type: string
          description: The accounting system, such as tripletex.
      required:
        - integration_id
        - integration_name
        - system
    PurchaseOrderLatestPush:
      type:
        - object
        - 'null'
      properties:
        workflow_run_id:
          type: string
          format: uuid
        integration_id:
          type:
            - string
            - 'null'
          format: uuid
        integration_name:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - queued
            - running
            - completed
            - completed_with_errors
            - failed
            - cancelled
        failure:
          type:
            - object
            - 'null'
          properties:
            code:
              type: string
            message:
              type: string
            overwritable:
              type: boolean
              description: >-
                Someone changed or deleted the order in the accounting system:
                pushing again with `overwrite` replaces their changes.
          required:
            - code
            - message
            - overwritable
      required:
        - workflow_run_id
        - integration_id
        - integration_name
        - status
        - failure
      description: The latest push of the order.
    PurchaseOrderToFill:
      oneOf:
        - type: object
          properties:
            field:
              type: string
              enum:
                - dimension
            message:
              type: string
            dimension_id:
              type: string
              format: uuid
              description: List its values with listDimensionValues dimension_ids.
            dimension_name:
              type: string
          required:
            - field
            - message
            - dimension_id
            - dimension_name
        - type: object
          properties:
            field:
              type: string
              enum:
                - agreement
            message:
              type: string
            suggestions:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                  title:
                    type:
                      - string
                      - 'null'
                  reason:
                    type: string
                    enum:
                      - contract_reference
                      - parties_and_term
                    description: >-
                      contract_reference: the agreement names the order's
                      contract reference. parties_and_term: it names the
                      supplier and buyer, and its term covers the order's dates.
                required:
                  - id
                  - title
                  - reason
          required:
            - field
            - message
            - suggestions
    PurchaseOrderSentToSupplier:
      type:
        - object
        - 'null'
      properties:
        channel:
          type: string
          enum:
            - email
          description: How it was sent.
        revision:
          type: integer
          description: The latest revision sent to the supplier.
        sent_at:
          type: string
          format: date-time
        pending:
          type: boolean
          description: >-
            The order changed since the supplier last got its terms: its
            revision is newer than supplier_revision.
      required:
        - channel
        - revision
        - sent_at
        - pending
      description: >-
        The latest revision sent to the supplier through Watchdog
        (sendPurchaseOrder), counting sends that went out or may have (accepted
        or unconfirmed emails); null when none went out.
    PurchaseOrderApproval:
      type:
        - object
        - 'null'
      properties:
        id:
          type: string
          format: uuid
          description: >-
            The approval request. Send it as approval.request_id to approve or
            reject it; it changes when the request is withdrawn and asked again.
        status:
          type: string
          enum:
            - pending
            - approved
            - rejected
          description: pending until one of the approvers approves or rejects it.
        sent:
          type: boolean
          description: >-
            Whether its approvers were asked. False while it only holds the
            approvers picked on a draft: opening the draft (status open) sends
            it. Only a sent request waits for approval or can be decided.
        revision:
          type: integer
          description: >-
            The revision it decides: 1 for a draft, which opens once approved,
            or the revision a proposed change would make.
        proposal_id:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            The proposed revision it decides (proposed_revision.id); null for a
            draft. Approving applies it, rejecting discards it, and the order's
            current revision stays in force meanwhile.
        approvers:
          type: array
          items:
            type: object
            properties:
              user_id:
                type: string
                minLength: 1
                maxLength: 200
                pattern: ^[A-Za-z0-9_-]+$
              first_name:
                type:
                  - string
                  - 'null'
              last_name:
                type:
                  - string
                  - 'null'
              email:
                type:
                  - string
                  - 'null'
              source:
                type: string
                enum:
                  - person
                  - rule
                description: '`person`: added by hand. `rule`: added by an approval rule.'
              decision:
                type:
                  - string
                  - 'null'
                enum:
                  - approved
                  - rejected
                  - null
            required:
              - user_id
              - first_name
              - last_name
              - email
              - source
              - decision
          description: >-
            In the order they were added. Any one of them decides. Empty while
            pending means no one can approve the order yet: add someone with
            updatePurchaseOrderApprovers.
        approver_teams:
          type: array
          items:
            type: object
            properties:
              team_id:
                type:
                  - string
                  - 'null'
                format: uuid
                description: Null when the team has been deleted since.
              name:
                type:
                  - string
                  - 'null'
                description: Null when the team has been deleted since.
              source:
                type: string
                enum:
                  - person
                  - rule
                description: '`person`: added by hand. `rule`: added by an approval rule.'
              decision:
                type:
                  - string
                  - 'null'
                enum:
                  - approved
                  - rejected
                  - null
              decided_by:
                type:
                  - object
                  - 'null'
                properties:
                  user_id:
                    type: string
                    minLength: 1
                    maxLength: 200
                    pattern: ^[A-Za-z0-9_-]+$
                  first_name:
                    type:
                      - string
                      - 'null'
                  last_name:
                    type:
                      - string
                      - 'null'
                  email:
                    type:
                      - string
                      - 'null'
                required:
                  - user_id
                  - first_name
                  - last_name
                  - email
                description: Who decided for the team; null until someone has.
              nobody_can_act:
                type: boolean
                description: >-
                  Nobody in the team can approve the order now: no member has
                  write access and can see it. Add someone to the team, or add
                  another approver. False once the team has decided or the
                  request is not pending.
              members:
                type: array
                items:
                  type: object
                  properties:
                    user_id:
                      type: string
                      minLength: 1
                      maxLength: 200
                      pattern: ^[A-Za-z0-9_-]+$
                    first_name:
                      type:
                        - string
                        - 'null'
                    last_name:
                      type:
                        - string
                        - 'null'
                    email:
                      type:
                        - string
                        - 'null'
                  required:
                    - user_id
                    - first_name
                    - last_name
                    - email
                description: >-
                  Who is in the team now: any of them with write access who can
                  see the order may decide for it.
            required:
              - team_id
              - name
              - source
              - decision
              - decided_by
              - nobody_can_act
              - members
          description: >-
            Teams asked to approve, in the order they were added; each counts as
            one approver.
        skipped_approvers:
          type: array
          items:
            type: object
            properties:
              user_id:
                type: string
                minLength: 1
                maxLength: 200
                pattern: ^[A-Za-z0-9_-]+$
              first_name:
                type:
                  - string
                  - 'null'
              last_name:
                type:
                  - string
                  - 'null'
              email:
                type:
                  - string
                  - 'null'
              reason:
                type: string
                enum:
                  - no_access
                  - no_write
                  - removed_by_hand
                description: >-
                  `no_access`: their access limits hide the order. `no_write`:
                  role without write access. `removed_by_hand`: a person removed
                  them.
            required:
              - user_id
              - first_name
              - last_name
              - email
              - reason
          description: >-
            People an approval rule names but did not add, while the request is
            pending.
        skipped_teams:
          type: array
          items:
            type: object
            properties:
              team_id:
                type: string
                format: uuid
              name:
                type: string
            required:
              - team_id
              - name
          description: >-
            Teams an approval rule names but did not add because nobody in them
            could approve the order, while the request is pending.
        requested_at:
          type: string
          format: date-time
        decided_at:
          type:
            - string
            - 'null'
          format: date-time
        decided_by:
          type:
            - object
            - 'null'
          properties:
            user_id:
              type: string
              minLength: 1
              maxLength: 200
              pattern: ^[A-Za-z0-9_-]+$
            first_name:
              type:
                - string
                - 'null'
            last_name:
              type:
                - string
                - 'null'
            email:
              type:
                - string
                - 'null'
          required:
            - user_id
            - first_name
            - last_name
            - email
        rejection_reason:
          type:
            - string
            - 'null'
          description: Why the order was rejected; null when no reason was given.
      required:
        - id
        - status
        - sent
        - revision
        - proposal_id
        - approvers
        - approver_teams
        - skipped_approvers
        - skipped_teams
        - requested_at
        - decided_at
        - decided_by
        - rejection_reason
      description: >-
        The order's approval request. A draft's latest: pending, or its
        decision. Past a draft, the one deciding a proposed revision while one
        waits, else the one that approved the terms in force. Null when it
        needed none (opened without approval, or imported), or a draft's request
        was withdrawn.
    PurchaseOrderImportState:
      type:
        - object
        - 'null'
      properties:
        id:
          type: string
          format: uuid
        intent:
          type:
            - string
            - 'null'
          enum:
            - new
            - placed
            - null
        missing:
          type: array
          items:
            $ref: '#/components/schemas/PurchaseOrderImportGap'
        printed:
          type: object
          properties:
            supplier:
              $ref: '#/components/schemas/PurchaseOrderPrintedParty'
            buyer:
              $ref: '#/components/schemas/PurchaseOrderPrintedParty'
          required:
            - supplier
            - buyer
          description: >-
            The supplier and buyer as the documents print them, to choose the
            right party on a draft. Null where the documents name none.
      required:
        - id
        - intent
        - missing
        - printed
      description: >-
        The import that drafted the order from documents: what they show
        (intent), what the draft still needs (missing) and the parties as
        printed. Null for an order created otherwise.
    PurchaseOrderProposedRevision:
      type:
        - object
        - 'null'
      properties:
        id:
          type: string
          format: uuid
          description: >-
            Send it as proposed_revision.id to accept or reject the proposed
            revision.
        revision:
          type:
            - integer
            - 'null'
          description: >-
            The revision it makes once accepted; null on a draft, whose
            supplier's reply proposes its lines.
        source:
          type: string
          enum:
            - member
            - supplier
          description: >-
            `member`: an edit that needs approval. `supplier`: read from a
            supplier's confirmation.
        decided_by:
          type: string
          enum:
            - approvers
            - members
          description: >-
            `approvers`: it needs approval, so the order's approval request
            decides it (approve or reject through approval). `members`: any
            member accepts or rejects it.
        prices_without_vat_basis:
          type: boolean
          description: >-
            The supplier's document stated no VAT basis, so its prices were read
            as excluding VAT. Check them before accepting.
        supplier_has_after_accept:
          type: boolean
          description: >-
            Accepting it leaves the supplier with the revision it makes: their
            own change to terms they had. Otherwise the order is sent to them
            afterwards.
        proposed_by:
          type:
            - object
            - 'null'
          properties:
            user_id:
              type: string
            first_name:
              type:
                - string
                - 'null'
            last_name:
              type:
                - string
                - 'null'
            email:
              type:
                - string
                - 'null'
          required:
            - user_id
            - first_name
            - last_name
            - email
          description: >-
            The person who proposed it; null for a confirmation read without
            one.
        document_ids:
          type: array
          items:
            type: string
            format: uuid
          description: The order's documents it was read from, attachments first.
        changes:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
              from:
                $ref: '#/components/schemas/ActivityValue'
              to:
                $ref: '#/components/schemas/ActivityValue'
            required:
              - field
              - from
              - to
            additionalProperties:
              $ref: '#/components/schemas/ActivityValue'
          description: >-
            Each changed term (`field`, `from`, `to`) and each added, changed or
            cancelled line (`field` line_items with `line_id`), as the order
            activity shows changes. Empty when it can no longer be shown against
            the order.
        currency_code:
          type:
            - string
            - 'null'
          description: >-
            The currency it gives the order, which `totals` are in; the order's
            own unless it changes it.
        totals:
          type: object
          properties:
            lines_excluding_vat:
              type: string
            commitment:
              type:
                - string
                - 'null'
          required:
            - lines_excluding_vat
            - commitment
        agreement_check:
          type:
            - object
            - 'null'
          properties:
            findings:
              type: array
              items:
                oneOf:
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - unit_price
                      target:
                        type: string
                      applicable:
                        type: boolean
                      line_key:
                        type: string
                      fingerprint:
                        type: string
                      evidence:
                        type: object
                        properties:
                          agreement_id:
                            type: string
                            format: uuid
                          price_item_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          document_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          terms:
                            type:
                              - string
                              - 'null'
                        required:
                          - agreement_id
                          - price_item_id
                          - document_id
                          - terms
                      current_unit_price:
                        type: string
                        pattern: ^-?\d+(?:\.\d+)?$
                      agreement_unit_price:
                        type: string
                        pattern: ^-?\d+(?:\.\d+)?$
                      quantity:
                        type: string
                        pattern: ^-?\d+(?:\.\d+)?$
                      amount_difference:
                        type: string
                        pattern: ^-?\d+(?:\.\d+)?$
                      unit_to_set:
                        type:
                          - string
                          - 'null'
                    required:
                      - code
                      - target
                      - applicable
                      - line_key
                      - fingerprint
                      - evidence
                      - current_unit_price
                      - agreement_unit_price
                      - quantity
                      - amount_difference
                      - unit_to_set
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - unit
                      target:
                        type: string
                      applicable:
                        type: boolean
                      line_key:
                        type: string
                      fingerprint:
                        type: string
                      evidence:
                        type: object
                        properties:
                          agreement_id:
                            type: string
                            format: uuid
                          price_item_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          document_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          terms:
                            type:
                              - string
                              - 'null'
                        required:
                          - agreement_id
                          - price_item_id
                          - document_id
                          - terms
                      current_unit:
                        type:
                          - string
                          - 'null'
                      agreement_unit:
                        type:
                          - string
                          - 'null'
                      current_unit_price:
                        type: string
                        pattern: ^-?\d+(?:\.\d+)?$
                      agreement_unit_price:
                        type:
                          - string
                          - 'null'
                        pattern: ^-?\d+(?:\.\d+)?$
                    required:
                      - code
                      - target
                      - applicable
                      - line_key
                      - fingerprint
                      - evidence
                      - current_unit
                      - agreement_unit
                      - current_unit_price
                      - agreement_unit_price
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - no_agreement_price
                      target:
                        type: string
                      applicable:
                        type: boolean
                      line_key:
                        type: string
                      fingerprint:
                        type: string
                    required:
                      - code
                      - target
                      - applicable
                      - line_key
                      - fingerprint
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - uncertain
                      target:
                        type: string
                      applicable:
                        type: boolean
                      line_key:
                        type: string
                      fingerprint:
                        type: string
                      evidence:
                        type: object
                        properties:
                          agreement_id:
                            type: string
                            format: uuid
                          price_item_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          document_id:
                            type:
                              - string
                              - 'null'
                            format: uuid
                          terms:
                            type:
                              - string
                              - 'null'
                        required:
                          - agreement_id
                          - price_item_id
                          - document_id
                          - terms
                      reason:
                        type: string
                        enum:
                          - calculation_rules
                          - rate_price
                          - ambiguous_price
                          - no_valid_price
                          - currency_mismatch
                          - no_order_currency
                      price_item_ids:
                        type: array
                        items:
                          type: string
                          format: uuid
                    required:
                      - code
                      - target
                      - applicable
                      - line_key
                      - fingerprint
                      - evidence
                      - reason
                      - price_item_ids
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - supplier
                      target:
                        type: string
                      applicable:
                        type: boolean
                      fingerprint:
                        type: string
                      supplier_id:
                        type: string
                        format: uuid
                    required:
                      - code
                      - target
                      - applicable
                      - fingerprint
                      - supplier_id
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - buyer
                      target:
                        type: string
                      applicable:
                        type: boolean
                      fingerprint:
                        type: string
                      buyer_id:
                        type: string
                        format: uuid
                    required:
                      - code
                      - target
                      - applicable
                      - fingerprint
                      - buyer_id
                  - type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - term
                      target:
                        type: string
                      applicable:
                        type: boolean
                      fingerprint:
                        type: string
                      fields:
                        type: array
                        items:
                          type: string
                          enum:
                            - issued_date
                            - valid_from
                            - valid_until
                        minItems: 1
                      effective_date:
                        type:
                          - string
                          - 'null'
                      expiration_date:
                        type:
                          - string
                          - 'null'
                    required:
                      - code
                      - target
                      - applicable
                      - fingerprint
                      - fields
                      - effective_date
                      - expiration_date
            lines:
              type: array
              items:
                type: object
                properties:
                  key:
                    type: string
                    description: The `line_id` of its line_items change.
                  outcome:
                    type: string
                    enum:
                      - no_difference
                      - differs
                      - not_checked
                  price_item_id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                  agreement_unit_price:
                    type:
                      - string
                      - 'null'
                  copied_from_agreement:
                    type: boolean
                  price_fingerprint:
                    type:
                      - string
                      - 'null'
                  terms:
                    type:
                      - string
                      - 'null'
                required:
                  - key
                  - outcome
                  - price_item_id
                  - agreement_unit_price
                  - copied_from_agreement
                  - price_fingerprint
                  - terms
          required:
            - findings
            - lines
          description: >-
            The proposed lines checked against the order's agreement, as
            getPurchaseOrderAgreementCheck checks the order's own; its findings
            cannot be applied. Null when the order has no agreement the caller
            can see.
        created_at:
          type: string
          format: date-time
      required:
        - id
        - revision
        - source
        - decided_by
        - prices_without_vat_basis
        - supplier_has_after_accept
        - proposed_by
        - document_ids
        - changes
        - currency_code
        - totals
        - agreement_check
        - created_at
      description: >-
        A change to the order's terms waiting for a decision: an edit that needs
        approval, or what a supplier's confirmation prints differently. The
        order keeps its current revision, which is what is sent and pushed,
        until it is accepted; its terms cannot change meanwhile. Null when none
        waits.
    PurchaseOrderSupplierReply:
      type: object
      properties:
        request:
          type:
            - object
            - 'null'
          properties:
            kind:
              type: string
              enum:
                - order
                - price_request
              description: 'order: the order was sent. price_request: a price was asked for.'
            sent_at:
              type: string
              format: date-time
              description: When it went out, or may have.
            sent_to:
              type: array
              items:
                type: string
              description: Its To addresses.
            replied_at:
              type:
                - string
                - 'null'
              format: date-time
              description: >-
                When the supplier's latest email after it arrived, at the reply
                address or forwarded by a member; null while it waits for an
                answer.
          required:
            - kind
            - sent_at
            - sent_to
            - replied_at
          description: >-
            The latest email that asked the supplier for something: the order,
            or a price. Messages ask for nothing, so they are not one. Null when
            none went out.
        confirmed_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the supplier confirmed the order's current terms: their
            confirmation matched them, or the changes it proposed were accepted.
            A member's change to the terms clears it; a later delivery notice or
            message does not. A draft they confirmed only needs opening.
      required:
        - request
        - confirmed_at
      description: >-
        What the order waits for from its supplier, and whether they confirmed
        it. Derived from the emails sent and the supplier's documents received.
    PurchaseOrderImportGap:
      type: object
      properties:
        field:
          type: string
          enum:
            - supplier
            - buyer
            - currency
            - lines
            - quantity
            - unit_price
            - price_basis
            - total
            - delivery_date
            - delivery
            - other
            - sources
          description: >-
            What the draft still needs. supplier, buyer, currency and lines
            follow the order as it is now, as does unit_price: a line whose
            price the documents left out and that is still zero. The others are
            notes from reading the documents, shown while the order is a draft:
            quantity, price_basis (VAT), total (the lines differ from the
            printed total by more than 1), delivery_date, delivery, sources
            (files not read in full: past the reading limit, too large, an email
            that cannot be parsed, an attachment left out, or text read in part
            as "name (read / total characters)"; named in note) and other.
        line_id:
          type:
            - string
            - 'null'
          format: uuid
          description: The line it concerns; null for the order.
        note:
          type:
            - string
            - 'null'
          description: >-
            What the documents showed, in the organization language; null when
            the field says it all.
      required:
        - field
        - line_id
        - note
    PurchaseOrderPrintedParty:
      type:
        - object
        - 'null'
      properties:
        name:
          type:
            - string
            - 'null'
        organization_number:
          type:
            - string
            - 'null'
        vat_number:
          type:
            - string
            - 'null'
      required:
        - name
        - organization_number
        - vat_number
    ActivityValue:
      type:
        - string
        - number
        - boolean
        - 'null'
        - array
        - object
      items:
        $ref: '#/components/schemas/ActivityValue'
      additionalProperties:
        $ref: '#/components/schemas/ActivityValue'
  securitySchemes:
    ApiKeyBearer:
      type: http
      scheme: bearer
      description: >-
        Personal API key sent as a bearer token, together with
        X-Organization-Id. The key must have at least the access level the
        endpoint requires (read, write or admin).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.