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

# Preview a view

> Answers a view without saving it: a number, series, ranked list or funnel. A funnel counts one try per person, from their first step one in the range; a later try is not counted. Members of every role, keys and brand agents. At most 90 days. [Views](/views#preview-a-view)



## OpenAPI

````yaml /api-reference/openapi.json post /v1/views/preview
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/views/preview:
    post:
      tags:
        - views
      summary: Preview a view
      description: >-
        Answers a view without saving it: a number, series, ranked list or
        funnel. A funnel counts one try per person, from their first step one in
        the range; a later try is not counted. Members of every role, keys and
        brand agents. At most 90 days. [Views](/views#preview-a-view)
      operationId: views.preview
      parameters:
        - 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
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PreviewViewInput'
      responses:
        '200':
          description: Preview a view
          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/PreviewViewAnswer'
        '422':
          description: >-
            - `validation_failed`: Nothing was changed. Fix what the message
            says is wrong (the field is named in `param` when there is one) and
            send the request again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '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:
    PreviewViewInput:
      type: object
      properties:
        definition:
          $ref: '#/components/schemas/PreviewViewDefinition'
        compare:
          type: boolean
          description: Also answer for the span of the same length just before
      required:
        - definition
      additionalProperties: false
    PreviewViewAnswer:
      type: object
      properties:
        period:
          $ref: '#/components/schemas/Period'
        compared_with:
          allOf:
            - $ref: '#/components/schemas/Period'
            - type:
                - object
                - 'null'
        series:
          type: array
          items:
            $ref: '#/components/schemas/ViewSeries'
          description: One entry for each measure, in the order asked
        rows:
          type: array
          items:
            $ref: '#/components/schemas/ViewRow'
          description: Empty unless the shape is list
        total_rows:
          type:
            - integer
            - 'null'
          minimum: 0
          description: How many rows a list has in all
        computed_at:
          type: string
          format: date-time
          description: When this answer was computed
        steps:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/FunnelStepAnswer'
          description: Set for a funnel
      required:
        - period
        - compared_with
        - series
        - rows
        - total_rows
        - computed_at
        - steps
    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
    PreviewViewDefinition:
      type: object
      properties:
        who:
          $ref: '#/components/schemas/ViewWho'
        what:
          type: array
          items:
            $ref: '#/components/schemas/ViewMeasure'
          minItems: 1
          maxItems: 4
          description: >-
            What to count: 1 to 4 measures. A list ranks by the first and shows
            the others as columns
        over:
          $ref: '#/components/schemas/ViewRange'
        shape:
          $ref: '#/components/schemas/PreviewViewShape'
        source:
          type: string
          enum:
            - trusted
            - platform
            - onchain
            - web_identified
            - any
          description: >-
            Whose events this view counts. Left out is the same as platform:
            trusted and chat platform events (chat is not available yet).
            trusted: only your server, an agent or a person in Lurk. onchain:
            only Lurk's on-chain observations (not available yet).
            web_identified: server-verified web identification (not available
            yet). any: all sources; devices, on-chain observations and web
            identification are not available yet. Units given, spent and held,
            and new people are counted whatever this says
      required:
        - who
        - what
        - over
        - shape
      additionalProperties: false
      description: >-
        The question: whose numbers, what to count, over which range, as which
        shape
    Period:
      type: object
      properties:
        from:
          type: string
          format: date-time
          description: The start of the span, included
        to:
          type: string
          format: date-time
          description: The end of the span, not included
      required:
        - from
        - to
      description: 'A date range: from is inclusive, to is exclusive'
    ViewSeries:
      type: object
      properties:
        measure:
          $ref: '#/components/schemas/ViewMeasure'
        unit:
          type:
            - string
            - 'null'
          pattern: ^[a-z][a-z0-9_-]{0,63}$
          description: The unit's key for given, spent and held; null for the rest
        total:
          type: integer
          description: >-
            The whole range: a sum for flows, what is held at its end, unique
            people for people
        previous_total:
          type:
            - integer
            - 'null'
          description: >-
            The same over the compared range; null unless `compare` was asked
            for and the range is not `now`
        points:
          type: array
          items:
            $ref: '#/components/schemas/ViewPoint'
          description: Empty unless the shape is over_time
        previous_points:
          type: array
          items:
            $ref: '#/components/schemas/ViewPoint'
          description: The compared range, aligned to points
      required:
        - measure
        - unit
        - total
        - previous_total
        - points
        - previous_points
    ViewRow:
      type: object
      properties:
        rank:
          type: integer
          exclusiveMinimum: 0
          description: >-
            1 for the top row. In a list by property, rows with equal values
            share a rank
        label:
          type: string
          description: >-
            What a person reads: a user's identifier, a rule's name, a
            property's value
        user:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              description: The person's `usr_…` ID
            external_id:
              type: string
              description: Your own identifier for the person
          required:
            - id
            - external_id
          description: The person, in a list of people; null otherwise
        rule:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
              description: The rule's `rule_…` ID
            key:
              type: string
              description: The rule's key
            name:
              type: string
              description: The rule's name
          required:
            - id
            - key
            - name
          description: The rule, in a list of rules; null otherwise
        property:
          type:
            - object
            - 'null'
          properties:
            value:
              type:
                - string
                - 'null'
              description: The value, as text; null for the row that counts the hidden ones
          required:
            - value
          description: Set in a list by property
        value:
          type: integer
          description: The first measure
        previous_rank:
          type:
            - integer
            - 'null'
          exclusiveMinimum: 0
          description: Rank in the compared range
        values:
          type: array
          items:
            type: integer
          description: One per measure
      required:
        - rank
        - label
        - user
        - rule
        - property
        - value
        - previous_rank
        - values
    FunnelStepAnswer:
      type: object
      properties:
        step:
          $ref: '#/components/schemas/FunnelStep'
        people:
          type: integer
          minimum: 0
          description: People who did this step and every one before it, in order, in time
        previous_people:
          type:
            - integer
            - 'null'
          minimum: 0
          description: The same over the compared range; null without compare
        median_seconds:
          type:
            - integer
            - 'null'
          minimum: 0
          description: >-
            Typical time from the step before, in whole seconds rounded down;
            null for the first step and when nobody reached this one
      required:
        - step
        - people
        - previous_people
        - median_seconds
    ViewWho:
      anyOf:
        - type: string
          enum:
            - everyone
        - type: object
          properties:
            audience:
              type: string
              minLength: 1
              maxLength: 128
              description: An aud_… ID or the audience's key
          required:
            - audience
          additionalProperties: false
      description: 'Whose numbers: `everyone`, or the people of one audience'
    ViewMeasure:
      oneOf:
        - type: object
          properties:
            measure:
              type: string
              enum:
                - active_users
                - returning_users
                - new_users
              description: >-
                `active_users`: people with an event in the range.
                `returning_users`: those of them first seen before the range.
                `new_users`: people first seen in the range
          required:
            - measure
          additionalProperties: false
        - type: object
          properties:
            measure:
              type: string
              enum:
                - events
              description: Count events
            event:
              type: string
              maxLength: 100
              pattern: ^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$
              description: Leave it out to count every event
            where:
              type: object
              properties:
                property:
                  type: string
                  minLength: 1
                  maxLength: 64
                  description: The property's name, as the event carries it (`plan`)
                equals:
                  anyOf:
                    - type: string
                      maxLength: 256
                    - type: number
                    - type: boolean
                  description: >-
                    The value it must have, compared exactly as text: 5 and
                    `"5"` match each other, `Pro` and `pro` do not
              required:
                - property
                - equals
              additionalProperties: false
              description: >-
                Only the events whose property has this value. Needs a named
                event.
          required:
            - measure
          additionalProperties: false
        - type: object
          properties:
            measure:
              type: string
              enum:
                - given
                - spent
                - held
              description: >-
                `given`: units added in the range. `spent`: units taken, as a
                positive number. `held`: what everyone holds at the end of the
                range
            unit:
              type: string
              pattern: ^[a-z][a-z0-9_-]{0,63}$
              description: The unit's key
          required:
            - measure
            - unit
          additionalProperties: false
      description: One thing to count. Each becomes one series in the answer
    ViewRange:
      type: string
      enum:
        - now
        - today
        - this_week
        - last_week
        - last_7_days
        - last_14_days
        - last_30_days
        - last_90_days
        - this_month
        - all_time
      description: >-
        The span a view covers, in the project's time zone; a week is Monday to
        Sunday. `now` is a moment, so only `held` can be read for it
    PreviewViewShape:
      oneOf:
        - type: object
          properties:
            type:
              type: string
              enum:
                - number
              description: One number for each measure
          required:
            - type
          additionalProperties: false
        - type: object
          properties:
            type:
              type: string
              enum:
                - over_time
              description: A series for each measure, one point per `every`
            every:
              type: string
              enum:
                - day
                - week
                - month
              description: How long each point covers
          required:
            - type
            - every
          additionalProperties: false
        - type: object
          properties:
            type:
              type: string
              enum:
                - list
              description: A ranked list, best first
            by:
              type: string
              enum:
                - user
                - rule
                - property
              description: >-
                Rank users, rank rules, or rank the values of one property of
                the event counted
            property:
              type: string
              minLength: 1
              maxLength: 64
              description: >-
                With `by: property`: the property's name, as the event carries
                it (`path`, `target`). A value that looks personal is counted
                under one row, Hidden (a best-effort check, not a guarantee:
                ranked values are as readable as a person's history)
            size:
              type: integer
              minimum: 1
              maximum: 100
              description: How many rows
          required:
            - type
            - by
            - size
          additionalProperties: false
        - $ref: '#/components/schemas/FunnelShape'
      description: >-
        How the answer comes back: a number, a series over time, a ranked list,
        or a funnel (a preview only; a saved view cannot be a funnel yet)
    ViewPoint:
      type: object
      properties:
        at:
          type: string
          format: date-time
          description: When the bucket starts
        value:
          type: integer
          description: The measure's value for the bucket
      required:
        - at
        - value
    FunnelStep:
      anyOf:
        - $ref: '#/components/schemas/ViewStep'
        - $ref: '#/components/schemas/RewardStep'
      description: >-
        One step: an event, optionally narrowed by one property, or the first
        reward as the last step
    FunnelShape:
      type: object
      properties:
        type:
          type: string
          enum:
            - funnel
          description: 'A funnel: how many people take each step in order'
        steps:
          type: array
          items:
            $ref: '#/components/schemas/FunnelStep'
          minItems: 2
          maxItems: 5
          description: >-
            In order: a person counts at a step once they did every step before
            it
        within:
          $ref: '#/components/schemas/FunnelWithin'
      required:
        - type
        - steps
        - within
      additionalProperties: false
      description: >-
        People who took each step in order, each strictly after the one before
        and within `within` of their first step. Each person has one try, from
        their first step one in the range: someone whose first try runs out of
        time is not counted, even if a later try finishes
    ViewStep:
      type: object
      properties:
        event:
          type: string
          maxLength: 100
          pattern: ^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$
          description: >-
            An event's name: lowercase words joined by dots, thing first, such
            as `checkin.scanned`
        where:
          type: object
          properties:
            property:
              type: string
              minLength: 1
              maxLength: 64
              description: The property's name, as the event carries it (`plan`)
            equals:
              anyOf:
                - type: string
                  maxLength: 256
                - type: number
                - type: boolean
              description: >-
                The value it must have, compared exactly as text: 5 and `"5"`
                match each other, `Pro` and `pro` do not
          required:
            - property
            - equals
          additionalProperties: false
          description: Only the events whose property has this value
      required:
        - event
      additionalProperties: false
      description: 'One step: an event, optionally narrowed by one property'
    RewardStep:
      type: object
      properties:
        reward:
          type: string
          enum:
            - first
          description: 'Always `first`: the person''s first reward'
      required:
        - reward
      additionalProperties: false
      description: >-
        The first time a person receives units of any unit, from a rule or by
        hand. A reward that was undone does not count, and units sent by another
        person do not count. Only as the last step.
    FunnelWithin:
      type: string
      enum:
        - 1h
        - 1d
        - 7d
        - 30d
      description: >-
        How long a person has, from their first step, to take every other step:
        an hour, a day, 7 days or 30 days. A step exactly at the end still
        counts
  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.