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

# Create a purchase

> Records a purchase for a user. Stripe and Paddle are the recommended paths when calling this
API directly; App Store and Play Store purchases normally flow through the Qonversion SDK and
rarely need to be POSTed manually.

Provide exactly one of `stripe_store_data`, `paddle_store_data`, `app_store_data`, or `play_store_data`.


<Note>Stripe and Paddle are the typical use cases. `app_store_data` and `play_store_data` are
accepted for completeness but App Store and Play Store purchases are normally handled
automatically by the Qonversion SDK.</Note>


## OpenAPI

````yaml /api-reference/rest-api.yaml post /users/{user_id}/purchases
openapi: 3.1.0
info:
  title: Qonversion REST API
  version: '3.1'
  description: >
    Qonversion REST API follows REST standards. It has predictable
    resource-oriented URLs,

    accepts JSON-encoded request bodies, returns JSON-encoded responses, and
    uses standard

    HTTP response codes, authentication, and verbs.


    ## Where to find your keys


    1. Sign in to the Qonversion dashboard at https://dash.qonversion.io/.

    2. Open your project and go to **Project Settings** in the sidebar.

    3. The **Project Keys** section exposes three values:
       - **Project Key** - bearer token for the v3 REST endpoints documented here.
         A 32-character URL-safe random string (`A-Z`, `a-z`, `0-9`, `_`, `-`) with no fixed prefix
         (e.g. `JFPATc4VaaWYsfurml3qZ4zsmNw0VfWH`).
       - **API Key** - used in the URL path of the analytics API
         (`https://api.qonversion.io/v1/analytics/{API_KEY}/...`); do NOT use it as a v3 bearer.
       - **Secret Key** - bearer for the entitlement grant/revoke endpoints. Always prefixed with `sk_`.

    ## Sandbox vs production


    Project Keys with the `test_` prefix (e.g.
    `test_PV77YHL7qnGvsdmpTs7gimsxUvY-Znl2`) target the

    **sandbox** environment. Production keys have no prefix. The same prefix
    scheme applies to Secret

    Keys. Sandbox users do not affect production analytics.


    ## Errors


    All endpoints share the error envelope shown in `Error`. The
    `meta.reference` URL is set

    automatically for the documented machine-readable codes (`invalid_data`,
    `invalid_request`,

    `invalid_entitlement_data`); other errors omit `meta`. There is no
    `meta.fields[]` array.
servers:
  - url: https://api.qonversion.io/v3
    description: Production
security:
  - ProjectKey: []
