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

# Preview an Invoice Request

> Price an invoice request as a draft and get it back as JSON, a PDF, or the invoice email, without saving it.



## OpenAPI

````yaml post /billing/invoices/preview
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.122.7
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
  - name: Payment Connector Webhooks
  - name: Moderation
  - name: Invoices
  - name: Workload Identity
paths:
  /billing/invoices/preview:
    post:
      tags:
        - Invoices
      summary: Preview an invoice request
      description: Prices the body as a draft and returns it. No row is saved.
      operationId: preview_invoice_request
      parameters:
        - name: format
          in: query
          required: false
          schema:
            type: string
            description: >-
              The preview body. `json` returns the invoice JSON. `pdf` returns
              the PDF with a draft mark.

              `email` returns the HTML of the invoice email. A preview saves no
              row.
            enum:
              - json
              - pdf
              - email
          style: form
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInvoiceRequest'
        required: true
      responses:
        '200':
          description: >-
            The preview in the format asked for: the PDF with a draft mark for
            `pdf`, the invoice JSON (an `InvoiceResponse`) for `json`, or the
            HTML of the invoice email for `email`. The SDKs return the raw
            response, so read it as bytes, JSON or text to match `format`.
          content:
            application/pdf:
              schema:
                type: string
                format: binary
        '400':
          description: >-
            A request field or the format parameter is not valid
            (InvalidRequestParameters or InvalidQueryParams).
        '404':
          description: The customer, a product or an addon does not exist (NotFound).
        '422':
          description: >-
            The body is not valid JSON, has an unknown field, or breaks an
            invoice rule (InvalidRequestBody).
        '500':
          description: Something went wrong :(
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import DodoPayments from 'dodopayments';

            const client = new DodoPayments({
              bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.invoices.preview({
              collection_method: 'auto_charge',
              currency: 'AED',
              customer_id: 'customer_id',
              items: [
                {
                  description: 'description',
                  kind: 'custom',
                  tax_category: 'digital_products',
                  unit_amount: 0,
                },
              ],
            });

            console.log(response);

            const content = await response.blob();
            console.log(content);
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            response = client.invoices.preview(
                collection_method="auto_charge",
                currency="AED",
                customer_id="customer_id",
                items=[{
                    "description": "description",
                    "kind": "custom",
                    "tax_category": "digital_products",
                    "unit_amount": 0,
                }],
            )
            print(response)
            content = response.read()
            print(content)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tresponse, err := client.Invoices.Preview(context.TODO(), dodopayments.InvoicePreviewParams{\n\t\tCollectionMethod: dodopayments.F(dodopayments.CollectionMethodAutoCharge),\n\t\tCurrency:         dodopayments.F(dodopayments.CurrencyAed),\n\t\tCustomerID:       dodopayments.F(\"customer_id\"),\n\t\tItems: dodopayments.F([]dodopayments.InvoicePreviewParamsItemUnion{dodopayments.InvoicePreviewParamsItemsCustomItem{\n\t\t\tDescription: dodopayments.F(\"description\"),\n\t\t\tKind:        dodopayments.F(dodopayments.InvoicePreviewParamsItemsCustomItemKindCustom),\n\t\t\tTaxCategory: dodopayments.F(dodopayments.TaxCategoryDigitalProducts),\n\t\t\tUnitAmount:  dodopayments.F(int64(0)),\n\t\t}}),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response)\n}\n"
        - lang: Java
          source: |-
            package com.dodopayments.api.example;

            import com.dodopayments.api.client.DodoPaymentsClient;
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
            import com.dodopayments.api.core.http.HttpResponse;
            import com.dodopayments.api.models.invoices.CollectionMethod;
            import com.dodopayments.api.models.invoices.InvoicePreviewParams;
            import com.dodopayments.api.models.misc.Currency;
            import com.dodopayments.api.models.misc.TaxCategory;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

                    InvoicePreviewParams params = InvoicePreviewParams.builder()
                        .collectionMethod(CollectionMethod.AUTO_CHARGE)
                        .currency(Currency.AED)
                        .customerId("customer_id")
                        .addItem(InvoicePreviewParams.Item.CustomItem.builder()
                            .description("description")
                            .taxCategory(TaxCategory.DIGITAL_PRODUCTS)
                            .unitAmount(0)
                            .build())
                        .build();
                    HttpResponse response = client.invoices().preview(params);
                }
            }
        - lang: Kotlin
          source: |-
            package com.dodopayments.api.example

            import com.dodopayments.api.client.DodoPaymentsClient
            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
            import com.dodopayments.api.core.http.HttpResponse
            import com.dodopayments.api.models.invoices.CollectionMethod
            import com.dodopayments.api.models.invoices.InvoicePreviewParams
            import com.dodopayments.api.models.misc.Currency
            import com.dodopayments.api.models.misc.TaxCategory

            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val params: InvoicePreviewParams = InvoicePreviewParams.builder()
                    .collectionMethod(CollectionMethod.AUTO_CHARGE)
                    .currency(Currency.AED)
                    .customerId("customer_id")
                    .addItem(InvoicePreviewParams.Item.CustomItem.builder()
                        .description("description")
                        .taxCategory(TaxCategory.DIGITAL_PRODUCTS)
                        .unitAmount(0)
                        .build())
                    .build()
                val response: HttpResponse = client.invoices().preview(params)
            }
        - lang: Ruby
          source: |-
            require "dodopayments"

            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )

            response = dodo_payments.invoices.preview(
              collection_method: :auto_charge,
              currency: :AED,
              customer_id: "customer_id",
              items: [{description: "description", kind: :custom, tax_category: :digital_products, unit_amount: 0}]
            )

            puts(response)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;
            use Dodopayments\Invoices\CollectionMethod;
            use Dodopayments\Misc\Currency;
            use Dodopayments\Misc\TaxCategory;
            use Dodopayments\Misc\CountryCode;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $response = $client->invoices->preview(
                collectionMethod: CollectionMethod::AUTO_CHARGE,
                currency: Currency::AED,
                customerID: 'customer_id',
                items: [
                  [
                    'description' => 'description',
                    'kind' => 'custom',
                    'taxCategory' => TaxCategory::DIGITAL_PRODUCTS,
                    'unitAmount' => 0,
                    'quantity' => 0,
                  ],
                ],
                format: 'json',
                billingAddress: [
                  'country' => CountryCode::AF,
                  'city' => 'city',
                  'state' => 'state',
                  'street' => 'street',
                  'zipcode' => 'zipcode',
                ],
                ccEmails: ['string'],
                customerEmail: 'customer_email',
                discountIDs: ['string'],
                dueAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                dunning: ['remindersEnabled' => true, 'offsetsDays' => [0]],
                memo: 'memo',
                metadata: ['foo' => 'string'],
                paymentTerms: ['type' => 'due_on_receipt'],
                reviewRequired: true,
                taxID: 'tax_id',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using DodoPayments.Client;
            using DodoPayments.Client.Models.Invoices;
            using DodoPayments.Client.Models.Misc;

            DodoPaymentsClient client = new();

            InvoicePreviewParams parameters = new()
            {
                CollectionMethod = InvoiceCollectionMethod.AutoCharge,
                Currency = Currency.Aed,
                CustomerID = "customer_id",
                Items =
                [
                    new InvoicePreviewParamsItemCustomItem()
                    {
                        Description = "description",
                        TaxCategory = TaxCategory.DigitalProducts,
                        UnitAmount = 0,
                        Quantity = 0,
                    },
                ],
            };

            var response = await client.Invoices.Preview(parameters);

            Console.WriteLine(response);
        - lang: Rust
          source: |-
            use dodopayments::Client;

            #[tokio::main]
            async fn main() -> dodopayments::Result<()> {
                let client = Client::from_env()?;
                let result = client
                    .invoices()
                    .preview()
                    .body(dodopayments::models::InvoicesPreviewParams {
                            collection_method: Some(Box::new(dodopayments::models::CollectionMethod::AutoCharge)),
                            currency: Some(Box::new(dodopayments::models::Currency::Aed)),
                            customer_id: Some("customer_id".to_string()),
                            items: Some(vec![serde_json::json!({"description":"description","kind":"custom","tax_category":"digital_products","unit_amount":0})]),
                            ..Default::default()
                        })
                    .query(serde_json::json!({}))
                    .await?;
                println!("{result:?}");
                Ok(())
            }
components:
  schemas:
    CreateInvoiceRequest:
      type: object
      required:
        - customer_id
        - currency
        - items
        - collection_method
      properties:
        billing_address:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/InvoiceAddressRequest'
        cc_emails:
          type:
            - array
            - 'null'
          items:
            type: string
          description: 10 addresses or fewer.
        collection_method:
          $ref: '#/components/schemas/CollectionMethod'
        currency:
          $ref: '#/components/schemas/Currency'
        customer_email:
          type:
            - string
            - 'null'
          description: The customer email is used when this is not set.
        customer_id:
          type: string
        discount_ids:
          type:
            - array
            - 'null'
          items:
            type: string
          description: 20 codes or fewer.
        due_at:
          type:
            - string
            - 'null'
          format: date-time
          description: A custom due date. Do not send it with `payment_terms`.
        dunning:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/DunningRequestBody'
        items:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceItemRequest'
          description: 1 to 50 items.
        memo:
          type:
            - string
            - 'null'
        metadata:
          $ref: '#/components/schemas/Metadata'
        payment_terms:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/PaymentTerms'
              description: Do not send it with `due_at`.
        review_required:
          type: boolean
          description: '`true` keeps a renewal draft for review before it finalises.'
        tax_id:
          type:
            - string
            - 'null'
      additionalProperties: false
    InvoiceAddressRequest:
      type: object
      description: The billing address of an invoice request.
      required:
        - country
      properties:
        city:
          type:
            - string
            - 'null'
        country:
          $ref: '#/components/schemas/CountryCodeAlpha2'
          description: Two-letter ISO country code (ISO 3166-1 alpha-2)
        state:
          type:
            - string
            - 'null'
        street:
          type:
            - string
            - 'null'
        zipcode:
          type:
            - string
            - 'null'
      additionalProperties: false
    CollectionMethod:
      type: string
      enum:
        - auto_charge
        - manual
    Currency:
      type: string
      enum:
        - AED
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CHF
        - CLP
        - CNY
        - COP
        - CRC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRU
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STN
        - SVC
        - SZL
        - THB
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
    DunningRequestBody:
      type: object
      description: >-
        The reminder override of one invoice. The business settings fill the
        other dunning values.
      required:
        - reminders_enabled
      properties:
        offsets_days:
          type:
            - array
            - 'null'
          items:
            type: integer
            format: int32
          description: >-
            Days from the due date. A negative value sends the reminder before
            the due date.
        reminders_enabled:
          type: boolean
      additionalProperties: false
    InvoiceItemRequest:
      oneOf:
        - $ref: '#/components/schemas/CustomItem'
        - $ref: '#/components/schemas/ProductItem'
    Metadata:
      type: object
      title: Metadata
      description: >-
        Arbitrary key-value metadata. Values can be string, integer, number, or
        boolean.
      additionalProperties:
        oneOf:
          - type: string
            title: String
          - type: integer
            title: Integer
            format: int64
          - type: number
            title: Number
            format: double
          - type: boolean
            title: Boolean
        title: Metadata Value
        description: Metadata value can be a string, integer, number, or boolean
    PaymentTerms:
      oneOf:
        - type: object
          title: Due On Receipt
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - due_on_receipt
              x-stainless-const: true
        - type: object
          title: Net
          required:
            - days
            - type
          properties:
            days:
              type: integer
              format: int32
              minimum: 0
            type:
              type: string
              enum:
                - net
              x-stainless-const: true
      discriminator:
        propertyName: type
    CountryCodeAlpha2:
      type: string
      description: ISO country code alpha2 variant
      enum:
        - AF
        - AX
        - AL
        - DZ
        - AS
        - AD
        - AO
        - AI
        - AQ
        - AG
        - AR
        - AM
        - AW
        - AU
        - AT
        - AZ
        - BS
        - BH
        - BD
        - BB
        - BY
        - BE
        - BZ
        - BJ
        - BM
        - BT
        - BO
        - BQ
        - BA
        - BW
        - BV
        - BR
        - IO
        - BN
        - BG
        - BF
        - BI
        - KH
        - CM
        - CA
        - CV
        - KY
        - CF
        - TD
        - CL
        - CN
        - CX
        - CC
        - CO
        - KM
        - CG
        - CD
        - CK
        - CR
        - CI
        - HR
        - CU
        - CW
        - CY
        - CZ
        - DK
        - DJ
        - DM
        - DO
        - EC
        - EG
        - SV
        - GQ
        - ER
        - EE
        - ET
        - FK
        - FO
        - FJ
        - FI
        - FR
        - GF
        - PF
        - TF
        - GA
        - GM
        - GE
        - DE
        - GH
        - GI
        - GR
        - GL
        - GD
        - GP
        - GU
        - GT
        - GG
        - GN
        - GW
        - GY
        - HT
        - HM
        - VA
        - HN
        - HK
        - HU
        - IS
        - IN
        - ID
        - IR
        - IQ
        - IE
        - IM
        - IL
        - IT
        - JM
        - JP
        - JE
        - JO
        - KZ
        - KE
        - KI
        - KP
        - KR
        - KW
        - KG
        - LA
        - LV
        - LB
        - LS
        - LR
        - LY
        - LI
        - LT
        - LU
        - MO
        - MK
        - MG
        - MW
        - MY
        - MV
        - ML
        - MT
        - MH
        - MQ
        - MR
        - MU
        - YT
        - MX
        - FM
        - MD
        - MC
        - MN
        - ME
        - MS
        - MA
        - MZ
        - MM
        - NA
        - NR
        - NP
        - NL
        - NC
        - NZ
        - NI
        - NE
        - NG
        - NU
        - NF
        - MP
        - 'NO'
        - OM
        - PK
        - PW
        - PS
        - PA
        - PG
        - PY
        - PE
        - PH
        - PN
        - PL
        - PT
        - PR
        - QA
        - RE
        - RO
        - RU
        - RW
        - BL
        - SH
        - KN
        - LC
        - MF
        - PM
        - VC
        - WS
        - SM
        - ST
        - SA
        - SN
        - RS
        - SC
        - SL
        - SG
        - SX
        - SK
        - SI
        - SB
        - SO
        - ZA
        - GS
        - SS
        - ES
        - LK
        - SD
        - SR
        - SJ
        - SZ
        - SE
        - CH
        - SY
        - TW
        - TJ
        - TZ
        - TH
        - TL
        - TG
        - TK
        - TO
        - TT
        - TN
        - TR
        - TM
        - TC
        - TV
        - UG
        - UA
        - AE
        - GB
        - UM
        - US
        - UY
        - UZ
        - VU
        - VE
        - VN
        - VG
        - VI
        - WF
        - EH
        - YE
        - ZM
        - ZW
    CustomItem:
      type: object
      description: A line that exists only on this invoice.
      required:
        - kind
        - description
        - unit_amount
        - tax_category
      properties:
        description:
          type: string
        kind:
          $ref: '#/components/schemas/CustomKind'
        quantity:
          type:
            - integer
            - 'null'
          format: int32
          description: The default is 1.
          minimum: 0
        tax_category:
          $ref: '#/components/schemas/TaxCategory'
        unit_amount:
          type: integer
          format: int32
          description: The price in the smallest currency unit.
      additionalProperties: false
    ProductItem:
      type: object
      required:
        - product_id
        - quantity
      properties:
        addons:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/AttachAddonReq'
        product_id:
          type: string
        quantity:
          type: integer
          format: int32
          minimum: 0
      additionalProperties: false
    CustomKind:
      type: string
      enum:
        - custom
      x-stainless-const: true
    TaxCategory:
      type: string
      description: >-
        Represents the different categories of taxation applicable to various
        products and services.
      enum:
        - digital_products
        - saas
        - e_book
        - edtech
        - live_tutoring
    AttachAddonReq:
      type: object
      title: Attach Addon Request
      required:
        - addon_id
        - quantity
      properties:
        addon_id:
          type: string
        quantity:
          type: integer
          format: int32
          description: Number of units of this addon.
          minimum: 0
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer
      description: >-
        Send your API key as a bearer token: `Authorization: Bearer <api_key>`.
        A test mode key starts with `dodo_test_`, for example
        `dodo_test_AbCd1234EfGh5678.<secret>`. A live mode key starts with
        `dodo_live_`. Use a test mode key on `test.dodopayments.com` and a live
        mode key on `live.dodopayments.com`. Keys from before these tags have no
        tag and operate as before.

````

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