Code Monkey home page Code Monkey logo

apex-for-xero's Introduction

Apex-for-Xero

This application contains Apex utilities for accessing the Xero REST APIs.

These classes are set up to use the Private Application type.

The aim of this project is to act as a starting point for accessing Xero APIs via Apex. I wanted to share this project as I spent a lot of time getting the authentication working for Xero, as Apex doesn't have a standard OAuth 1.0 library and there wasn't much detail online about it.

For more information about the Xero APIs, check out: http://developer.xero.com/documentation/api/api-overview/

Quick Setup

  1. Create your private and public keys
    • Setup -> Security Controls -> Certification and Key Management
    • Create a Self-Signed Certification. Give it the name of XeroCertificate
    • Click Download Certificate. This is the certificate you upload into Xero.
  2. Create your application in Xero and upload your public key .cer file generated above
  3. Deploy this package to a Salesforce environment (Deploy to Org)
  4. Access the Xero Settings Custom Setting (Setup -> Develop -> Custom Settings -> Click Manage on Xero Settings) and enter your Xero credentials (from your application created in Xero)
  5. You can now access Xero API resources via Apex. Eg... XeroAccountingApi.getContacts();

Usage

Once the above steps are complete, you can now access the example methods to access the Xero API resources. There are currently only a few pre-built methods set up to start using. Please use these as a base and extend as necessary.

Get Contacts

This method queries all contacts in your Xero org. To execute, simply run:

XeroAccountingApi.getContacts();

And a list of type XeroContact is returned.

Create Contact

This method creates a contact for the given XML:

// Create a Contact
XeroContact newContact = new XeroContact();
newContact.Name = 'ABC Limited 1';

// Send Contact to Xero
XeroAccountingApi.createContact(XeroXmlUtility.serialize(newContact, 'Contact'));

You can view example XML requests here

Get Invoices

This method queries all invoices in your Xero org. To execute, run:

XeroAccountingApi.getInvoices();

Create Invoice

This method creates an invoice for the given XML:

XeroInvoice newInvoice = new XeroInvoice();
newInvoice.Date_x = system.today();
... // Add additional Invoice details based on the XeroInvoice wrapper

// Send Invoice to Xero
XeroAccountingApi.createInvoice(XeroXmlUtility.serialize(newInvoice, 'Invoice'));

You can view example XML requests here

Contributing

Feel free to fork this repo and use as you wish. I'd welcome anyone to add additional methods and add to this project, I will do the same as I go.

apex-for-xero's People

Contributors

benedwards44 avatar

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.