paths:
  /users/{user_id}/purchases:
    post:
      tags:
        - Purchases
      summary: Create a purchase
      description: >
        Records a purchase for a user. Stripe and Paddle are the recommended
        paths when calling this

        API directly; App Store and Play Store purchases normally flow through
        the Qonversion SDK and

        rarely need to be POSTed manually.


        Provide exactly one of `stripe_store_data`, `paddle_store_data`,
        `app_store_data`, or `play_store_data`.
      operationId: createPurchase
      parameters:
        - name: user_id
          in: path
          required: true
          schema:
            type: string
          description: Qonversion User ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - currency
                - price
                - purchased
              properties:
                currency:
                  type: string
                  description: >-
                    Three-letter ISO 4217 currency code (case-insensitive;
                    normalised to uppercase server-side)
                price:
                  type: string
                  description: Monetary amount (decimal string, e.g. "12.99")
                purchased:
                  type: integer
                  format: int64
                  description: Unix epoch seconds of the transaction
                stripe_store_data:
                  $ref: '#/components/schemas/StripeStoreData'
                paddle_store_data:
                  $ref: '#/components/schemas/PaddleStoreData'
                app_store_data:
                  type: object
                  description: >
                    App Store transaction data. Use only when posting App Store
                    purchases manually

                    instead of via the SDK.
                  required:
                    - transaction_id
                    - original_transaction_id
                    - product_id
                  properties:
                    transaction_id:
                      type: string
                    original_transaction_id:
                      type: string
                    product_id:
                      type: string
                    receipt:
                      type: string
                      description: Base64-encoded App Store receipt
                play_store_data:
                  type: object
                  description: >
                    Google Play transaction data. Use only when posting Play
                    purchases manually

                    instead of via the SDK.
                  required:
                    - order_id
                    - purchase_token
                    - product_id
                    - type
                  properties:
                    order_id:
                      type: string
                    purchase_token:
                      type: string
                    product_id:
                      type: string
                    type:
                      type: string
                      enum:
                        - subscription
                        - non_recurring
            example:
              currency: USD
              price: '12.99'
              purchased: 1653458781
              stripe_store_data:
                subscription_id: sub_123e4567
                product_id: prod_123e4567
      responses:
        '201':
          description: Purchase created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Purchase'
              example:
                user_id: QON_7791a27fc4e747412381842b36a
                currency: USD
                price: '12.99'
                purchased: 1653458781
                stripe_store_data:
                  subscription_id: sub_123e4567
                  product_id: prod_123e4567
        '400':
          description: Invalid data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >
            Returned when the user is not found (`User not found`) or when the
            referenced product

            cannot be located (`Qonversion product with the specified ID not
            found`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ProjectKey: []
components:
  schemas:
    StripeStoreData:
      type: object
      required:
        - subscription_id
        - product_id
      properties:
        subscription_id:
          type: string
          description: Stripe subscription identifier
          example: sub_123e4567
        product_id:
          type: string
          description: Stripe product identifier
          example: prod_123e4567
    PaddleStoreData:
      type: object
      required:
        - transaction_id
        - product_id
        - type
      properties:
        type:
          type: string
          enum:
            - subscription
            - non_recurring
          description: Purchase type
          example: subscription
        transaction_id:
          type: string
          description: Paddle transaction identifier. Always present.
          example: txn_01hv4rrk
        subscription_id:
          type: string
          description: >-
            Paddle subscription identifier. Required when `type` is
            `subscription`; omitted for `non_recurring` purchases.
          example: sub_01hv4rrk
        product_id:
          type: string
          description: Paddle product identifier
          example: pro_01hv4rrk
    Purchase:
      type: object
      description: >
        The response echoes whichever store-data variant was provided in the
        request:

        exactly one of `stripe_store_data`, `paddle_store_data`,
        `app_store_data`, or `play_store_data` will be present.
      required:
        - user_id
      properties:
        user_id:
          type: string
          description: Qonversion User ID
          example: QON_7791a27fc4e747412381842b36a
        currency:
          type: string
          description: Three-letter ISO 4217 currency code (uppercase)
          example: USD
        price:
          type: string
          description: Monetary amount (decimal string)
          example: '12.99'
        purchased:
          type: integer
          format: int64
          description: Unix epoch seconds of the transaction
          example: 1653458781
        stripe_store_data:
          $ref: '#/components/schemas/StripeStoreData'
        paddle_store_data:
          $ref: '#/components/schemas/PaddleStoreData'
        app_store_data:
          type: object
          description: >-
            App Store transaction data. Echoed only when the purchase was
            created with `app_store_data`.
          properties:
            transaction_id:
              type: string
            original_transaction_id:
              type: string
            product_id:
              type: string
            receipt:
              type: string
              description: Base64-encoded App Store receipt
        play_store_data:
          type: object
          description: >-
            Google Play transaction data. Echoed only when the purchase was
            created with `play_store_data`.
          properties:
            order_id:
              type: string
            purchase_token:
              type: string
            product_id:
              type: string
            type:
              type: string
              enum:
                - subscription
                - non_recurring
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - type
          properties:
            type:
              type: string
              enum:
                - request
                - resource
                - logical
                - internal
              description: Error category
            code:
              type: string
              description: Machine-readable error code
            message:
              type: string
              description: Human-readable error message
        meta:
          type: object
          description: >
            Optional metadata. Currently only contains a `reference` URL for a
            small subset

            of error codes (`invalid_data`, `invalid_request`,
            `invalid_entitlement_data`).
          properties:
            reference:
              type: string
              format: uri
              example: >-
                https://documentation.qonversion.io/reference/handling-api-errors
  securitySchemes:
    ProjectKey:
      type: http
      scheme: bearer
      description: >
        Use your **Project Key** from the Qonversion dashboard

        (Project Settings -> Project Keys -> Project Key).


        Production keys have no prefix; keys prefixed with `test_` target the
        sandbox environment.


        Example (sandbox): `Bearer test_PV77YHL7qnGvsdmpTs7gimsxUvY-Znl2`

        Example (production): `Bearer JFPATc4VaaWYsfurml3qZ4zsmNw0VfWH`

````