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

# Preview an invoice

> Previews an upcoming invoice for a billing account, showing the financial impact of potential subscription changes, such as adding products or changing quantities. This does not modify any existing subscriptions.



## OpenAPI

````yaml /api/en/workspaces.yaml post /workspaces/{workspaceId}/billing-accounts/{billingAccountId}/invoices/preview
openapi: 3.0.3
info:
  title: Altostrat Workspaces API
  version: 1.0.0
  description: >-
    The Altostrat Workspaces API is the microservice responsible for tenancy,
    billing, user identity, and organizational hierarchy.

    It serves as the foundational layer for all multi-tenancy and subscription
    logic within the Altostrat SDX platform, enabling the secure separation of
    customer data and resources for SD-WAN, network automation, and agentic AI
    features.

    This API allows you to programmatically manage:

    - **Workspaces:** The top-level containers for all tenant resources, users,
    and billing configurations.

    - **Organizations:** Hierarchical entities used to model customer tenants or
    business units, track resource usage, and apply limits.

    - **Billing & Subscriptions:** The financial accounts and Stripe-powered
    subscriptions that govern access to Altostrat SDX features and resources.

    - **Members & Access:** The users and their specific roles (Owner, Admin,
    Viewer) within a workspace.

    Developers use this API to build the structural foundation and manage the
    billing lifecycle upon which all other Altostrat SDX automation and AI
    features operate.
servers:
  - url: https://v1.api.altostrat.io
    description: Production API Server
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: Manage workspaces, the top-level containers for all resources.
  - name: Workspace Members
    description: Manage user access and roles within a workspace.
  - name: Organizations
    description: Manage hierarchical organizations for tenancy and resource segmentation.
  - name: Billing Accounts
    description: Manage financial accounts linked to Stripe for billing and subscriptions.
  - name: Subscriptions
    description: Manage product subscriptions powered by Stripe.
  - name: Invoices
    description: Retrieve invoice history and preview upcoming billing changes.
  - name: Payment Methods
    description: Manage customer payment methods for subscriptions.
  - name: Public
    description: Unauthenticated endpoints for retrieving public organization information.
paths:
  /workspaces/{workspaceId}/billing-accounts/{billingAccountId}/invoices/preview:
    post:
      tags:
        - Invoices
      summary: Preview an invoice
      description: >-
        Previews an upcoming invoice for a billing account, showing the
        financial impact of potential subscription changes, such as adding
        products or changing quantities. This does not modify any existing
        subscriptions.
      parameters:
        - $ref: '#/components/parameters/WorkspaceId'
        - $ref: '#/components/parameters/BillingAccountId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoicePreviewRequest'
      responses:
        '200':
          description: The previewed invoice object.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StripeInvoice'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          description: >-
            Unprocessable Entity - The preview could not be generated, for
            example, if a requested product does not have a configured price in
            Stripe.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: unprocessable_entity
                code: product_not_available
                message: >-
                  The product 'sso_monthly' is not available for invoice
                  preview. Please ensure you have a price with this lookup key
                  in Stripe.
                doc_url: https://docs.altostrat.io/errors/product_not_available
        '500':
          $ref: '#/components/responses/ServerError'
