Skip to main content

Overview

Royal Mail keeps invoice data and tracking data apart. Its invoice report has no tracking numbers, and tracking numbers only come from tracking reports that Royal Mail generates on request. Trackstar requests those reports, joins them to the invoice rows, and serves the result as a combined line-item file. Most rows of that file are one tracked item (one barcode) with its share of an invoice line’s charges. Invoice lines with no tracked items, such as surcharges, fees and credits, are one row each with no barcode, so the line items for an invoice add up to the invoice total. Because the line-item file is built by Trackstar, its columns use Trackstar’s naming (lowercase with underscores) rather than Royal Mail’s report column names. It has 16 columns with a single header row. Most of this page documents that file. The other files a Royal Mail connection serves are listed in the next section.

Files you’ll receive

The Files endpoint returns three kinds of file for a Royal Mail connection.
  • Invoice line items. There is one file per Royal Mail tracking report, and each report covers up to 500 sales orders, so a busy invoice period produces several files. Royal Mail takes hours to generate a report, so the line-item files for an invoice arrive over several syncs, after its invoice rows file. The report name in the file name starts with ts. Invoice lines with no tracked items go in a file ending _untracked.csv, which arrives in the same sync as its invoice rows file. Credit notes, ad-hoc invoices and manual adjustments go in a file ending _dockets.csv, usually in the first sync after Royal Mail issues them.
  • Invoice rows. Each time Trackstar finds invoice lines it has not processed before, it writes them to this file and requests tracking reports for the tracked ones. Every file has the same name; tell them apart by id or created_date. This file does not produce line items on its own: its rows reach the API through the line-item files.
  • Invoice PDFs. Served only when the connection was set up with login details for Royal Mail’s online invoicing portal. They sit in a pdf/ folder, which shows in the file id but not in file_name.
file_type=csv returns both CSV kinds. To list only the line-item files, filter with file_name[contains]=invoice_line_items.
The same line items can appear in two line-item files. This happens when a tracking report has to be downloaded again after a failed sync. The invoice line items endpoint holds each line item once, so de-duplicate if you read the raw files directly.

Shape notes

These apply to the invoice line-item file.
  • One row per tracked item, per invoice line. A Royal Mail sales order can cover many items. Each invoice line’s charges are divided evenly across all the tracked items matched to its sales order, outbound and returned alike, so gross_cost and net_cost are per-item shares and can carry long decimals. If Royal Mail bills one sales order on two invoice lines, each barcode appears once per line, each time with that line’s share.
  • Charge rows have no tracking number. Invoice lines for untracked products (anything other than TPS, TPN, TSS, TSN, TRS and TRN, such as oversize surcharges, collection fees and compensation), credits and other lines with a gross value of zero or less, and sales orders that have no items in Royal Mail’s tracking report each come through as one row. That row has a blank tracking_number, source_type set to invoice, and the invoice line’s full gross_cost and net_cost.
  • Credit notes, ad-hoc invoices and manual adjustments are one row per docket. Royal Mail leaves these out of its invoice report, so Trackstar reads them from Royal Mail’s Invoice Ad-hoc report into the _dockets.csv file. That covers compensation credit notes, one-off invoices such as collection fees and duplicate-charge corrections, and the manual adjustment lines (docket numbers starting with J) on a weekly invoice. These rows have a blank tracking_number, class_of_mail and volume, because Royal Mail’s report doesn’t include them, and source_type set to invoice. Credits are negative. sales_order_no is Royal Mail’s reference for the docket, not the docket number printed on the PDF.
  • source_type marks direction. outbound for items sent to a recipient; rts for items returned to sender; invoice for charge rows with no tracked item. Returned items also populate reason_for_non_delivery and date_return_to_sender.
  • Two date formats. invoice_date uses Royal Mail’s DD.MM.YYYY format; date_item_delivered and date_return_to_sender use YYYY-MM-DD.
  • Tracking numbers are S10 barcodes. Two letters, nine digits, and a GB suffix (e.g., AB123456789GB).

Mapping to invoice line items

How each row becomes a record in the invoice line items endpoint.

Sample rows

Curated subset of columns for readability. The downloadable CSV has all 16 columns.

Download

Download full sample CSV (1 header row + 28 data rows, 16 columns)
All sample data is synthetic. Account numbers, invoice numbers, tracking numbers, and names are fabricated and do not correspond to any real shipments or customers.

Fields

Each row is one tracked item on one invoice line, or one invoice line with no tracked items. All 16 columns appear in every row, in this order.

Account and invoice

Product and item

Costs and delivery

Invoice rows file

sales_orders_invoices_adhoc.csv holds the rows of Royal Mail’s invoice report that Trackstar processed in one batch. It has one header row and 37 columns, named by Trackstar in Royal Mail’s report order. Values appear as they do in Royal Mail’s report. Every row with an invoice number is included, and each invoice line (invoice number and sales order) appears in one of these files. Lines Royal Mail adds to an invoice after it was first processed arrive in a later file.
The line-item file carries these columns forward: account_number, account_name, invoice_number, invoice_date, sales_order_no, product_code, product_name, class_of_mail and volume as they are, and gross_value and net_value as gross_cost and net_cost, split across the order’s tracked items or whole on a charge row.