PDF Invoices can be accessed via the TrackTik API once you know the Invoice ID and the PDF URL available in the Invoice data. Accessing Invoice data and its PDF requires that the header of your HTTP request to download the PDF also contains the same Bearer JWT token that you use for your other API calls.
Locate the invoice
First, find the invoice using whatever date ranges or other data you already know. You can for example look for the latest invoices that have a PDF invoice generated with:
[GET] /invoices?sort=-id&include=pdfUrl&pdfUrl:not
{
"client": 52,
"status": "APPROVED",
"documentNumber": "1075",
"poNumber": "",
"externalInvoiceId": "",
"invoiceDate": "2019-06-01T00:00:00+00:00",
"date": "2019-06-01T00:00:00+00:00",
"dueDate": "2019-06-11T00:00:00+00:00",
"servicePeriodStartDate": "2019-06-01T00:00:00+00:00",
"servicePeriodStart": "2019-06-01T00:00:00+00:00",
"servicePeriodEndDate": "2019-06-30T00:00:00+00:00",
"servicePeriodEnd": "2019-06-30T00:00:00+00:00",
"taxClass": 2,
"contract": 24,
"subTotal": 1440,
"taxTotal": 215.64,
"total": 1655.64,
"distributed": false,
"aging": "120+",
"approvedBy": 1209,
"invoiceBatchId": 4,
"id": 976,
==> "pdfUrl": "https://<your TT portal domain>/backoffice/billing/invoice/view/id/976"
}HTTP Request the PDF
That pdfUrl is accessible to anyone making an HTTP Request where the Bearer JWT Token is in the HTTP header. So an API solution that is already able to call endpoints like /invoices can also download that PDF at the URL shown through another HTTP request.
E.g. Using the pdfUrl from above
[GET] https://<your TT portal domain>/backoffice/billing/invoice/view/id/976
Where the HTTP header contains a valid non-expired token (ideally this would be your current token used for other API calls in the past hour or so):
Results in a downloaded PDF:
Capturing the PDF as a stream (for saving into a file)
HTTP requests pointed to the URI of the PDF document will return a stream of data. This stream can be converted as Base64 so that it can be saved into a text based field in your database perhaps, or for the creation of the PDF file at the destination.
Here’s an example from one of our customers' past integrations that achieved this using Rest Sharp in C# (file save step not shown):
RestClient clients = new RestClient(path);
clients.ClearHandlers();
clients.AddHandler("*", () => { return new JsonDeserializer(); });
RestRequest request = new RestRequest(Method.GET);
request.AddParameter("Authorization", string.Format("Bearer " + accessToken),
ParameterType.HttpHeader);
IRestResponse response = await clients.ExecuteAsync(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// Read bytes
byte[] fileBytes = response.RawBytes;
string s = Convert.ToBase64String(fileBytes);
}