openapi: 3.0.3
info:
  title: Verdo Team Decisions
  description: |
    Structured team decisions with deadlines, routing and webhooks.
    Use when your agent needs a person to approve a proposal, pick between options or sign off
    on something, and needs a structured result rather than a discussion.

    The agent proposes; a person decides. No operation here invites people, approves, rejects
    or settles a decision: those happen in Verdo. Past decisions are records, not consent
    (execution_authorized: false).
  version: 1.0.0
  contact:
    name: Verdo
    url: https://verdo.ink
servers:
  - url: https://verdo.ink/api
    description: Production
security:
  - bearerAuth: []

paths:
  /zapier/decisions:
    post:
      operationId: createDecision
      summary: Propose a decision
      description: |
        Propose a decision with 2-10 options. It invites nobody: the decision opens in the Verdo
        dashboard, and tags can route it to an approver configured in Verdo. With an
        idempotency_key, a retry while that decision is still open returns it with
        created: false and replayed: true (HTTP 200) instead of creating another.
        Needs a full-access key; draft-only keys are refused.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [title, options]
              properties:
                title:
                  type: string
                  maxLength: 140
                  description: The decision question
                  example: "Ship the redesigned onboarding flow this sprint?"
                options:
                  type: array
                  minItems: 2
                  maxItems: 10
                  items:
                    type: string
                  description: The options to choose from, as plain strings
                  example: ["Ship it", "One more round of testing", "Descope"]
                method:
                  type: string
                  enum: [single_choice, ranked_choice, approval, dot]
                  default: single_choice
                  description: Voting method
                deadline_hours:
                  type: integer
                  minimum: 1
                  maximum: 720
                  default: 48
                  description: Hours until the decision closes
                authority_mode:
                  type: string
                  enum: [majority, consensus]
                  default: majority
                  description: How the result is reached
                anonymous:
                  type: boolean
                  default: false
                  description: Whether votes are anonymous
                tags:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                  description: Tags for the decision. A workspace routing rule matching one assigns its approver.
                  example: ["engineering"]
                idempotency_key:
                  type: string
                  minLength: 1
                  maxLength: 128
                  description: Retry safety. While the decision this key created is open, the same key returns it.
                  example: "onboarding-redesign-sprint-47"
                source_agent:
                  type: string
                  maxLength: 200
                  description: A name for the agent creating this, recorded on the decision. Default is the API key's name.
                  example: "sprint-planner"
      responses:
        "201":
          description: Decision created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CreateResult"
        "200":
          description: Existing open decision returned for the same idempotency_key (created false, replayed true)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CreateResult"
        "400":
          $ref: "#/components/responses/Error"
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
        "429":
          $ref: "#/components/responses/Error"

  /zapier/decisions/search:
    get:
      operationId: listDecisions
      summary: List and filter decisions
      description: Up to 25 decisions, newest first, filtered by title words, status, tags, creating agent or notification status. Read-only.
      parameters:
        - name: query
          in: query
          schema:
            type: string
          description: Words to match in decision titles
        - name: lifecycle_status
          in: query
          schema:
            type: string
          description: Comma-separated statuses (draft, active, decided, implemented, stalled, superseded, reversed, cancelled, rejected)
          example: "active,decided"
        - name: tags
          in: query
          schema:
            type: string
          description: Comma-separated tags (decisions with any of them)
        - name: source_agent
          in: query
          schema:
            type: string
        - name: notification_status
          in: query
          schema:
            $ref: "#/components/schemas/NotificationStatus"
      responses:
        "200":
          description: Matching decisions
          content:
            application/json:
              schema:
                type: object
                properties:
                  decisions:
                    type: array
                    items:
                      $ref: "#/components/schemas/Decision"
        "401":
          $ref: "#/components/responses/Error"

  /zapier/decisions/{id}:
    get:
      operationId: checkDecision
      summary: Check a decision
      description: Status, outcome once a person has decided, votes per option, owner, dashboard link and request fingerprint. Read-only.
      parameters:
        - $ref: "#/components/parameters/DecisionId"
      responses:
        "200":
          description: The decision
          content:
            application/json:
              schema:
                type: object
                properties:
                  decision:
                    $ref: "#/components/schemas/Decision"
        "401":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"

  /zapier/decisions/precedent:
    get:
      operationId: searchDecisions
      summary: Search past decided decisions
      description: Past decided decisions whose title matches, newest first. Past records, not consent. Read-only.
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
            maxLength: 140
          example: "onboarding"
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 10
      responses:
        "200":
          description: Matching past decisions
          content:
            application/json:
              schema:
                type: object
                properties:
                  decisions:
                    type: array
                    items:
                      $ref: "#/components/schemas/PrecedentItem"
                  execution_authorized:
                    type: boolean
                    enum: [false]
        "401":
          $ref: "#/components/responses/Error"

  /zapier/decisions/{id}/precedent:
    get:
      operationId: getPrecedent
      summary: Read a past decision's record
      description: One past decision's outcome, date, owner, how it was decided, votes per option, the rationale if approved for sharing, and related decisions. A past record, not consent. Read-only.
      parameters:
        - $ref: "#/components/parameters/DecisionId"
      responses:
        "200":
          description: The past decision record
          content:
            application/json:
              schema:
                type: object
                properties:
                  precedent:
                    $ref: "#/components/schemas/PrecedentDetail"
        "401":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"

  /v1/decisions/{id}/cancel:
    post:
      operationId: cancelDecision
      summary: Withdraw your own decision
      description: Withdraws a draft or open decision this API key created. It closes for good as cancelled. This decides nothing. Needs a full-access key.
      parameters:
        - $ref: "#/components/parameters/DecisionId"
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
                  maxLength: 500
                  description: Why it is being withdrawn (shown to the people it was sent to)
                  example: "Requirements changed"
      responses:
        "200":
          description: Decision cancelled
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                  status:
                    $ref: "#/components/schemas/LifecycleStatus"
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"

  /v1/decisions/{id}/edit:
    post:
      operationId: editDecision
      summary: Revise your own decision
      description: Revises a draft or open decision this API key created. A change voids every vote cast so far and changes the request fingerprint. Needs a full-access key.
      parameters:
        - $ref: "#/components/parameters/DecisionId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              minProperties: 1
              properties:
                title:
                  type: string
                  maxLength: 140
                description:
                  type: string
                options:
                  type: array
                  minItems: 2
                  maxItems: 10
                  items:
                    type: string
                  description: The full new list of options
      responses:
        "200":
          description: Decision edited
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                  changed:
                    type: boolean
                  votes_voided:
                    type: integer
                  request_fingerprint:
                    type: string
                    nullable: true
        "401":
          $ref: "#/components/responses/Error"
        "403":
          $ref: "#/components/responses/Error"
        "404":
          $ref: "#/components/responses/Error"

  /v1/webhooks/subscribe:
    post:
      operationId: subscribeWebhook
      summary: Subscribe to a decision event
      description: |
        Subscribes a public https URL to one event. The response carries the signing_secret,
        shown only once. Each delivery has X-Verdo-Timestamp and
        X-Verdo-Signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<raw body>">. Check it before
        trusting a delivery.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url, event_type]
              properties:
                url:
                  type: string
                  format: uri
                  example: "https://your-server.example/webhook"
                event_type:
                  type: string
                  enum: [decision.settled, decision.rejected, decision.cancelled, decision.expired, decision.escalated]
      responses:
        "201":
          description: Subscribed
          content:
            application/json:
              schema:
                type: object
                properties:
                  subscription_id:
                    type: string
                  signing_secret:
                    type: string
                    description: HMAC-SHA256 signing secret (shown once)
                  event_type:
                    type: string
                  url:
                    type: string
                    format: uri
        "400":
          $ref: "#/components/responses/Error"
        "401":
          $ref: "#/components/responses/Error"

  /v1/webhooks:
    get:
      operationId: listWebhooks
      summary: List webhook subscriptions
      description: The workspace's signed webhook subscriptions with delivery stats. Never the signing secret.
      responses:
        "200":
          description: Subscriptions
          content:
            application/json:
              schema:
                type: object
                properties:
                  subscriptions:
                    type: array
                    items:
                      type: object
        "401":
          $ref: "#/components/responses/Error"

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A Verdo API key (vdok_...), from Settings > API keys in Verdo. Creating, cancelling and editing need a full-access key.

  parameters:
    DecisionId:
      name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid

  responses:
    Error:
      description: The request failed. error is a stable code; message says what to do.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
                example: "draft_only_key"
              message:
                type: string
              retry_after_seconds:
                type: number
                description: On 429, seconds to wait before retrying

  schemas:
    LifecycleStatus:
      type: string
      enum: [draft, active, decided, implemented, stalled, superseded, reversed, cancelled, rejected]

    NotificationStatus:
      type: string
      enum: [pending, delivered, partially_delivered, failed]

    CreateResult:
      type: object
      properties:
        id:
          type: string
          format: uuid
        url:
          type: string
          format: uri
          description: The decision's dashboard link, to send to the person who decides
        request_fingerprint:
          type: string
          nullable: true
        created:
          type: boolean
        replayed:
          type: boolean

    Decision:
      type: object
      properties:
        id:
          type: string
        decision_id:
          type: string
          format: uuid
        title:
          type: string
        method:
          type: string
        authority_mode:
          type: string
        status:
          $ref: "#/components/schemas/LifecycleStatus"
        outcome:
          type: string
          nullable: true
          description: The chosen option, once a person has decided
        outcome_option_id:
          type: string
          nullable: true
        owner:
          type: object
          nullable: true
          properties:
            name:
              type: string
              nullable: true
            email:
              type: string
              nullable: true
        vote_breakdown:
          type: array
          items:
            type: object
            properties:
              option:
                type: string
              votes:
                type: integer
        url:
          type: string
          format: uri
        decided_at:
          type: string
          nullable: true
          format: date-time
        request_fingerprint:
          type: string
          nullable: true
          description: Returned by check only
        notification_status:
          $ref: "#/components/schemas/NotificationStatus"
        routing_rule_label:
          type: string
          nullable: true
          description: Returned by check only
        source_agent:
          type: string
          nullable: true
          description: Returned by check only
        idempotency_key:
          type: string
          nullable: true
          description: Returned by check only

    PrecedentItem:
      type: object
      properties:
        id:
          type: string
          format: uuid
        title:
          type: string
        status:
          type: string
        winner:
          type: string
          nullable: true
        settled_at:
          type: string
          nullable: true
          format: date-time
        owner_name:
          type: string
          nullable: true
        authority_mode:
          type: string
          nullable: true
        rationale:
          type: string
          nullable: true
        execution_authorized:
          type: boolean
          enum: [false]

    PrecedentDetail:
      allOf:
        - $ref: "#/components/schemas/PrecedentItem"
        - type: object
          properties:
            vote_counts:
              type: array
              items:
                type: object
                properties:
                  option:
                    type: string
                  votes:
                    type: integer
            related:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: string
                  title:
                    type: string
                  status:
                    type: string
                  settled_at:
                    type: string
                    nullable: true
