Preview a Draft Invoice
Preview a draft invoice as JSON, a PDF with a draft mark, or the invoice email.
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.previewExisting('invoice_id');
console.log(response);
const content = await response.blob();
console.log(content);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_existing(
invoice_id="invoice_id",
)
print(response)
content = response.read()
print(content)package main
import (
"context"
"fmt"
"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)
func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
response, err := client.Invoices.PreviewExisting(
context.TODO(),
"invoice_id",
dodopayments.InvoicePreviewExistingParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response)
}
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.InvoicePreviewExistingParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();
HttpResponse response = client.invoices().previewExisting("invoice_id");
}
}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.InvoicePreviewExistingParams
fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()
val response: HttpResponse = client.invoices().previewExisting("invoice_id")
}require "dodopayments"
dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)
response = dodo_payments.invoices.preview_existing("invoice_id")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;
$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);
try {
$response = $client->invoices->previewExisting('invoice_id', format: 'json');
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Invoices;
DodoPaymentsClient client = new();
InvoicePreviewExistingParams parameters = new() { InvoiceID = "invoice_id" };
var response = await client.Invoices.PreviewExisting(parameters);
Console.WriteLine(response);use dodopayments::Client;
#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let invoice_id = "invoice_id";
let result = client
.invoices()
.preview_existing()
.invoice_id(invoice_id)
.query(serde_json::json!({}))
.await?;
println!("{result:?}");
Ok(())
}curl --request GET \
--url https://test.dodopayments.com/billing/invoices/{invoice_id}/preview \
--header 'Authorization: Bearer <token>'"<string>"Authorizations
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.
Path Parameters
Invoice ID
Query Parameters
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.
json, pdf, email Response
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.
The response is of type file.
Was this page helpful?
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.previewExisting('invoice_id');
console.log(response);
const content = await response.blob();
console.log(content);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_existing(
invoice_id="invoice_id",
)
print(response)
content = response.read()
print(content)package main
import (
"context"
"fmt"
"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)
func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
response, err := client.Invoices.PreviewExisting(
context.TODO(),
"invoice_id",
dodopayments.InvoicePreviewExistingParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response)
}
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.InvoicePreviewExistingParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();
HttpResponse response = client.invoices().previewExisting("invoice_id");
}
}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.InvoicePreviewExistingParams
fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()
val response: HttpResponse = client.invoices().previewExisting("invoice_id")
}require "dodopayments"
dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)
response = dodo_payments.invoices.preview_existing("invoice_id")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;
$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);
try {
$response = $client->invoices->previewExisting('invoice_id', format: 'json');
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Invoices;
DodoPaymentsClient client = new();
InvoicePreviewExistingParams parameters = new() { InvoiceID = "invoice_id" };
var response = await client.Invoices.PreviewExisting(parameters);
Console.WriteLine(response);use dodopayments::Client;
#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let invoice_id = "invoice_id";
let result = client
.invoices()
.preview_existing()
.invoice_id(invoice_id)
.query(serde_json::json!({}))
.await?;
println!("{result:?}");
Ok(())
}curl --request GET \
--url https://test.dodopayments.com/billing/invoices/{invoice_id}/preview \
--header 'Authorization: Bearer <token>'"<string>"