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

# Get what a rule did

> From the receipts: how many times the rule changed something, for how many people, and how much it gave or took per unit, plus how often it did not apply and why, and the ten people it reached most. Skips are kept for 30 days.



## OpenAPI

````yaml /api-reference/openapi.json get /v1/rules/{id}/stats
openapi: 3.1.0
info:
  title: Lurk API
  version: 1.0.0
  description: Events in, rules decide, units change, receipts out.
servers:
  - url: https://api.getlurk.com
security: []
tags:
  - name: events
    description: Send what your users do. Lurk runs your live rules on each event.
    x-group: Events
    x-displayName: Events
  - name: units
    description: What people collect and hold, and their balances.
    x-group: Units
    x-displayName: Units
  - name: rules
    description: What Lurk does when an event comes in. A person takes a rule live.
    x-group: Rules
    x-displayName: Rules
  - name: activity
    description: A receipt for every change, with why it happened.
    x-group: Receipts
    x-displayName: Receipts
  - name: users
    description: The people your events are about.
    x-group: People
    x-displayName: People
  - name: webhook_endpoints
    description: Where Lurk sends signed notices of what changed.
    x-group: Webhooks
    x-displayName: Webhooks
  - name: known_values
    description: The properties of your own events whose values Lurk remembers.
    x-group: Known values
    x-displayName: Known values
  - name: feedback
    description: Tell the Lurk team about a bug, a gap or an idea.
    x-group: Feedback
    x-displayName: Feedback
  - name: annotations
    description: >-
      Short notes on a day of the project, such as a release or a campaign
      start.
    x-group: Annotations
    x-displayName: Annotations
  - name: trusted_issuers
    description: The sign-in providers a project trusts for its app's users.
    x-group: Trusted issuers
    x-displayName: Trusted issuers
  - name: client_events
    description: The events a signed-in device may send, and their caps.
    x-group: Client events
    x-displayName: Client events
  - name: issuer_identities
    description: Which person each sign-in subject is bound to.
    x-group: Issuer identities
    x-displayName: Issuer identities
  - name: proposals
    description: Changes an agent or Lurky asks for and a person approves or declines.
    x-group: Proposals
    x-displayName: Proposals
  - name: holds
    description: Changes a rule parked for a person to give or refuse.
    x-group: Holds
    x-displayName: Holds
  - name: audiences
    description: The groups of people that rules can read.
    x-group: Audiences
    x-displayName: Audiences
  - name: budgets
    description: What each live rule's budgets have given in the window they are in now.
    x-group: Budgets
    x-displayName: Budgets
  - name: templates
    description: Kits that add units and rules to a project in one go.
    x-group: Templates
    x-displayName: Templates
  - name: views
    description: Saved questions about a project, with their answers.
    x-group: Views
    x-displayName: Views
  - name: integrations
    description: Every way events reach Lurk or state leaves it, and the state of each.
    x-group: Integrations
    x-displayName: Integrations
  - name: projects
    description: Where units, rules and events live. An organization can have several.
    x-group: Projects
    x-displayName: Projects
  - name: clocks
    description: A test project's clock, which can be moved to try schedules and expiries.
    x-group: Clocks
    x-displayName: Clocks
