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

# Create Invoice Preview

> Previews the upcoming invoice for a subscription — the pending charges, line items, and applicable discounts — without creating a real invoice.



## OpenAPI

````yaml /openapi.json post /invoices/previews
openapi: 3.1.0
info:
  title: OpenLoop API
  version: 0.1.0
  description: >-
    Unified reference for the OpenLoop Patient (clinical) and Payments & Revenue
    APIs.
servers:
  - url: https://api.openloophealth.com/v0.1
    description: Production partner edge
  - url: https://api-staging.openloophealth.com/v0.1
    description: Staging partner edge (sandbox credentials)
security: []
paths:
  /invoices/previews:
    post:
      tags:
        - Invoices
      summary: Create Invoice Preview
      description: >-
        Previews the upcoming invoice for a subscription — the pending charges,
        line items, and applicable discounts — without creating a real invoice.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                provider_subscription_id:
                  type: string
                  description: >-
                    Provider subscription id to preview the upcoming invoice for
                    (e.g. `test_subscription_id`).
                discounts:
                  type: array
                  items:
                    type: object
                    properties:
                      coupon:
                        type: string
                        description: >-
                          Provider coupon id. Exactly one of `coupon` or
                          `promotion_code` per entry.
                      promotion_code:
                        type: string
                        description: >-
                          Provider promotion-code id. Exactly one of `coupon` or
                          `promotion_code` per entry.
                  description: >-
                    Ad-hoc, not-yet-applied discounts to simulate. Each entry
                    has exactly one of `coupon` or `promotion_code`. Omitted
                    entirely when not provided, in which case the preview
                    inherits the subscription/customer's existing discounts.
              required:
                - provider_subscription_id
            example:
              provider_subscription_id: test_subscription_id
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      provider_customer_id:
                        type: string
                        description: Provider customer id derived from the subscription.
                      provider_invoice_id:
                        type:
                          - string
                          - 'null'
                        description: '`null` on a preview (the invoice is not yet created).'
                      provider_subscription_id:
                        type:
                          - string
                          - 'null'
                        description: The subscription being previewed.
                      number:
                        type:
                          - string
                          - 'null'
                        description: '`null` on a preview.'
                      description:
                        type:
                          - string
                          - 'null'
                        description: Invoice description.
                      status:
                        type: string
                        description: Preview status (e.g. `draft`).
                      currency:
                        type: string
                        description: Currency code (e.g. `usd`).
                      paid_date:
                        type: number
                        description: '`0` on a preview.'
                      due_date:
                        type:
                          - number
                          - 'null'
                        description: Unix timestamp the invoice is due.
                      total_amount:
                        type: number
                        description: Upcoming invoice total in cents.
                      total_paid:
                        type: number
                        description: '`0` on a preview.'
                      post_payment_credit_notes_amount:
                        type: number
                        description: '`0` on a preview.'
                      period_end:
                        type: number
                        description: Billing period end (Unix timestamp).
                      period_start:
                        type: number
                        description: Billing period start (Unix timestamp).
                      billing_reason:
                        type:
                          - string
                          - 'null'
                        description: Why the invoice would be created (e.g. `upcoming`).
                      collection_method:
                        type: string
                        description: '`charge_automatically` or `send_invoice`.'
                      hosted_invoice_url:
                        type:
                          - string
                          - 'null'
                        description: '`null` on a preview.'
                      invoice_pdf:
                        type:
                          - string
                          - 'null'
                        description: '`null` on a preview.'
                      discounts:
                        type: array
                        items:
                          type: object
                          properties:
                            provider_discount_id:
                              type: string
                              description: Provider discount ID.
                            provider_coupon_id:
                              type:
                                - string
                                - 'null'
                              description: >-
                                Provider coupon ID that created the discount, or
                                `null`.
                            provider_promotion_code_id:
                              type:
                                - string
                                - 'null'
                              description: >-
                                Provider promotion code ID that created the
                                discount, or `null` when a coupon was applied
                                directly.
                        description: Applicable discount details.
                      payments:
                        type: array
                        items:
                          type: object
                          properties:
                            provider_payment_id:
                              type: string
                              description: Provider payment (invoice-payment) ID.
                            provider_payment_intent_id:
                              type:
                                - string
                                - 'null'
                              description: >-
                                Provider payment intent ID for this payment.
                                `null` whenever the provider recorded no payment
                                intent for it — a charge payment, a
                                payment-record payment, or an invoice finalized
                                before 2019-03-15.
                            amount_paid_cents:
                              type: number
                              description: Amount paid in cents.
                            amount_requested_cents:
                              type: number
                              description: Amount requested in cents.
                            currency:
                              type: string
                              description: Currency code (e.g. `"usd"`).
                            created:
                              type: number
                              description: Unix timestamp the payment was created.
                        description: Empty on a preview.
                      lines:
                        type: array
                        items:
                          type: object
                          properties:
                            provider_product_id:
                              type: string
                              description: Provider product ID.
                            provider_price_id:
                              type: string
                              description: Provider price ID.
                            product:
                              type:
                                - object
                                - 'null'
                              properties:
                                name:
                                  type:
                                    - string
                                    - 'null'
                                  description: Product name.
                                description:
                                  type:
                                    - string
                                    - 'null'
                                  description: Product description.
                                status:
                                  type: string
                                  description: Product status.
                                metadata:
                                  type: object
                                  description: Custom metadata (string key/value pairs).
                              description: Product details or `null`.
                            billing_interval:
                              type:
                                - string
                                - 'null'
                              description: Billing interval (e.g. `"month"`).
                            billing_interval_count:
                              type:
                                - number
                                - 'null'
                              description: Number of intervals per billing cycle.
                            currency:
                              type: string
                              description: Currency code (e.g. `"usd"`).
                            description:
                              type:
                                - string
                                - 'null'
                              description: Line description.
                            amount_cents:
                              type: number
                              description: Line amount in cents.
                            quantity:
                              type: number
                              description: Line quantity.
                            discounts:
                              type: array
                              items:
                                type: object
                                properties:
                                  provider_discount_id:
                                    type: string
                                    description: Provider discount ID.
                                  provider_coupon_id:
                                    type:
                                      - string
                                      - 'null'
                                    description: >-
                                      Provider coupon ID that created the
                                      discount, or `null`.
                                  provider_promotion_code_id:
                                    type:
                                      - string
                                      - 'null'
                                    description: >-
                                      Provider promotion code ID that created
                                      the discount, or `null` when a coupon was
                                      applied directly.
                              description: >-
                                Discounts applied to the line item (same shape
                                as the invoice `discounts` fields above).
                        description: Pending line item details.
                      created:
                        type:
                          - number
                          - 'null'
                        description: '`null` on a preview.'
                required:
                  - data
              example:
                data:
                  provider_customer_id: test_customer_id
                  provider_invoice_id: null
                  provider_subscription_id: test_subscription_id
                  number: null
                  description: null
                  status: draft
                  currency: usd
                  paid_date: 0
                  due_date: null
                  total_amount: 19900
                  total_paid: 0
                  post_payment_credit_notes_amount: 0
                  period_end: 1900
                  period_start: 1800
                  billing_reason: upcoming
                  collection_method: charge_automatically
                  hosted_invoice_url: null
                  invoice_pdf: null
                  discounts: []
                  payments: []
                  lines: []
                  created: null
        '400':
          description: 'ValidationError: Missing `provider_subscription_id`.'
        '401':
          description: Missing or invalid bearer token.
        '403':
          description: >-
            No configuration exists for your account, or provider access has
            been disabled for it.
        '404':
          description: >-
            NotFoundError: Subscription not found (the payment provider
            `resource_missing`).
        '500':
          description: An upstream provider error.
      security:
        - serviceToken: []
        - userToken: []
components:
  securitySchemes:
    serviceToken:
      type: oauth2
      description: >-
        Service (M2M) access token issued by POST /auth/token using the
        client_credentials grant. Required scopes, where known, are listed on
        each operation below.
      flows:
        clientCredentials:
          tokenUrl: https://api.openloophealth.com/v0.1/auth/token
          scopes: {}
    userToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User access token issued by POST /auth/token via the verification-code
        grant (after Verify a one-time code) or the refresh_token grant.

````

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