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

# Declare what happened

> After acting: a case opened or closed, a contact made, how an effect ended, a commitment, a handoff, a suppression added or lifted. With an `Idempotency-Key`.



## OpenAPI

````yaml openapi/en/cell.json POST /v1/coordination/declare
openapi: 3.1.0
info:
  title: Niadra data API
  version: '1'
  description: >-
    Writing, context, history, objects, identity, privacy and governance of one
    space. Every space has a stable address, with the space and the region in
    its name.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: The space, which comes in the source key.
      region:
        default: us-east-2
        description: The region of the space, which also comes in the key.
security: []
paths:
  /v1/coordination/declare:
    post:
      tags:
        - coordination
      summary: Declare what happened
      description: >-
        What happened after the fact: a case opened or closed, an owner lease, a
        task lock, a contact that left (`contact.made`, with the token's `jti`),
        how a reserved effect ended, a commitment made, withdrawn or decided, a
        handoff that moved, a suppression added or lifted. A declaration never
        fails for the order it arrives in; a `contact.made` for a decision no
        longer held is still recorded.


        **Authentication.** Source key: `Authorization: Bearer nia_sk_...`.
        Required scope: `coordinate`. It answers only in a space with the
        `coordination` feature on (the `features` document); in a space without
        it, 404.
      operationId: declare_v1_coordination_declare_post
      parameters:
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            maxLength: 256
            minLength: 1
            title: Idempotency-Key
            type: string
          description: >-
            Required. Kept 24 hours with the hash of the body: a retry with the
            same key returns the first answer, and the same key with a different
            body returns 409 `conflict`.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeclareRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeclareResult'
          description: >-
            The declaration was recorded; `accepted` says whether a commitment
            holds.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
        '503':
          description: '`coordination_unavailable`: nothing new was recorded, send it again.'
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: >-
            # One farewell per conversation: the check reserved the effect, the
            declaration settles it

            key = f"farewell:{conversation.conversation_id}"

            decision = conversation.check("farewell", purpose="service",
            effect_key=key)

            if decision.decision == "allow" and decision.effect and
            decision.effect.state == "none":
                try:
                    send(farewell)
                    conversation.declare.effect(key, "done")
                except TimeoutError:
                    conversation.declare.effect(key, "unknown_outcome")  # never sent again on its own
        - lang: typescript
          label: TypeScript
          source: >-
            // One farewell per conversation: the check reserved the effect, the
            declaration settles it

            const key = `farewell:${convo.id}`;

            const decision = await convo.check("farewell", { purpose: "service",
            effectKey: key });

            if (decision.decision === "allow" && decision.effect?.state ===
            "none") {
              try {
                await send(farewell);
                convo.declare.effect(key, "done");
              } catch {
                convo.declare.effect(key, "unknown_outcome"); // never sent again on its own
              }
            }
components:
  schemas:
    DeclareRequest:
      description: >-
        What happened, after the fact: one kind of declaration, with the fields
        of its kind in `detail` (the

        coordination spec, 5).
      discriminator:
        mapping:
          case.closed:
            $ref: '#/components/schemas/CaseClosed'
          case.opened:
            $ref: '#/components/schemas/CaseOpened'
          commitment.decided:
            $ref: '#/components/schemas/CommitmentDecided'
          commitment.made:
            $ref: '#/components/schemas/CommitmentMade'
          commitment.withdrawn:
            $ref: '#/components/schemas/CommitmentWithdrawn'
          contact.made:
            $ref: '#/components/schemas/ContactMade'
          effect:
            $ref: '#/components/schemas/EffectDeclared'
          handoff:
            $ref: '#/components/schemas/HandoffDeclared'
          lease:
            $ref: '#/components/schemas/LeaseDeclared'
          suppression.added:
            $ref: '#/components/schemas/SuppressionAdded'
          suppression.lifted:
            $ref: '#/components/schemas/SuppressionLifted'
          task_lock:
            $ref: '#/components/schemas/TaskLockDeclared'
        propertyName: kind
      oneOf:
        - $ref: '#/components/schemas/CaseOpened'
        - $ref: '#/components/schemas/CaseClosed'
        - $ref: '#/components/schemas/LeaseDeclared'
        - $ref: '#/components/schemas/TaskLockDeclared'
        - $ref: '#/components/schemas/ContactMade'
        - $ref: '#/components/schemas/EffectDeclared'
        - $ref: '#/components/schemas/CommitmentMade'
        - $ref: '#/components/schemas/CommitmentWithdrawn'
        - $ref: '#/components/schemas/CommitmentDecided'
        - $ref: '#/components/schemas/HandoffDeclared'
        - $ref: '#/components/schemas/SuppressionAdded'
        - $ref: '#/components/schemas/SuppressionLifted'
      title: DeclareRequest
    DeclareResult:
      additionalProperties: false
      properties:
        accepted:
          title: Accepted
          type: boolean
        decision_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Decision Id
      required:
        - accepted
      title: DeclareResult
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    CaseClosed:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/ReleaseDetail'
        kind:
          const: case.closed
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CaseClosed
      type: object
    CaseOpened:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/LeaseDetail'
        kind:
          const: case.opened
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CaseOpened
      type: object
    CommitmentDecided:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentDecidedDetail'
        kind:
          const: commitment.decided
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentDecided
      type: object
    CommitmentMade:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentMadeDetail'
        kind:
          const: commitment.made
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentMade
      type: object
    CommitmentWithdrawn:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/CommitmentWithdrawnDetail'
        kind:
          const: commitment.withdrawn
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: CommitmentWithdrawn
      type: object
    ContactMade:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/ContactMadeDetail'
        kind:
          const: contact.made
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: ContactMade
      type: object
    EffectDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/EffectDetail'
        kind:
          const: effect
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: EffectDeclared
      type: object
    HandoffDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/HandoffDetail'
        kind:
          const: handoff
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: HandoffDeclared
      type: object
    LeaseDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/LeaseDetail'
        kind:
          const: lease
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: LeaseDeclared
      type: object
    SuppressionAdded:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/SuppressionAddedDetail'
        kind:
          const: suppression.added
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: SuppressionAdded
      type: object
    SuppressionLifted:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/SuppressionLiftedDetail'
        kind:
          const: suppression.lifted
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: SuppressionLifted
      type: object
    TaskLockDeclared:
      additionalProperties: false
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        detail:
          $ref: '#/components/schemas/TaskLockDetail'
        kind:
          const: task_lock
          title: Kind
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
      required:
        - agent
        - kind
        - detail
      title: TaskLockDeclared
      type: object
    ReleaseDetail:
      additionalProperties: false
      description: The claim a case closes, with the epoch it got when it was accepted.
      properties:
        claim_id:
          format: uuid
          title: Claim Id
          type: string
        epoch:
          minimum: 0
          title: Epoch
          type: integer
      required:
        - claim_id
        - epoch
      title: ReleaseDetail
      type: object
    ObjectRef:
      additionalProperties: false
      description: >-
        A business object in a system of record, e.g. `invoice` / `erp` /
        `0823`.
      properties:
        id:
          maxLength: 512
          minLength: 1
          title: Id
          type: string
          description: The id in that system.
        namespace:
          maxLength: 256
          minLength: 1
          title: Namespace
          type: string
          description: The system it lives in, such as `erp`.
        type:
          maxLength: 256
          minLength: 1
          title: Type
          type: string
          description: Object type, such as `invoice`, `order` or `ticket`.
      required:
        - type
        - namespace
        - id
      title: ObjectRef
      type: object
    Handle:
      additionalProperties: false
      description: >-
        An identifier of a subject in some channel or system: a phone, an
        e-mail, a CRM id.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Namespace for scoped identifiers: the WhatsApp Business account for
            `wa_bsuid`, the system for `system_id`, the country for
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: Defaults to `person`, except for organization-only handle types.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            The identifier. Normalized on the server: E.164 for phones,
            lowercase for e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    LeaseDetail:
      additionalProperties: false
      description: >-
        An owner lease or a case, held by the declaring agent. `level` defaults
        to the space's least

        restrictive level.
      properties:
        intents:
          items:
            pattern: ^[a-z][a-z0-9_]{0,39}$
            type: string
          maxItems: 20
          title: Intents
          type: array
        lease_s:
          maximum: 86400
          minimum: 1
          title: Lease S
          type: integer
        level:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Level
      required:
        - lease_s
      title: LeaseDetail
      type: object
    CommitmentDecidedDetail:
      additionalProperties: false
      description: >-
        The person accepted or declined a commitment, maybe in a later
        conversation.
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
        outcome:
          enum:
            - accepted
            - declined
          title: Outcome
          type: string
      required:
        - commitment_id
        - outcome
      title: CommitmentDecidedDetail
      type: object
    CommitmentMadeDetail:
      additionalProperties: false
      description: '`score` ranks commitments of a `best_wins` type: the higher holds.'
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
        score:
          anyOf:
            - type: number
            - type: 'null'
          title: Score
        terms:
          additionalProperties: true
          title: Terms
          type: object
        type:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Type
          type: string
        valid_until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Valid Until
      required:
        - commitment_id
        - type
      title: CommitmentMadeDetail
      type: object
    CommitmentWithdrawnDetail:
      additionalProperties: false
      properties:
        commitment_id:
          maxLength: 512
          minLength: 1
          title: Commitment Id
          type: string
      required:
        - commitment_id
      title: CommitmentWithdrawnDetail
      type: object
    ContactMadeDetail:
      additionalProperties: false
      description: >-
        `jti` is the contact token's; `unchecked` says the contact left without
        a decision, because the

        purpose fails open and none came in time.
      properties:
        channel:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Channel
          type: string
        decision_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Decision Id
        gateway_id:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Gateway Id
        jti:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: Jti
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
        unchecked:
          default: false
          title: Unchecked
          type: boolean
      required:
        - purpose
        - channel
      title: ContactMadeDetail
      type: object
    EffectDetail:
      additionalProperties: false
      description: How the attempt the caller holds ended.
      properties:
        attempt:
          minimum: 1
          title: Attempt
          type: integer
        effect_key:
          maxLength: 512
          minLength: 1
          title: Effect Key
          type: string
        state:
          enum:
            - done
            - failed
            - unknown_outcome
          title: State
          type: string
      required:
        - effect_key
        - state
        - attempt
      title: EffectDetail
      type: object
    HandoffDetail:
      additionalProperties: false
      properties:
        handoff_id:
          maxLength: 512
          minLength: 1
          title: Handoff Id
          type: string
        outcome:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Outcome
        status:
          enum:
            - created
            - accepted
            - closed
          title: Status
          type: string
      required:
        - handoff_id
        - status
      title: HandoffDetail
      type: object
    SuppressionAddedDetail:
      additionalProperties: false
      description: >-
        The subject may not be contacted for `purpose`, on `channel` or on every
        channel. `until` defaults to

        the reason's own interval, or to no end.
      properties:
        channel:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Channel
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
        reason:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Reason
          type: string
        until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Until
      required:
        - purpose
        - reason
      title: SuppressionAddedDetail
      type: object
    SuppressionLiftedDetail:
      additionalProperties: false
      description: Lifts what the same source suppressed for `purpose` and `channel`.
      properties:
        channel:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Channel
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
      required:
        - purpose
      title: SuppressionLiftedDetail
      type: object
    TaskLockDetail:
      additionalProperties: false
      properties:
        lease_s:
          maximum: 86400
          minimum: 1
          title: Lease S
          type: integer
        task:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Task
          type: string
      required:
        - task
        - lease_s
      title: TaskLockDetail
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        A person, a customer organization (`account`) or an organization that
        takes part without being a customer (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        The kind of identifier. The value is classified by its format, never by
        the field it came from.
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````