twl2009
twl2009

Reputation: 89

Xero-node get invoice as PDF

I am trying to create an invoice in xero and then get a pdf version uploaded onto mongoDB through my parse server. I am authenicating xero in an express app in the main.js of my application.
When I save the invoice Pdf to parse it is rejected as 'schema mismatch, expecting file but getting object', what am I missing in my code to create the PDF version?

let oauth_verifier = req.query.oauth_verifier;
let accessToken = await xeroClient.oauth1Client.swapRequestTokenforAccessToken(lastRequestToken, oauth_verifier)
    .then(async() => {
        var invoice = xeroClient.invoices.create(data)
            .then(async(invoice) => {
                var inv = invoice["Invoices"][0];
                var invId = inv["InvoiceID"];
                await xeroClient.invoices.get({ InvoiceID: invId}, "application/pdf")
                    .then((invPdf) => {

                        Parse.initialize("--------------------");    
                        Parse.serverURL = 'http://--.---.---.--:--/parse';
                        var Invoices = Parse.Object.extend("Invoices");
                        var invoice = new Invoices;
                        invoice.set('invoicePdf', invPdf);
                        invoice.save(); 

                        event.returnValue = true;
                        win.close();
                    })
            })

Upvotes: 1

Views: 896

Answers (1)

droopsnoot
droopsnoot

Reputation: 983

In the GitHub source for the Node.JS, there is a separate function called savePDF which seems to do the trick, as you noted in the comments above. https://github.com/XeroAPI/xero-node/blob/36ab8a513263426a173633691f5308237f473b99/src/AccountingAPIClient.ts#L469

Upvotes: 1

Related Questions