Download an invoice
Route
POST
/api/v1/invoices/:id/download
Logic
- If the invoice has already been generated, you will receive in the response the
invoice
object with thefile_url
where you can download your pdf file. - If the invoice has never been generated, this endpoint will returns an empty
200
response, you will receive ainvoice.generated
webhook when the PDF file is ready. You can check the webhook documentation to know more about this.
Usage
- Curl
- Python
- Ruby
- Javascript
- Go
- C#
- PHP
LAGO_URL="https://api.getlago.com"
INVOICE_ID="__YOU_INVOICE_ID__"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/invoices/$INVOICE_ID/download" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
client = Client(api_key='__YOUR_API_KEY__')
invoice = None
try:
invoice = client.invoices.download('5eb02857-a71e-4ea2-bcf9-57d8885990ba') # Invoice ID
except LagoApiError as e:
repair_broken_state(e) # do something on error or raise your own exception
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})
client.invoices.download('5eb02857-a71e-4ea2-bcf9-57d8885990ba') // Invoice ID
await client.invoices.downloadInvoice('invoice-id');
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
lagoClient := lago.New().
SetApiKey("__YOUR_API_KEY__")
invoice, err := lagoClient.Invoice().Download("__YOUR_INVOICE_ID__")
if err != nil {
// Error is *lago.Error
panic(err)
}
// invoice is *lago.Invoice
fmt.Println(invoice)
// If the invoice has to be generated, the response is empty
// And you will get a webhook `invoice.generated`
}
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class DownloadInvoiceExample
{
public static void Main()
{
Configuration.Default.BasePath = "https://api.getlago.com/api/v1";
// Configure HTTP bearer authorization: bearerAuth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new InvoicesApi(Configuration.Default);
var id = "183da83c-c007-4fbb-afcd-b00c07c41ffe"; // string | ID of the existing Lago Invoice
try
{
// Download an existing invoice
Invoice result = apiInstance.DownloadInvoice(id);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling InvoicesApi.DownloadInvoice: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: bearerAuth
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new OpenAPI\Client\Api\InvoicesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$id = "183da83c-c007-4fbb-afcd-b00c07c41ffe"; // string | ID of the existing Lago Invoice
try {
$result = $apiInstance->downloadInvoice($id);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling InvoicesApi->downloadInvoice: ', $e->getMessage(), PHP_EOL;
}
Responses
- HTTP 200
- HTTP 401
- HTTP 404
- The
invoice
file has already been generated. - The
invoice
file has not been generated, returns an empty response.
{
"status": 401,
"error": "Unauthorized"
}
Access to the API endpoint is unhautorized.
Possible reasons are:
- The
Authorization
header is missing - The
Authorization
header does not contain the API key - The Api key is invalid or expired
{
"status": 404,
"error": "Bad Request",
"code": "invoice_not_found"
}
The invoice
is not found.