0

Has anyone successfully used firebase functions to connect to and send data to Xero API. I am trying to get my head around how to approach it. Any help would be appreciated.

thanks

Paul Newns
  • 61
  • 8

1 Answers1

1

A little late to the (vacant) party but I've successfully done this with a private Xero application - it's incredibly simple using their xero-node lib.

following the docs but removing privateKeyPath and replacing it with privateKeyString:

...
const XeroClient = require('xero-node').AccountingAPIClient;

// store this in ENV
const config = {
    "appType": "private",
    "consumerKey": "YOURCKEY",
    "consumerSecret": "YOURSK",
    'privateKeyString': 
"-----BEGIN RSA PRIVATE KEY-----\n\
YOURPEMPRIVATEKEY==\n\
-----END RSA PRIVATE KEY-----"
}
...
exports.createContact = functions.https.onRequest((req, res) => {
    // be sure to add cors lib
    return cors(req, res, () => {

        let xero = new XeroClient(config);
        xero.contacts.create({
            Name: 'phill'
        });
        xero.contacts.get().then(() => {
            res.status(200).send({
                message: "success"
            });
        });
    });
});
...

MofX
  • 1,569
  • 12
  • 22
ariaule
  • 51
  • 3