Getting started with the Xero API
Our app will be a “Private Application” (in Xero terms), which isn’t suitable for public use but does provide easy access to the whole API for personal and/or testing purposes. The instructions have been tested on Mac OS X and Linux and shouldn’t take more than 15 minutes to complete. The only prerequisite is installing Node.js. The LTS release is fine - the code will work with any version from 0.10 upwards.
The steps are:
- Create a new folder for your application and
cdinto it in a terminal window.
- Create a Private Application for your organisation (Demo Company or otherwise). Note: You can ignore step 3 of “Create a public/private key pair” (i.e.
openssl pkcs12 ...)
- Initialise your application:
npm init -y
- Install an NPM module to simplify making API calls:
npm install --save request
- Create a
main.jsfile with the following contents. Note that
consumer_keyshould be the value of your 30-character Consumer Key from step 3 above.
You should now be able to run your code using
node main.js and see a JSON representation of your organisation!
So, now you’ve got a super-simple app. But what’s next? Here some potential next steps in your journey as a Xero developer:
- Explore the other API endpoints by referring to the documentation in the Xero Developer Centre (and especially the really useful API previewer)
- Check out the prebuilt Code Samples and Libraries and well as the various third-party modules
- Get help and inspiration from the Developer Community (all 37,513 of them!)
- Make your Private application Public by mastering OAuth. See API Application Types for more information.
- Read more about Xero’s plans for the platform, including real-time updates via webhooks
- Find more advanced tutorials such as building a Xero app using React
At Chaser we’re always interested in hearing from other Xero developers. So do get in touch @chaser_io if you’d like to share what you’ve built or ask about our experiences. We’d love to hear from you!
Update: Join a discussion about this post in the Xero Developer Community