paths:
  /v1/rules/{id}/stats:
    get:
      tags:
        - rules
      summary: Get what a rule did
      description: >-
        From the receipts: how many times the rule changed something, for how
        many people, and how much it gave or took per unit, plus how often it
        did not apply and why, and the ten people it reached most. Skips are
        kept for 30 days.
      operationId: rules.stats
      parameters:
        - schema:
            type: string
            description: A rule_… ID or the rule's key
            examples:
              - order-points
          required: true
          description: A rule_… ID or the rule's key
          name: id
          in: path
        - schema:
            type: integer
            minimum: 1
            maximum: 90
            default: 30
            description: How many past days to look at, 1 to 90
          required: false
          description: How many past days to look at, 1 to 90
          name: days
          in: query
        - schema:
            type: string
            description: W3C Trace Context; joins your trace to ours
          required: false
          description: W3C Trace Context; joins your trace to ours
          name: traceparent
          in: header
      responses:
        '200':
          description: Get what a rule did
          headers:
            Request-Id:
              schema:
                type: string
                description: Quote this when you contact support
              required: true
              description: Quote this when you contact support
            traceparent:
              schema:
                type: string
                description: W3C Trace Context for this call, in the caller's trace
              required: true
              description: W3C Trace Context for this call, in the caller's trace
            RateLimit:
              schema:
                type: string
                description: The tightest limit now, e.g. `"ingest-key";r=5999;t=42`
              required: true
              description: The tightest limit now, e.g. `"ingest-key";r=5999;t=42`
            RateLimit-Policy:
              schema:
                type: string
                description: Its quota and window, e.g. `"ingest-key";q=6000;w=60`
              required: true
              description: Its quota and window, e.g. `"ingest-key";q=6000;w=60`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RuleStatsOutput'
        '429':
          description: Too many requests. Wait `Retry-After` seconds.
          headers:
            Request-Id:
              schema:
                type: string
                description: Quote this when you contact support
              required: true
              description: Quote this when you contact support
            traceparent:
              schema:
                type: string
                description: W3C Trace Context for this call, in the caller's trace
              required: true
              description: W3C Trace Context for this call, in the caller's trace
            RateLimit:
              schema:
                type: string
                description: The tightest limit now, e.g. `"ingest-key";r=5999;t=42`
              required: true
              description: The tightest limit now, e.g. `"ingest-key";r=5999;t=42`
            RateLimit-Policy:
              schema:
                type: string
                description: Its quota and window, e.g. `"ingest-key";q=6000;w=60`
              required: true
              description: Its quota and window, e.g. `"ingest-key";q=6000;w=60`
            Retry-After:
              schema:
                type: string
                description: Seconds to wait
              required: true
              description: Seconds to wait
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        default:
          description: Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    RuleStatsOutput:
      type: object
      properties:
        rule:
          type: string
          description: The rule's key
        period:
          $ref: '#/components/schemas/RulePeriod'
        receipts:
          type: integer
          minimum: 0
          description: Times it changed something
        users:
          type: integer
          minimum: 0
          description: People it reached
        given:
          type: array
          items:
            $ref: '#/components/schemas/UnitTotal'
          description: What it gave, per unit. Negative for taking
        skipped:
          type: array
          items:
            $ref: '#/components/schemas/SkipCount'
          description: >-
            Times it did not apply. Skips are kept for 30 days, so a longer
            period shows the last 30
        top_users:
          type: array
          items:
            $ref: '#/components/schemas/RuleStatsUser'
          maxItems: 10
          description: >-
            The people it reached most in the period, by number of receipts,
            then by amount, then by ID
      required:
        - rule
        - period
        - receipts
        - users
        - given
        - skipped
        - top_users
      description: What the rule actually did, from the receipts
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            status:
              type: integer
            code:
              type: string
              enum:
                - invalid_json
                - invalid_key
                - forbidden
                - approval_required
                - not_found
                - idempotency_conflict
                - conflict
                - unblock_clock_reversed
                - insufficient_balance
                - reference_used
                - validation_failed
                - rate_limited
                - internal
                - unavailable
            message:
              type: string
            param:
              type: string
            next_step:
              type: string
              description: >-
                What to do about this kind of error, in one sentence. Always
                sent by current servers
            request_id:
              type: string
            doc_url:
              type: string
              format: uri
          required:
            - status
            - code
            - message
            - request_id
            - doc_url
      required:
        - error
    RulePeriod:
      type: object
      properties:
        from:
          type: string
          format: date-time
          description: The start of the period, as an instant
        to:
          type: string
          format: date-time
          description: The end of the period, as an instant
      required:
        - from
        - to
      description: The days a preview or the statistics looked at
    UnitTotal:
      type: object
      properties:
        unit:
          type: string
          pattern: ^[a-z][a-z0-9_-]{0,63}$
          description: The unit's key
        amount:
          type: integer
          description: 'The total: positive for given, negative for taken'
      required:
        - unit
        - amount
    SkipCount:
      type: object
      properties:
        reason:
          type: string
          enum:
            - condition_failed
            - condition_unknown
            - limit_reached
            - insufficient_balance
            - unit_setting
            - hold_refused
            - budget_reached
            - supply_gone
          description: >-
            condition_unknown: the holding could not be confirmed, so the rule
            does not fire and is not retried. unit_setting: a unit's own setting
            stopped it (it cannot go up or down, or the change would pass its
            cap). hold_refused: a person refused the change a rule had held.
            budget_reached: the rule has given all its budget for this window.
            supply_gone: a unit with a limited supply has none left for the
            change
        count:
          type: integer
          minimum: 0
          description: How many times the rule was skipped for this reason
      required:
        - reason
        - count
    RuleStatsUser:
      type: object
      properties:
        id:
          type: string
          description: The usr_… ID
        external_id:
          type: string
          description: The brand's own identifier for the person
        receipts:
          type: integer
          minimum: 1
          description: Times the rule changed something for them in the period
        given:
          type: array
          items:
            $ref: '#/components/schemas/UnitTotal'
          description: What they got in the period, per unit; negative for taking
      required:
        - id
        - external_id
        - receipts
        - given
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        A project key (Developers → API keys). Keep it on your server, not in an
        app.

````

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