components:
  parameters:
    WorkspaceId:
      name: workspaceId
      in: path
      required: true
      description: The ID of the workspace.
      schema:
        type: string
        example: ws_a1b2c3d4e5f6g7h8
    BillingAccountId:
      name: billingAccountId
      in: path
      required: true
      description: >-
        The ID of the billing account, which corresponds to a Stripe Customer ID
        (`cus_...`).
      schema:
        type: string
        example: cus_a1b2c3d4e5f6g7h8
  schemas:
    InvoicePreviewRequest:
      type: object
      properties:
        subscription_id:
          type: string
          description: >-
            The ID of an existing subscription to preview changes for. If
            omitted, previews a new subscription.
          example: sub_a1b2c3d4e5f6g7h8
        items:
          type: array
          description: >-
            A list of products and their new quantities to preview. To remove a
            product, set its quantity to 0 or omit it.
          items:
            type: object
            properties:
              product_type:
                type: string
                description: The type of the meterable product.
                enum:
                  - locations
                  - users
                  - sso
                example: locations
              quantity:
                type: integer
                description: The new quantity for this product.
                minimum: 0
                example: 15
              interval:
                type: string
                description: >-
                  The billing interval. If omitted, it's inferred from the
                  existing subscription or defaults to 'month'.
                enum:
                  - month
                  - year
                example: month
        cancel_subscription:
          type: boolean
          description: >-
            Set to `true` to preview the invoice for canceling the subscription
            at the end of the current period.
          example: false
    StripeInvoice:
      type: object
      properties:
        id:
          type: string
          example: in_1Kb...
        customer_id:
          type: string
          example: cus_...
        status:
          type: string
          example: paid
        amount_due:
          type: integer
          description: Final amount due in the smallest currency unit (e.g., cents).
          example: 999
        amount_paid:
          type: integer
          description: The amount paid on this invoice in the smallest currency unit.
          example: 999
        currency:
          type: string
          example: usd
        created_at:
          type: string
          format: date-time
          example: '2025-10-29T00:40:06.000000Z'
        subtotal:
          type: integer
          description: Total of all line items before discounts and taxes.
          example: 1099
        total:
          type: integer
          description: Total after discounts and taxes.
          example: 999
        tax:
          type: integer
          nullable: true
          description: The amount of tax on this invoice.
          example: 0
        discount_amount:
          type: integer
          nullable: true
          description: The total discount amount applied to this invoice.
          example: 100
        discount_names:
          type: array
          items:
            type: string
          example:
            - 10% Off Coupon
        lines:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceLineItem'
        due_date:
          type: string
          format: date-time
          nullable: true
          example: null
        hosted_invoice_url:
          type: string
          format: uri
          nullable: true
          example: https://invoice.stripe.com/...
        invoice_pdf:
          type: string
          format: uri
          nullable: true
          example: https://pay.stripe.com/...
        number:
          type: string
          nullable: true
          example: AB123-001
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          description: A broad category for the error (e.g., 'invalid_request_error').
          example: invalid_request_error
        code:
          type: string
          description: A short, unique string identifying the specific error.
          example: parameter_missing
        message:
          type: string
          description: A human-readable description of what went wrong.
          example: The 'name' parameter is required for this request.
        doc_url:
          type: string
          description: >-
            A direct link to the documentation page for this specific error
            code.
          example: https://docs.altostrat.io/errors/parameter_missing
    InvoiceLineItem:
      type: object
      properties:
        id:
          type: string
          example: il_1Kb...
        description:
          type: string
          example: 10 × Locations
        amount:
          type: integer
          description: The total amount for this line item in the smallest currency unit.
          example: 1000
        currency:
          type: string
          example: usd
        quantity:
          type: integer
          example: 10
        price_id:
          type: string
          nullable: true
          example: price_...
        unit_amount:
          type: integer
          nullable: true
          description: The unit amount in the smallest currency unit.
          example: 100
        product_name:
          type: string
          nullable: true
          example: Locations
  responses:
    BadRequest:
      description: >-
        Bad Request - The request was malformed or contained invalid parameters.
        The response body will contain details about the error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            type: invalid_request_error
            code: parameter_invalid
            message: The 'name' parameter cannot exceed 50 characters.
            doc_url: https://docs.altostrat.io/errors/parameter_invalid
    Unauthorized:
      description: >-
        Unauthorized - The request was not authenticated. Ensure you have
        provided a valid Bearer token in the Authorization header.
    Forbidden:
      description: >-
        Forbidden - The authenticated user does not have permission to perform
        this action.
    NotFound:
      description: Not Found - The requested resource could not be found.
    ServerError:
      description: Internal Server Error - An unexpected error occurred on the server.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            type: api_error
            code: internal_server_error
            message: An internal server error occurred. Please try again later.
            doc_url: https://docs.altostrat.io/errors/internal_server_error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Enter your JWT in the format: Bearer {token}'

````