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

> ## Agent Instructions
> CrispStats is a hosted, privacy-first analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing and no data import except a site's history from a Plausible export (Settings, Import and export). Websites use the script. iOS, Android, React Native and Flutter use the mobile SDKs in the install guides. Those SDKs are source files, not a published package, and they do not read an advertising id.
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> The script tag is the main install; the npm package @crispstats/tracker does the same from code, never alongside the tag. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Record a payment

> Record a payment, renewal, refund or free trial from your own checkout or billing. Needs a key with the Revenue and payments: write permission (keys made before permissions: the events, write or admin scope). `amount` is integer minor units (4900 is 49.00). `transactionId` makes the call safe to retry: the same id is recorded once. A refund sends `refunded: true` with the sale's `transactionId` and takes the sale's attribution. `timestamp` may go back 365 days. The payment is attributed, converted to the site's currency and announced on Realtime like a payment from a connected provider. `trial: true` records a free trial start instead: `amount` may be 0 or left out (when sent, it is the price the trial converts to and is not revenue), it is attributed like a sale, never announced as one, and converts when the same customer pays within 60 days. An amount of 0 without `trial` is refused.



## OpenAPI

````yaml /api-reference/openapi.json post /sites/{siteId}/payments
openapi: 3.1.0
info:
  title: CrispStats API
  version: 1.0.0
  description: >-
    Read a site's analytics; manage its sites, funnels, notes, alerts and API
    keys; and record or delete the payments of your own checkout. Authenticate
    with an API key as a bearer token (`Authorization: Bearer cs_sk_…`); the
    demo site `demo` can be read without one. Money is integer minor units in
    the stated `currency`, rates are 0..1, durations are seconds and timestamps
    are ISO-8601 UTC. Limits: a daily allowance per key from the plan, plus 20
    requests per 10 seconds; without a key, 500 requests a day. Every key in a
    workspace also counts toward a workspace ceiling of 5 times the plan's daily
    allowance, shared with the MCP server, where each JSON-RPC request in a POST
    counts once and a batch may hold at most 20 requests. Every response carries
    `X-RateLimit-*` headers, and a 429 carries `Retry-After`. Every list carries
    one `pagination` object ({limit, offset, total, hasMore}); range-aware
    reports take `timezone` (an IANA name, defaulting to the site's) and accept
    exact ISO timestamps as well as days in `from` and `to`.
servers:
  - url: https://crispstats.com/api/v1
security:
  - apiKey: []
  - {}
tags:
  - name: Sites
  - name: Analytics
  - name: Raw data
  - name: Payments
  - name: Account
  - name: Keys
  - name: Funnels
  - name: Notes
  - name: Alerts
paths:
  /sites/{siteId}/payments:
    post:
      tags:
        - Payments
      summary: Record a payment
      description: >-
        Record a payment, renewal, refund or free trial from your own checkout
        or billing. Needs a key with the Revenue and payments: write permission
        (keys made before permissions: the events, write or admin scope).
        `amount` is integer minor units (4900 is 49.00). `transactionId` makes
        the call safe to retry: the same id is recorded once. A refund sends
        `refunded: true` with the sale's `transactionId` and takes the sale's
        attribution. `timestamp` may go back 365 days. The payment is
        attributed, converted to the site's currency and announced on Realtime
        like a payment from a connected provider. `trial: true` records a free
        trial start instead: `amount` may be 0 or left out (when sent, it is the
        price the trial converts to and is not revenue), it is attributed like a
        sale, never announced as one, and converts when the same customer pays
        within 60 days. An amount of 0 without `trial` is refused.
      operationId: recordPayment
      parameters:
        - name: siteId
          in: path
          required: true
          description: The site's id, from GET /sites. The demo site is read-only.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                transactionId:
                  type: string
                  minLength: 1
                  maxLength: 200
                  description: >-
                    Your id for the payment, unique per site: an order, invoice
                    or charge id. Sending the same id again records nothing new
                    and answers duplicate: true. For a refund, the id of the
                    sale being refunded.
                amount:
                  description: >-
                    Required for a payment: the amount in minor units of the
                    currency (4900 is 49.00 USD), at least 1. For a refund, the
                    amount refunded. With trial: true it may be 0 or left out;
                    when sent, it is the price the trial converts to and is not
                    counted as revenue.
                  type: integer
                  minimum: 0
                  maximum: 1000000000000
                currency:
                  description: >-
                    Required for a payment: ISO 4217 currency code, such as USD.
                    A refund is in its sale's currency. A trial needs it only
                    with an amount.
                  type: string
                  pattern: ^[A-Za-z]{3}$
                visitorId:
                  description: >-
                    The visitor id from crispstats.id(), saved at checkout. Ties
                    the payment to that visitor's visits and sources.
                  type: string
                customerId:
                  description: >-
                    Your own id for the customer, the same id you pass to
                    identify(). Attribution then also uses that person's visits.
                  type: string
                  minLength: 1
                  maxLength: 200
                email:
                  description: >-
                    The customer's e-mail. Stored only as a hash and a masked
                    form (j***@e***.com); links renewals and refunds to the
                    first payment.
                  type: string
                  maxLength: 320
                product:
                  description: What was bought, shown in the payments list.
                  type: string
                  minLength: 1
                  maxLength: 200
                renewal:
                  description: >-
                    true for a subscription renewal. Counted as renewal revenue
                    and in MRR.
                  type: boolean
                subscription:
                  description: >-
                    true for the first payment of a new subscription. Counted as
                    new revenue and in MRR.
                  type: boolean
                refunded:
                  description: >-
                    true to record a refund of the sale named by transactionId.
                    It takes the sale's attribution.
                  type: boolean
                trial:
                  description: >-
                    true to record a free trial start instead of a payment. It
                    is attributed to the visitor's source like a sale, never
                    counted as revenue, and converts when the same customer
                    (customerId, email or visitorId) pays within 60 days.
                  type: boolean
                refundId:
                  description: >-
                    Refunds only: your id for this refund. Send it when a sale
                    can be refunded more than once by the same amount: without
                    it, a second refund of the same amount on the same sale is
                    taken as the first one sent again.
                  type: string
                  minLength: 1
                  maxLength: 40
                timestamp:
                  description: >-
                    When the payment happened, ISO 8601 with a timezone.
                    Defaults to now. Up to 365 days back, never in the future.
                  type: string
                  pattern: >-
                    ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:?\d{2})$
              required:
                - transactionId
              additionalProperties: false
            examples:
              payment:
                summary: A payment
                value:
                  transactionId: order_1042
                  amount: 4900
                  currency: USD
                  visitorId: 3f2a9c0e7b1d4e5f8a6b2c3d4e5f6a7b
                  email: jane@example.com
              trial:
                summary: A free trial start
                value:
                  transactionId: trial_sub_7
                  trial: true
                  amount: 2900
                  currency: USD
                  visitorId: 3f2a9c0e7b1d4e5f8a6b2c3d4e5f6a7b
                  email: jane@example.com
      responses:
        '200':
          description: 'Sent before: nothing new was recorded.'
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
          content:
            application/json:
              schema:
                type: object
                required:
                  - transactionId
                  - recorded
                  - duplicate
                  - linked
                  - waitingForSale
                  - trial
                properties:
                  transactionId:
                    type: string
                  recorded:
                    type: boolean
                    description: Stored by this request.
                  duplicate:
                    type: boolean
                    description: >-
                      This transactionId (for a refund: this refund) was
                      recorded before. Nothing changed.
                  linked:
                    type: boolean
                    description: >-
                      Tied to a visit, so the payment is credited to a source,
                      campaign and landing page.
                  waitingForSale:
                    type: boolean
                    description: >-
                      A refund whose sale is not recorded yet. It is kept and
                      counted once the sale arrives.
                  trial:
                    type: boolean
                    description: >-
                      A free trial start (trial: true), stored apart from
                      revenue.
        '201':
          description: Recorded.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
          content:
            application/json:
              schema:
                type: object
                required:
                  - transactionId
                  - recorded
                  - duplicate
                  - linked
                  - waitingForSale
                  - trial
                properties:
                  transactionId:
                    type: string
                  recorded:
                    type: boolean
                    description: Stored by this request.
                  duplicate:
                    type: boolean
                    description: >-
                      This transactionId (for a refund: this refund) was
                      recorded before. Nothing changed.
                  linked:
                    type: boolean
                    description: >-
                      Tied to a visit, so the payment is credited to a source,
                      campaign and landing page.
                  waitingForSale:
                    type: boolean
                    description: >-
                      A refund whose sale is not recorded yet. It is kept and
                      counted once the sale arrives.
                  trial:
                    type: boolean
                    description: >-
                      A free trial start (trial: true), stored apart from
                      revenue.
        '202':
          description: >-
            A refund whose sale is not recorded yet: kept, and counted when the
            sale arrives.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
          content:
            application/json:
              schema:
                type: object
                required:
                  - transactionId
                  - recorded
                  - duplicate
                  - linked
                  - waitingForSale
                  - trial
                properties:
                  transactionId:
                    type: string
                  recorded:
                    type: boolean
                    description: Stored by this request.
                  duplicate:
                    type: boolean
                    description: >-
                      This transactionId (for a refund: this refund) was
                      recorded before. Nothing changed.
                  linked:
                    type: boolean
                    description: >-
                      Tied to a visit, so the payment is credited to a source,
                      campaign and landing page.
                  waitingForSale:
                    type: boolean
                    description: >-
                      A refund whose sale is not recorded yet. It is kept and
                      counted once the sale arrives.
                  trial:
                    type: boolean
                    description: >-
                      A free trial start (trial: true), stored apart from
                      revenue.
        '400':
          $ref: '#/components/responses/InvalidRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PlanLimitReached'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '503':
          description: >-
            Payments cannot be written just now. Nothing was changed; retry
            later with the same request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  headers:
    X-RateLimit-Limit:
      description: Requests allowed per day for this caller.
      schema:
        type: integer
    X-RateLimit-Remaining:
      description: Requests left today.
      schema:
        type: integer
    X-RateLimit-Reset:
      description: When the daily allowance resets, as Unix seconds.
      schema:
        type: integer
    Retry-After:
      description: Seconds to wait before retrying.
      schema:
        type: integer
  responses:
    InvalidRequest:
      description: A parameter is missing or not valid. `fields` says which.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_request
              message: >-
                range: Invalid option: expected one of
                "today"|"yesterday"|"24h"|"7d"|"30d"|"90d"|"mtd"|"last_month"|"ytd"|"12m"|"all"
    Unauthorized:
      description: No key was sent for a site that needs one, or the key is not valid.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: >-
                That API key is not valid. It may have been revoked or expired.
                Create a new one under API and MCP, API keys.
    PlanLimitReached:
      description: >-
        The key's workspace is paused (its trial reached its events for the
        month, or it has no plan), or a write would go past the plan's limits,
        such as its number of sites. Choosing a plan in the dashboard, under
        Billing, resumes it.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: plan_limit_reached
              message: >-
                This organization's data is paused: its trial reached its events
                for this month, or it has no plan since the trial or a plan
                ended. An owner can choose a plan at
                https://crispstats.com/app/billing to resume at once.
    Forbidden:
      description: >-
        The key lacks the permission this request needs, or is limited to other
        sites.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: forbidden
              message: >-
                That API key cannot read revenue and payments: it needs the
                Revenue and payments: read permission. Edit the key under API
                and MCP, API keys.
    NotFound:
      description: >-
        The site, key, funnel, note, alert or visitor does not exist, or this
        key cannot reach it. Another workspace's objects answer the same way.
      headers: {}
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: That site was not found, or this key does not have access to it.
    RateLimited:
      description: The caller is over its rate limit.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Too many requests at once. Wait 4 seconds and try again.
  schemas:
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - invalid_request
                - unauthorized
                - plan_limit_reached
                - forbidden
                - not_found
                - method_not_allowed
                - rate_limited
                - internal_error
                - service_unavailable
            message:
              type: string
              description: What went wrong and how to fix it.
            fields:
              type: object
              additionalProperties:
                type: string
              description: 'On validation errors: the problem with each parameter.'
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        An API key that starts with cs_sk_, created under API and MCP, API keys.
        A key covers every site of its workspace or a chosen list, and carries
        permissions per resource (Analytics, Revenue and payments, Goals and
        events, Funnels, Sites, Notes, Alerts) and extras (Visitor details, Raw
        events export, Team members, Workspace name, See API keys, Manage API
        keys). A change acts for the key's creator, with their current role. A
        request outside them answers 403 naming the missing permission.

````

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