Code Monkey home page Code Monkey logo

xero-extended's Introduction

Xero

A simple node library for Xero Private Applications

Install

npm install xero-extended

Use

You can use similar methods for xero.Invoices, xero.Payments, and xero.Users.

var Xero = require('xero');
var xero = new Xero(CONSUMER_KEY, CONSUMER_SECRET, RSA_PRIVATE_KEY);

// Find a bunch of Invoices
xero.Invoices.all(function (err, invoices) {
  if (err) {
    return res.json(err);
  }
  
  res.json(null, invoices);
});

// Find a single Invoice
xero.Invoices.find('<Some ID>', function (err, invoice) {
  if (err) {
    return res.json(err);
  }
  
  res.json(null, invoice);
});

// Create an Invoice
var invoiceData = {
  Type: xero.Invoices.SALE,
  Contact: {
    Name: 'Nathan Hoad'
  },
  Date: new Date(),
  DueDate: '2014-12-01',
  LineAmountTypes: xero.Invoices.EXCLUSIVE,
  LineItems: [
    { 
       Description: 'This is a thing', 
       Quantity: 7, 
       UnitAmount: 120, 
       DiscountRate: 10,
       AccountCode: 200
     }
  ]
};
xero.Invoices.create(invoiceData, function (err, invoice) {
  if (err) {
    res.json(err);
  }
  
  res.json(null, invoice);
})

Raw calls

Request

var Xero = require('xero');

var xero = new Xero(CONSUMER_KEY, CONSUMER_SECRET, RSA_PRIVATE_KEY);
xero.call('GET', '/Users', null, function(err, json) {
    if (err) {
        log.error(err);
        return res.json(400, {error: 'Unable to contact Xero'});
    }
    return res.json(200, json);
});

Response

{
   "Response":{
      "Id":"37286998-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "Status":"OK",
      "ProviderName":"My Account",
      "DateTimeUTC":"2013-04-22T17:13:31.2755569Z",
      "Users":[
         {
            "UserID":"613fbf01-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "FirstName":"Chadd",
            "LastName":"Sexington",
            "UpdatedDateUTC":"2013-04-12T05:54:50.477",
            "IsSubscriber":"true",
            "OrganisationRole":"STANDARD"
         }
      ]
   }
}

Download PDF

var Xero = require('xero');
var fs = require('fs');

var xero = new Xero(CONSUMER_KEY, CONSUMER_SECRET, RSA_PRIVATE_KEY);
var invoiceId = 'invoice-identifier';
var req = xero.call('GET', '/Invoices/' + invoiceId);

req.setHeader('Accept', 'application/pdf');
req.on('response', function(response) {
  var file = fs.createWriteStream(invoiceId + '.pdf');
  response.pipe(file);
});
req.end();

Docs

http://developer.xero.com/api/

Authors

xero-extended's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

paulussup

xero-extended's Issues

Invoices.create not working

Hi,

I am using xero-extended to create an invoice in xero.
I am authenticated and have installed xero-extended as well as xero but xero.Invoices.all/find/create are all undefined.
this is my code, are you able to help?

Thanks

var Xero = require('xero');
var fs = require('fs');
// require('xero-extended');

var customer_key = 'xxxxxxxxxxxxx';
var customer_secret = 'xxxxxxxxxxx';
var rsa_private_key = fs.readFileSync('/Users/xxxx/privatekey.pfx').toString();

var xero = new Xero(customer_key,customer_secret, rsa_private_key);

xero.call('GET', '/Users', null, function(err, json) {
        if (err) {
            console.error(err);
            return console.log('Unable to contact Xero');
        }
        return console.log(json);
    });

// Find a bunch of Invoices 
xero.Invoices.all(function (err, invoices) {
  if (err) {
    return res.json(err);
  }
  res.json(null, invoices);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.