> For the complete documentation index, see [llms.txt](https://docs.digitalriver.com/commerce-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalriver.com/commerce-api/admin-apis/order-management/downloading-the-invoice.md).

# Downloading the invoice

An invoice represents a document associated with a sale you provide to the shopper. The invoice itemizes the products or services rendered, including their cost, quantity, fees, duties, and taxes. It also establishes an obligation on the part of the shopper to pay you for those products and services.

Invoices can be especially useful when selling to other businesses. For business transactions, it's often customary to send customers an invoice, which they pay later, rather than immediately billing a credit card you have on file.

This topic explains how to download the invoice PDF file.

## Invoice PDF download scenarios

You can [download the invoice PDF programmatically](#downloading-the-invoice-pdf-programmatically) or [from a webhook notification](#downloading-the-invoice-pdf-via-a-webhook-notification).

### Downloading the invoice PDF programmatically

To download the invoice PDF programmatically, follow these steps:

1. [Getting the download information for the order's invoice](#step-1-getting-the-download-information-for-the-orders-invoice)
2. [Getting the receipt for the invoice](#step-2-getting-the-receipt-for-the-invoice)

#### Step 1: Getting the download information for the order's invoice

To get the download information for the order's invoice, send a [`GET /v1/orders/{orderId}/invoices`](https://docs.digitalriver.com/commerce-api-references/admin-apis/order-management/retrieve-an-invoice-synchronous-api#v1-orders-orderid-invoices) `request`. Replace `{orderId}` with the actual order ID. This request retrieves all downloadable invoice URLs (invoiceURL) for the order. [Each invoice can be individually downloaded using the provided `receiptId`](#step-2-getting-the-receipt-for-the-invoice).

Example request:

```bash
curl --location --request GET 'https://api.digitalriver.com/v1/orders/{orderId}/invoices' \
--header 'authorization: basic ***'
```

Example `200 OK` response:

```json
{
    "invoices": [
        {
            "type": "vat_invoice",
            "invoiceURL": "https://api.digitalriver.com/v1/orders/1075294270082/invoices/{receiptId}"
        }
    ]
}
```

#### Step 2: Getting the receipt for the invoice

To retrieve the receipt for an invoice, send a [`GET /v1/orders/{orderId}/invoices/{receiptId}`](https://docs.digitalriver.com/commerce-api-references/admin-apis/order-management/retrieve-an-invoice-synchronous-api#v1-orders-orderid-invoices-receiptid) request to download the invoice by its unique invoice identifier (`receiptId`) for a specified order (`orderId`):

```bash
curl --location --request GET 'https://api.digitalriver.com/v1/orders/{orderId}/invoices/{receiptId}' \
--header 'authorization: basic ***'
```

Replace `{orderId}` with the order's identifier and `{receiptId}` with the invoice's identifier. Ensure your 'authorization' header contains the correct basic auth credentials. You will receive a 200 OK response that includes the PDF file of the invoice:

<div align="left"><figure><img src="/files/eEjILltxwYcAKkJN4W5O" alt=""><figcaption><p>Invoice PDF</p></figcaption></figure></div>

### Downloading the invoice PDF via a webhook notification

{% hint style="success" %}
You must [enable the following events when creating a webhook](https://help.digitalriver.com/help/gc/Administration/Webhook-Service/Webhook-service.htm#createWebhook) in [Global Commerce](https://gc.digitalriver.com/gc/ent/login.do) before you can perform this task:

* `order.invoice.created`: The creation of an order invoice triggers this event.
  {% endhint %}

To retrieve the invoice PDF file, follow these steps:

1. **Wait for the `order.invoice.created` event**: This event is triggered when an invoice file is created.
2. **Obtain the `fileId`**: In the notification you receive, locate the `"fileId"` value. Here's an example snippet:

   ```json
   "data": {
     "object": {
       "fileId": "9e00869b-e2f5-4663-aacb-e33687466020",
       ...
     }
   }
   ```
3. **Retrieve the Invoice PDF**: Use the fileId obtained to fetch the invoice PDF by sending a [GET /files/{fileId}/content](https://docs.digitalriver.com/commerce-api-references/admin-apis/file-management/retrieve-a-file#files-id-content) request as shown below:

   ```
   curl --location --request GET 'https://api.digitalriver.com/files/{fileId}/content' \
   --header 'Authorization: Basic<YourAuthCredentials>'
   ```

Replace `{fileId}` with the actual `fileId` value and `<YourAuthCredentials>` with your appropriate authorization header value.

```json
{
  "id": "9e00869b-e2f5-4663-aacb-e33687466020",
  "fileName": "File Name"
}
```

By performing these steps, you will be able to download the invoice PDF file associated with the generated `fileId`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digitalriver.com/commerce-api/admin-apis/order-management/downloading-the-invoice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
