> ## 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.

# Code invoice lines

> Coding is how the invoice posts in the accounting system: an account, a VAT code and dimension values per line, from the organization’s vocabulary, which its accounting connections sync (list it with listLedgerAccounts, listVatCodes and listDimensionValues). Sets the account, VAT code or dimension values of one line, all existing lines with line_item_id: all, or selected lines with an array of line IDs. All-line and selected-line edits are atomic and preserve every field left out, including VAT and dimensions when changing the account; incompatible VAT codes are refused rather than replaced. Single-line account edits retain their existing automatic VAT and dimension defaults. Only active codes of the organization’s connection can be set. Once the invoice is sent for approval (locked), only its approvers, the AP team and admins change its coding, approvals given stay, and the line must stay complete and valid: change a value, remove an optional dimension, or switch account with the dimensions it requires in the same request; removing the account, the VAT code or a required dimension returns 400. Once it is in its accounting system its coding no longer changes (409). The change is recorded in the invoice’s activity.



## OpenAPI

````yaml /openapi.json patch /v1/invoices/{id}/coding
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/invoices/{id}/coding:
    patch:
      tags:
        - Invoices
      summary: Code invoice lines
      description: >-
        Coding is how the invoice posts in the accounting system: an account, a
        VAT code and dimension values per line, from the organization’s
        vocabulary, which its accounting connections sync (list it with
        listLedgerAccounts, listVatCodes and listDimensionValues). Sets the
        account, VAT code or dimension values of one line, all existing lines
        with line_item_id: all, or selected lines with an array of line IDs.
        All-line and selected-line edits are atomic and preserve every field
        left out, including VAT and dimensions when changing the account;
        incompatible VAT codes are refused rather than replaced. Single-line
        account edits retain their existing automatic VAT and dimension
        defaults. Only active codes of the organization’s connection can be set.
        Once the invoice is sent for approval (locked), only its approvers, the
        AP team and admins change its coding, approvals given stay, and the line
        must stay complete and valid: change a value, remove an optional
        dimension, or switch account with the dimensions it requires in the same
        request; removing the account, the VAT code or a required dimension
        returns 400. Once it is in its accounting system its coding no longer
        changes (409). The change is recorded in the invoice’s activity.
      operationId: updateInvoiceCoding
      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.
        - schema:
            type: string
            format: uuid
          required: true
          name: id
          in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoiceCodingPatch'
      responses:
        '200':
          description: The invoice’s coding.
          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/InvoiceCoding'
        '400':
          description: >-
            A code is not an active one of the connection, the line does not
            fit, or the invoice is sent for approval and the line would not be
            complete and valid.
          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: >-
                    A code is not an active one of the connection, the line does
                    not fit, or the invoice is sent for approval and the line
                    would not be complete and valid.
                  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'
        '409':
          description: >-
            The invoice is deleted or in its accounting system, the organization
            has no connection to code with, or other work is changing the
            invoice (retry).
          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: conflict
                  message: >-
                    The invoice is deleted or in its accounting system, the
                    organization has no connection to code with, or other work
                    is changing the invoice (retry).
                  request_id: req_example
              schema:
                $ref: '#/components/schemas/Error_conflict'
        '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:
    InvoiceCodingPatch:
      type: object
      properties:
        line_item_id:
          anyOf:
            - type: string
              format: uuid
            - type: string
              enum:
                - all
            - type: array
              items:
                type: string
                format: uuid
              minItems: 1
            - type: 'null'
          description: >-
            The line to code; null for an invoice without lines; all targets
            every existing line; an array targets those line IDs. All and array
            edits apply only supplied fields in one transaction.
        ledger_account_id:
          type:
            - string
            - 'null'
          format: uuid
        vat_code_id:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            For a single-line edit, left out with a new account, the account’s
            default VAT code replaces a missing or disallowed one. For all or
            selected lines, left out preserves each line’s VAT code and
            incompatible values are refused.
        dimension_values:
          type: array
          items:
            type: object
            properties:
              dimension_id:
                type: string
                format: uuid
              value_id:
                type:
                  - string
                  - 'null'
                format: uuid
            required:
              - dimension_id
              - value_id
          maxItems: 50
          description: >-
            Sets or clears (null) the value of each dimension named; others keep
            theirs.
      required:
        - line_item_id
    InvoiceCoding:
      type: object
      properties:
        state:
          type: string
          enum:
            - ready
            - needs_input
            - invalid
            - unavailable
            - booked
          description: >-
            The worst state of its lines; unavailable without accounts payable
            or synced accounts; booked once the accounting system has posted its
            booking (see voucher), which is its coding: no lines, nothing to
            fill and nothing suggested.
        open_field_count:
          type: integer
          description: Missing fields across the lines.
        nothing_to_post:
          type: boolean
          description: >-
            The invoice’s total is 0 and every line is not_booked. It needs no
            coding, and is transferred without a supplier invoice: as a plain
            voucher with its documents, or not at all when the accounting system
            refuses that.
        suggesting:
          type: boolean
          description: >-
            Whether Watchdog is still making the invoice’s coding suggestions,
            after it arrived or a person asked again. They are written all at
            once; read the coding again when the invoice_coding_suggestions
            workflow ends.
        dimensions:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              kind:
                type: string
                enum:
                  - department
                  - project
                  - custom
              name:
                type: string
              is_active:
                type: boolean
            required:
              - id
              - kind
              - name
              - is_active
          description: >-
            The organization’s active dimensions, in the accounting system’s
            order.
        lines:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceCodingLine'
        groups:
          type: array
          items:
            type: object
            properties:
              ledger_account_id:
                type:
                  - string
                  - 'null'
                format: uuid
              vat_code_id:
                type:
                  - string
                  - 'null'
                format: uuid
              dimension_value_ids:
                type: array
                items:
                  type: string
                  format: uuid
              line_item_ids:
                type: array
                items:
                  type: string
                  format: uuid
              total_excluding_vat:
                type: string
            required:
              - ledger_account_id
              - vat_code_id
              - dimension_value_ids
              - line_item_ids
              - total_excluding_vat
          description: 'The lines grouped by identical coding: each group posts as one.'
        voucher:
          $ref: '#/components/schemas/InvoiceCodingVoucher'
      required:
        - state
        - open_field_count
        - nothing_to_post
        - suggesting
        - dimensions
        - lines
        - groups
        - voucher
    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_conflict:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - conflict
            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
    InvoiceCodingLine:
      type: object
      properties:
        line_item_id:
          type:
            - string
            - 'null'
          format: uuid
          description: Null for the one row of an invoice without lines.
        line_number:
          type:
            - integer
            - 'null'
        total_excluding_vat:
          type:
            - string
            - 'null'
        account:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              format: uuid
            number:
              type: string
            name:
              type: string
            is_active:
              type: boolean
            default_vat_code_id:
              type:
                - string
                - 'null'
              format: uuid
            vat_locked:
              type: boolean
            allowed_vat_code_ids:
              type: array
              items:
                type: string
                format: uuid
              description: The VAT codes a posting may use. Empty when any is allowed.
            required_dimension_ids:
              type: array
              items:
                type: string
                format: uuid
              description: The dimensions every posting on the account must carry.
          required:
            - id
            - number
            - name
            - is_active
            - default_vat_code_id
            - vat_locked
            - allowed_vat_code_ids
            - required_dimension_ids
        vat_code:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              format: uuid
            code:
              type: string
            name:
              type: string
            rate:
              type:
                - string
                - 'null'
            is_active:
              type: boolean
          required:
            - id
            - code
            - name
            - rate
            - is_active
        dimension_values:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              dimension_id:
                type: string
                format: uuid
              code:
                type:
                  - string
                  - 'null'
              name:
                type: string
              is_active:
                type: boolean
            required:
              - id
              - dimension_id
              - code
              - name
              - is_active
        state:
          type: string
          enum:
            - ready
            - needs_input
            - invalid
          description: >-
            ready: it can post. needs_input: a field is missing (open_fields).
            invalid: a code cannot be used (problems).
        open_fields:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                enum:
                  - account
                  - vat_code
                  - dimension
              dimension_id:
                type:
                  - string
                  - 'null'
                format: uuid
                description: The dimension, for a dimension field.
            required:
              - field
              - dimension_id
          description: >-
            Fields the line cannot post without: the account, VAT code and
            required dimensions.
        not_booked:
          type: boolean
          description: >-
            The line’s amount excluding VAT is 0: it books nothing, so it needs
            no coding and no posting is written for it. Coding set on it is kept
            and shown, but never required or judged.
        expected_fields:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                enum:
                  - account
                  - vat_code
                  - dimension
              dimension_id:
                type:
                  - string
                  - 'null'
                format: uuid
                description: The dimension, for a dimension field.
            required:
              - field
              - dimension_id
          description: >-
            Empty dimensions the line is expected to carry (dimension_needs):
            recent similar bookings almost always did. It can post without them.
        dimension_needs:
          type: array
          items:
            type: object
            properties:
              dimension_id:
                type: string
                format: uuid
              need:
                type: string
                enum:
                  - required
                  - expected
                  - optional
                description: >-
                  required: the account requires it. expected: recent similar
                  bookings (the same line, else the supplier on the account,
                  else the account) almost always carried it. optional: they
                  sometimes did.
              alternatives:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      format: uuid
                    code:
                      type:
                        - string
                        - 'null'
                    name:
                      type: string
                    invoice_count:
                      type: integer
                      description: Recent similar invoices booked to this value.
                  required:
                    - id
                    - code
                    - name
                    - invoice_count
                description: Other values history used, most used first; at most two.
            required:
              - dimension_id
              - need
              - alternatives
          description: >-
            The dimensions the line should carry, as Watchdog decided when it
            last suggested its coding or a person set its account. Dimensions
            not listed are not expected.
        problems:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                enum:
                  - account
                  - vat_code
                  - dimension
              dimension_id:
                type:
                  - string
                  - 'null'
                format: uuid
                description: The dimension, for a dimension field.
              reason:
                type: string
                enum:
                  - inactive
                  - removed
                  - vat_not_allowed
                description: >-
                  inactive or removed in the accounting system; vat_not_allowed:
                  the account does not allow the VAT code.
            required:
              - field
              - dimension_id
              - reason
        source:
          type:
            - string
            - 'null'
          enum:
            - manual
            - suggested
            - null
          description: >-
            Who last wrote the line: a person, or suggestions. Null while
            nothing is set.
        fields:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceCodingFieldSource'
          description: >-
            Where each field’s value came from: every set field, and every field
            a suggestion was made for.
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_by_user_id:
          type:
            - string
            - 'null'
      required:
        - line_item_id
        - line_number
        - total_excluding_vat
        - account
        - vat_code
        - dimension_values
        - state
        - open_fields
        - not_booked
        - expected_fields
        - dimension_needs
        - problems
        - source
        - fields
        - updated_at
        - updated_by_user_id
    InvoiceCodingVoucher:
      type: object
      properties:
        status:
          type: string
          enum:
            - draft
            - sent
            - booked
          description: >-
            draft: Watchdog’s postings from its coding, not booked yet. sent:
            approved and sent to the accounting system, no booking read back
            yet; still Watchdog’s postings. booked: the accounting system’s own
            postings, read back from it.
        source_system:
          type:
            - string
            - 'null'
          description: The accounting system that booked it; null unless booked.
        system_name:
          type:
            - string
            - 'null'
          description: >-
            Its display name, such as Tripletex; null unless booked or when
            unknown.
        number:
          type:
            - string
            - 'null'
          description: The voucher number there; null unless booked.
        url:
          type:
            - string
            - 'null'
          format: uri
          description: >-
            Opens the booked voucher in the accounting system's web app, for
            someone signed in there; null unless booked, or when Watchdog knows
            no web address for that system or connection.
        company_currency:
          type:
            - string
            - 'null'
          description: >-
            ISO 4217 code of the currency the booked voucher is in (the
            company’s, such as NOK), its postings’ company_amount; null unless
            booked and stated.
        postings:
          type: array
          items:
            type: object
            properties:
              kind:
                type: string
                enum:
                  - cost
                  - supplier
                  - customer
                  - system
                description: >-
                  cost: an account, VAT code and dimensions coded for lines.
                  supplier: the supplier’s credit for the total plus any
                  rounding. system: on a booked voucher, rows the accounting
                  system adds itself (VAT, rounding); on a draft, the rounding
                  the invoice states, its account set when sent. customer: only
                  on a booked voucher.
              account:
                type:
                  - object
                  - 'null'
                properties:
                  id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      The code in the organization’s vocabulary; null when the
                      booking names one Watchdog has not synced.
                  code:
                    type:
                      - string
                      - 'null'
                    description: The account number or VAT code.
                  name:
                    type:
                      - string
                      - 'null'
                required:
                  - id
                  - code
                  - name
                description: >-
                  Null on a draft posting whose lines have no account yet, and
                  on a draft's rounding, whose account the accounting system
                  names when it is sent.
              vat_code:
                type:
                  - object
                  - 'null'
                properties:
                  id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      The code in the organization’s vocabulary; null when the
                      booking names one Watchdog has not synced.
                  code:
                    type:
                      - string
                      - 'null'
                    description: The account number or VAT code.
                  name:
                    type:
                      - string
                      - 'null'
                required:
                  - id
                  - code
                  - name
                description: >-
                  Null on the supplier posting and on a draft posting whose
                  lines have no VAT code yet.
              dimensions:
                type: array
                items:
                  type: object
                  properties:
                    dimension_id:
                      type:
                        - string
                        - 'null'
                      format: uuid
                    dimension:
                      type: string
                      description: The dimension’s name.
                    value_id:
                      type:
                        - string
                        - 'null'
                      format: uuid
                    code:
                      type:
                        - string
                        - 'null'
                    name:
                      type:
                        - string
                        - 'null'
                  required:
                    - dimension_id
                    - dimension
                    - value_id
                    - code
                    - name
              amount:
                type:
                  - string
                  - 'null'
                description: >-
                  Excluding VAT; null on a draft of an invoice without lines,
                  whose net is unknown.
              amount_gross:
                type:
                  - string
                  - 'null'
                description: Including VAT.
              currency:
                type:
                  - string
                  - 'null'
                description: >-
                  ISO 4217 code of amount and amount_gross where the accounting
                  system states it (Tripletex states it on every posting, NOK on
                  the VAT postings it generates for a foreign-currency invoice);
                  null when unstated, in which case they are in the invoice’s
                  currency.
              company_amount:
                type:
                  - string
                  - 'null'
                description: >-
                  Booked only: excluding VAT, in the currency the voucher is
                  booked in (company_currency); null when the accounting system
                  states none.
              company_amount_gross:
                type:
                  - string
                  - 'null'
                description: 'Booked only: including VAT, in company_currency.'
              line_item_ids:
                type: array
                items:
                  type: string
                  format: uuid
                description: >-
                  The lines the posting books: on a draft, the lines summed into
                  it; on a booked voucher, the lines Watchdog linked it to
                  (often none).
            required:
              - kind
              - account
              - vat_code
              - dimensions
              - amount
              - amount_gross
              - currency
              - company_amount
              - company_amount_gross
              - line_item_ids
          description: >-
            Draft and sent: Watchdog’s lines with an amount summed per account,
            VAT code and dimension values, then the supplier posting; amounts
            are not yet rounded as a transfer rounds them. Booked: the
            accounting system’s postings in its order.
        differences:
          type: array
          items:
            type: object
            properties:
              posting:
                type: integer
                description: The index of the booked posting in postings.
              field:
                type: string
                enum:
                  - account
                  - vat_code
                  - dimension
              dimension_id:
                type:
                  - string
                  - 'null'
                format: uuid
              dimension:
                type:
                  - string
                  - 'null'
                description: The dimension’s name, for a dimension.
              booked:
                type:
                  - object
                  - 'null'
                properties:
                  id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      The code in the organization’s vocabulary; null when the
                      booking names one Watchdog has not synced.
                  code:
                    type:
                      - string
                      - 'null'
                    description: The account number or VAT code.
                  name:
                    type:
                      - string
                      - 'null'
                required:
                  - id
                  - code
                  - name
                description: >-
                  What the accounting system booked; null when it left the
                  dimension empty.
              watchdog:
                type:
                  - object
                  - 'null'
                properties:
                  id:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      The code in the organization’s vocabulary; null when the
                      booking names one Watchdog has not synced.
                  code:
                    type:
                      - string
                      - 'null'
                    description: The account number or VAT code.
                  name:
                    type:
                      - string
                      - 'null'
                required:
                  - id
                  - code
                  - name
                description: >-
                  Watchdog’s coding of the posting’s lines; null when it has no
                  value for the dimension.
            required:
              - posting
              - field
              - dimension_id
              - dimension
              - booked
              - watchdog
          description: >-
            Booked only: where a cost posting disagrees with Watchdog’s coding
            of the lines it books (its linked lines, or every line when it is
            the only cost posting). Compared only when Watchdog coded all those
            lines alike and the booking’s value is synced.
      required:
        - status
        - source_system
        - system_name
        - number
        - url
        - company_currency
        - postings
        - differences
      description: >-
        The voucher the invoice posts as: Watchdog’s draft from the coding
        above, or the accounting system’s booking compared with it.
    InvoiceCodingFieldSource:
      type: object
      properties:
        field:
          type: string
          enum:
            - account
            - vat_code
            - dimension
        dimension_id:
          type:
            - string
            - 'null'
          format: uuid
          description: The dimension, for a dimension field.
        source:
          type: string
          enum:
            - suggested
            - confirmed
            - changed
            - manual
          description: >-
            suggested: Watchdog suggested the value and no one has acted on it.
            confirmed: a person kept the suggested value. changed: a person
            replaced or cleared the suggestion. manual: a person set it without
            a suggestion.
        reason:
          oneOf:
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - precedent
                rule:
                  type: string
                  enum:
                    - same_line
                    - same_supplier_account
                    - same_supplier
                    - usual_on_account
                  description: >-
                    same_line: the supplier’s earlier lines of the same kind
                    were booked to this account, VAT code or dimension value
                    (for a dimension, on at least three in four of them).
                    same_supplier_account: the supplier’s earlier invoices on
                    this line’s account were booked to this dimension value on
                    at least three in four. same_supplier: the supplier’s
                    earlier invoices on any account were. usual_on_account: the
                    organization books this line’s account to this dimension
                    value on at least three in four invoices.
                invoice_count:
                  type: integer
                  description: How many earlier invoices agree.
                certainty:
                  type:
                    - string
                    - 'null'
                  enum:
                    - sure
                    - check
                    - null
                  description: >-
                    Decided by code after the invoice-coding agent reviewed the
                    line. sure: the agent kept this rule value. check: it did
                    not review it, for example when its run ran out of time.
                    Null on values the agent has not reviewed.
              required:
                - proposer
                - rule
                - invoice_count
                - certainty
              description: The supplier’s earlier bookings.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - reference
                field:
                  type: string
                  enum:
                    - buyer_reference
                    - order_reference
                    - accounting_cost
                    - project_reference
                    - contract_reference
                    - delivery_name
                    - delivery_address
                    - recipient_address
                    - recipient_name
                    - recipient_department
                    - seller_reference
                  description: >-
                    The invoice field. order_reference is one of its order
                    references; an address is its street and postal code.
                value:
                  type: string
                  description: The field’s value, as this invoice holds it.
                invoice_count:
                  type: integer
                  description: How many earlier invoices agree.
                certainty:
                  type:
                    - string
                    - 'null'
                  enum:
                    - sure
                    - check
                    - null
                  description: >-
                    Decided by code after the invoice-coding agent reviewed the
                    line. sure: the agent kept this rule value. check: it did
                    not review it, for example when its run ran out of time.
                    Null on values the agent has not reviewed.
              required:
                - proposer
                - field
                - value
                - invoice_count
                - certainty
              description: >-
                Every earlier booked invoice with the same value in one of this
                invoice’s fields was booked to this dimension value.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - order_line
                purchase_order_id:
                  type:
                    - string
                    - 'null'
                  format: uuid
                  description: Null when the order is restricted.
                number:
                  type:
                    - string
                    - 'null'
                  description: >-
                    The order's number; null on one without, or when it is
                    restricted.
                line_reference:
                  type:
                    - string
                    - 'null'
                  description: >-
                    The order line's reference; null when the value is the
                    order's own coding, or the order is restricted.
                restricted:
                  type: boolean
                  description: >-
                    The order is outside your access, so it is cited without
                    naming it.
              required:
                - proposer
                - purchase_order_id
                - number
                - line_reference
                - restricted
              description: >-
                The purchase order line the invoice line bills, or the order
                itself for a dimension the line leaves open, was coded so when
                it was ordered. It ranks above every other suggestion, and the
                agent keeps it.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - order
                purchase_order_id:
                  type:
                    - string
                    - 'null'
                  format: uuid
                  description: Null when the order is restricted.
                number:
                  type:
                    - string
                    - 'null'
                  description: >-
                    The order's number; null on one without, or when it is
                    restricted.
                restricted:
                  type: boolean
                  description: >-
                    The order is outside your access, so it is cited without
                    naming it.
                certainty:
                  type:
                    - string
                    - 'null'
                  enum:
                    - sure
                    - check
                    - null
                  description: >-
                    Decided by code after the invoice-coding agent reviewed the
                    line. sure: the agent kept this rule value. check: it did
                    not review it, for example when its run ran out of time.
                    Null on values the agent has not reviewed.
              required:
                - proposer
                - purchase_order_id
                - number
                - restricted
                - certainty
              description: >-
                The invoice line bills the purchase order as a whole, and the
                order was coded so when it was ordered: every active line of a
                blanket order, or the order itself. It ranks above the other
                rules; the agent may replace it.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - agent
                certainty:
                  type: string
                  enum:
                    - sure
                    - check
                  description: >-
                    Decided by code from the supplier’s history and the rules,
                    never by the model. sure: the supplier’s history backs the
                    account; on a sure account, the VAT code the account gives
                    the line (else the supplier’s usual one) at the line’s rate,
                    or the supplier’s usual dimension value. check: anything
                    else and every override of a rule’s value; worth a look
                    before approving.
                history:
                  type:
                    - object
                    - 'null'
                  properties:
                    same_kind_lines:
                      type: integer
                      description: >-
                        The supplier’s earlier lines like this one (by text)
                        booked to the account.
                    same_kind_total:
                      type: integer
                      description: >-
                        The supplier’s earlier lines like this one, on any
                        account.
                    account_invoices:
                      type: integer
                      description: The supplier’s earlier invoices booked to the account.
                    supplier_invoices:
                      type: integer
                      description: The supplier’s earlier invoices.
                  required:
                    - same_kind_lines
                    - same_kind_total
                    - account_invoices
                    - supplier_invoices
                  description: >-
                    For an account, the supplier’s bookings before this invoice
                    that code counted to decide certainty; all 0 without any.
                    Null for a VAT code or dimension value.
                overrode:
                  type:
                    - object
                    - 'null'
                  properties:
                    proposer:
                      type: string
                      enum:
                        - precedent
                        - reference
                        - order
                        - vat
                        - dimension_default
                      description: The rule that proposed the value the agent replaced.
                    value_id:
                      type: string
                      description: The value the rule proposed.
                  required:
                    - proposer
                    - value_id
                  description: >-
                    The rule’s value the agent replaced; null when it filled an
                    empty field.
              required:
                - proposer
                - certainty
                - history
                - overrode
              description: >-
                The invoice-coding agent chose the value (an account, VAT code
                or dimension value) for an empty field, or replaced a rule’s
                value.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - vat
                rule:
                  type: string
                  enum:
                    - locked
                    - default
                    - reverse_charge
                  description: >-
                    locked: the account allows only this VAT code. default: the
                    account’s default VAT code, whose rate is the line’s.
                    reverse_charge: the account’s code for services bought from
                    abroad, on a 0 % line from a foreign supplier.
                certainty:
                  type:
                    - string
                    - 'null'
                  enum:
                    - sure
                    - check
                    - null
                  description: >-
                    Decided by code after the invoice-coding agent reviewed the
                    line. sure: the agent left the VAT code to the line’s
                    account, which is sure and gives this code at the line’s
                    rate. check: anything else, for example when its run ran out
                    of time. Null on values the agent has not reviewed.
              required:
                - proposer
                - rule
                - certainty
              description: The line’s account sets the VAT code.
            - type: object
              properties:
                proposer:
                  type: string
                  enum:
                    - dimension_default
                source_value_id:
                  type: string
                  format: uuid
                  description: >-
                    The dimension value on the line (a project) whose default
                    this is.
                certainty:
                  type:
                    - string
                    - 'null'
                  enum:
                    - sure
                    - check
                    - null
                  description: >-
                    Decided by code after the invoice-coding agent reviewed the
                    line. sure: the value it follows is sure, and the agent kept
                    this one or it was filled after the agent. check: anything
                    else. Null on values the agent has not reviewed.
              required:
                - proposer
                - source_value_id
                - certainty
              description: >-
                Another of the line’s dimension values (a project) sets this
                dimension in the accounting system: its default value there.
            - type: 'null'
          description: What a suggestion was based on. Null for manual.
      required:
        - field
        - dimension_id
        - source
        - reason
  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.