0

I'm just sharing a piece of code I hope will be helpful if you want to get rid of Xero and export all your PDF because by default they are preventing you to do that (probably in the hope you will stay longer).

I hope this will help anyone trying to move away from Xero the app is such a disaster !

Tibo
  • 621
  • 1
  • 8
  • 24

1 Answers1

0

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)

Tibo
  • 621
  • 1
  • 8
  • 24