You fetch one invoice from a REST API by sending a GET request to that invoice's own URL, usually something like /invoices/{id}, and sending your API key in an authorization header. The request carries no body. Everything the server needs is in the URL and the headers, which is why GET is called a safe, read-only method.

The part most people get wrong is expecting a list back. A call to /invoices returns a collection. A call to /invoices/1042 returns one record. Mixing the two is the most common reason a request returns unexpected data or an error.

Reading the Request Structure

A single invoice request has four parts, and each one does a job. If any part is wrong, you get an error rather than a partial result.

  • Method: GET. It tells the server not to change anything.
  • URL: the base address, the resource name, and the invoice identifier.
  • Headers: your credentials, plus the format you want back.
  • Query string: optional filters such as which fields to include.

A typical request looks like this in plain text form:

GET /v1/invoices/1042?expand=customer
Host: api.example.com
Authorization: Bearer YOUR_API_KEY
Accept: application/json

The Authorization header is where keys and tokens go. Never put a key in the URL. Keys in URLs end up in server logs, browser history and shared links, and anyone who sees the log can use it until it is rotated.

Choosing GET or POST for Invoices

GET is right for anything that only reads. Use it for fetching one invoice, listing invoices, or fetching a PDF attachment reference. Use POST when you create something, PUT or PATCH when you change something, and DELETE when you remove it.

Some APIs bend this rule for complex searches, because GET requests have practical URL length limits and cannot carry a body. If a search needs a long list of filters, the documentation may ask you to use POST for a search endpoint. Follow the documentation rather than the general rule.

A useful habit: if repeating the same request twice would leave the server unchanged, GET is almost certainly the right method.

A Worked Request, Step by Step

Here is the whole path from a blank screen to usable invoice data, using generic menu paths and standard tools. Labels differ between tools and API versions, so check your own client.

  1. Find the invoice identifier. It is usually the number in your invoice view or the value called id in a previous list response. Do not confuse it with the human invoice number printed on the document.
  2. Build the URL by joining the base address, the resource path, and the identifier: base plus /v1/invoices/ plus the id. Use HTTPS, not HTTP.
  3. Add the Accept: application/json header so the response comes back as JSON rather than HTML or XML.
  4. Add your authorization header. Use the scheme the documentation names, such as a bearer token or a basic credential pair.
  5. Send the request and read the status code before reading the body.
  6. Check that the returned invoice id matches the one you asked for. This one step catches most copy-paste errors.

In a command-line client, that is a single command with the URL first and the headers as flags. In a visual client, the same three fields appear as tabs. Neither approach is more correct.

Status Codes and What They Tell You

The status code is the fastest diagnosis you have. Read it before you look at the JSON.

  • 200: success, and the body holds the invoice.
  • 400: the request is malformed, often a badly formatted identifier or a filter the API does not recognise.
  • 401: the key is missing, expired or wrong. Recheck the header name and the scheme word before the token.
  • 403: the key is valid but not allowed to read that invoice. This is common when a key is scoped to one business or account.
  • 404: no invoice with that identifier exists at that path, or the path is wrong.
  • 429: you have made too many requests. Wait for the period named in the response headers, then retry.
  • 500: the fault is on the server side. Retry once after a short wait; if it repeats, keep the request details for support.

Rule of thumb: retry automatically only 429 and 500 responses. Retrying 400, 401, 403 or 404 just burns your request allowance.

Shape of an Invoice Response

An invoice body usually carries a header block, line items, totals and a status. Field names vary between providers, but the structure tends to repeat.

  • Identifiers: the internal id and the customer-facing invoice number.
  • Dates: issue date and due date, usually in a date-only format.
  • Parties: the customer reference, sometimes expanded into a nested object.
  • Line items: an array, each with a description, quantity, unit amount and line total.
  • Totals: subtotal, tax and the amount due, with a currency code.
  • Status: values such as open, paid, void or draft.

Smaller total fields matter more than they look. Read the amount due field, not the subtotal, when you are checking what a customer owes. Currency codes are three letters such as USD or GBP, and they are not decorative.

Why amounts are often in minor units

Some APIs return amounts as integers in the smallest currency unit, so 2499 means 24.99. Check the documentation for a note on this before you divide anything. If you assume it is a decimal and it is not, or the reverse, every reported figure will be wrong by a factor of 100.

Filters, Fields and Single Fetches

Two query parameters are worth knowing by name, though the exact wording is up to the provider.

A fields parameter trims the response: request only the invoice number, status and amount due when you are building a simple list. A smaller response is faster to transfer and easier to read.

An expand parameter pulls in linked objects, such as the customer record, in one round trip. Without it you make two requests. With too much of it you get a large nested response that changes shape when the linked record is missing.

If you only need one invoice, never fetch the whole list and filter on your side. Fetching 100 invoices to use one wastes time and can push you into rate limits. If you must list, ask for the smallest reasonable page size and follow the pagination links the response gives you.

Testing Safely Before You Build

Send your first requests with a key that can only read, on an account with test data. A read-only key limits the damage from a wrong path, and a test invoice lets you predict the exact response you should see.

Save one successful response as a sample. Compare later changes against it, because a field quietly disappearing is easier to spot beside a known-good copy. Log status codes and request paths, but never log the authorization header.

If a request works in a visual client but fails in your code, compare the raw headers. The usual culprits are a missing Accept header, a stray space in the token, or a URL that has doubled up on a slash.