POST
/
v1
/
orders
/
{id}
/
invoice
import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.orders.generateInvoice({
    id: "<value>",
  });

  // Handle the result
  console.log(result);
}

run();
"<any>"

Once the invoice is generated, it’s permanent and cannot be modified.

Make sure the billing details (name and address) are correct before generating the invoice. You can update them before generating the invoice by calling the PATCH /v1/orders/{id} endpoint.

After successfully calling this endpoint, you get a 202 response, meaning the generation of the invoice has been scheduled. It usually only takes a few seconds before you can retrieve the invoice using the GET /v1/orders/{id} /invoice endpoint.

If you want a reliable notification when the invoice is ready, you can listen to the order.updated webhook and check the is_invoice_generated field.

Authorizations

Authorization
string
header
required

You can generate an Organization Access Token from your organization's settings.

Path Parameters

id
string
required

The order ID.

Response

202
application/json

Successful Response

The response is of type any.