How do I view all of my invoices using the API?
Is there an API call or set of calls I can use to view all of my account's invoices?
1 Reply
You can combine multiple API calls to list all of your invoices. This output can also be used in a more advanced script to generate PDFs or make the output look better. Here is the call I quickly put together:
for i in $(curl -H "Authorization: Bearer $your_token” https://api.linode.com/v4/account/invoices | jq '.data[] | .id'); do curl -sH "Authorization: Bearer $your_token" https://api.linode.com/v4/account/invoices/$i | python3 -m json.tool; done;
Let’s break that down:
First, gather the invoice IDs by hitting the invoices endpoint and then filter the output using jq.
for i in $(curl -H "Authorization: Bearer $your_token” https://api.linode.com/v4/account/invoices | jq '.data[] | .id’)
For each iteration in the for loop, print the invoice based on the ID we gathered. The ending python3 -m json.tool
is optional and makes the output easier to read in a terminal.
do curl -sH "Authorization: Bearer $your_token" https://api.linode.com/v4/account/invoices/$i | python3 -m json.tool;
This can be refined or changed using other endpoints to gather invoice items or payments. Here are some endpoints that will help you modify the above call.
https://developers.linode.com/api/v4/account-invoices-invoice-id-items
https://developers.linode.com/api/v4/account-payments.