Here's some code :
key = "xxxx"
secret = "xxxx"
from xero import Xero
from xero.auth import PrivateCredentials
with open('privatekey.pem') as keyfile:
rsa_key = keyfile.read()
credentials = PrivateCredentials(key, rsa_key)
xero = Xero(credentials)
def export_all():
#print xero.contacts.all()
invoices = xero.invoices.all()
for invoice in invoices:
if len(invoice['InvoiceNumber']) > 3:
print "EXPORTING" + invoice['InvoiceNumber'] + "-- " + invoice['InvoiceID']
export_one(invoice['InvoiceID'], invoice['InvoiceNumber'])
def export_one(invoiceID, invoiceNumber):
invoice = xero.invoices.get(invoiceID, headers={'Accept': 'application/pdf'})
with open('./export/' + invoiceNumber + '.pdf', 'wb') as f:
f.write(invoice)
export_all()
When you are leaving remember to export your contacts (you can do this manually clicking a button)