Retrieve an invoice by ID with bearer-token authentication and a runnable Python example.
Retrieve an invoice by ID to inspect its customer details, items, amounts, and metadata in your API integration.
Audience: Developers using the Stax API.
Retrieve an invoice
- Prepare a merchant API key for bearer-token authentication.
- Copy the invoice's
idfrom a Get All Invoices response. Use an invoice belonging to the merchant associated with your API key. - Run the Python 3 example below. Enter your API key and invoice ID when prompted; the API key input stays hidden. Use the recommended starting configuration shown here: Python's standard library with no extra packages, no optional query parameters, and a 30-second request timeout.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import quote
from urllib.request import Request, urlopen
api_key = getpass.getpass("Merchant API key: ").strip()
# Copy the selected invoice's id from the data array returned by GET /invoice.
# The example UUID matches the documented API response; enter your own invoice ID.
example_invoice_id = "e40bd293-f754-4d15-a6cb-56514757b73b"
invoice_id = input(f"Invoice ID (example: {example_invoice_id}): ").strip()
if not api_key or not invoice_id:
sys.exit("Enter both a merchant API key and an invoice ID.")
request = Request(
f"https://apiprod.fattlabs.com/invoice/{quote(invoice_id, safe='')}",
headers={"Authorization": f"Bearer {api_key}", "Accept": "application/json"},
method="GET",
)
try:
with urlopen(request, timeout=30) as response:
invoice = json.load(response)
if not isinstance(invoice, dict) or not invoice.get("id"):
sys.exit("Unexpected response: no invoice object with an ID was returned.")
print(json.dumps(invoice, indent=2))
if invoice.get("payment_method") is None:
print("No payment method is available for this invoice.")
except HTTPError as error:
print(f"Request failed: HTTP {error.code}", file=sys.stderr)
print(error.read().decode("utf-8", errors="replace"), file=sys.stderr)
sys.exit(1)
except (URLError, TimeoutError) as error:
sys.exit(f"Connection failed: {error}")
except (ValueError, UnicodeError) as error:
sys.exit(f"Could not decode the invoice response: {error}")A successful request returns HTTP 200 and an invoice object. For the documented example invoice, the response includes these fields (other fields omitted here):
{
"id": "e40bd293-f754-4d15-a6cb-56514757b73b",
"status": "PAID",
"total": 1,
"balance_due": 0,
"total_paid": 1
}If the request fails, the script prints the HTTP status and response body. For an invalid ID, check that you copied the invoice's id, not its customer's ID. For an authentication failure, check that your merchant API key belongs to the invoice's merchant.
Use Update an Invoice to modify an invoice. For the example ID above, the request path is PUT /invoice/e40bd293-f754-4d15-a6cb-56514757b73b; use your own invoice ID as the final path segment.
Key Features
- Retrieve detailed information about an invoice by its unique ID.
- Inspect invoice attributes, including:
- Customer information (e.g., name, email, address).
- Items and associated costs.
- Payment status and method (if applicable).
- Any metadata or additional fields associated with the invoice.
- Use Get All Invoices when you need to filter a list of invoices instead of retrieving one known ID.
Optional: Find invoices before retrieving one
Use Get All Invoices (GET /invoice) to search for invoices, then pass the selected invoice's id to this endpoint. The following filters belong to the list endpoint, not this single-invoice request. Refer to that endpoint for parameter usage.
| Parameter | Description | Example |
|---|---|---|
name | Search by the customer's name. | keywords[]=John |
company_name | Search by the company name. | keywords[]=ABC Corp |
email | Search by email address. | keywords[][email protected] |
address | Search by address. | keywords[]=123 Main St |
price | Search by price range or exact price. | keywords[]=100.00 |
schedule_id | Search for invoices tied to a specific schedule. | schedule_id=e70c126c-f7b7-4673-a129-5b650f00f84a |
payment_method | Search by the payment method used (card or bank). If an invoice is unpaid, payment_method will return null. |
The schedule ID above uses the UUID format shown in the list endpoint's response. Copy schedule_id from an invoice returned by GET /invoice; do not substitute the invoice's own id. Some invoices have no associated schedule.
Optional: Update the invoice
Use Update an Invoice with the same invoice ID you retrieved. Follow the update endpoint's request-body requirements rather than sending the entire retrieved object unchanged.
Response Structure
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Invoice details were successfully retrieved. |
| 400 | Bad Request | Invalid or missing parameters in the request. |
| 401 | Unauthorized | Authentication failed. |
| 404 | Not Found | An invoice with the specified ID does not exist. |
| 500 | Internal Server Error | Unexpected server error. |
Important Considerations
- Invoice Search: Use the list endpoint to find an invoice before requesting it by ID.
- Payment Method Visibility: If the invoice has not been paid, the
payment_methodfield will benull. - Data Handling: Handle retrieved invoice data according to your organization's access and retention policies to support your compliance efforts and record keeping. Consult your legal team regarding specific requirements.
