Skip to content
Nik Wakelin edited this page Sep 15, 2016 · 2 revisions

Contacts Methods

get_contact_by_id

GET /api.xro/2.0/contact

Gets a contact record for a specific Xero organisation

  result = gateway.get_contact_by_id(contact_id)
  contact = result.contact if result.success?

get_contact_by_number

GET /api.xro/2.0/contact

Gets a contact record for a specific Xero organisation

  gateway.get_contact_by_number(contact_number)

get_contacts

GET /api.xro/2.0/contacts

Gets all contact records for a particular Xero customer.

  gateway.get_contacts(:type => :all, :sort => :name, :direction => :desc)
  gateway.get_contacts(:type => :all, :modified_since => 1.month.ago) # modified since 1 month ago

contact.save

PUT /api.xro/2.0/contact or POST /api.xro/2.0/contact

Saves a contact record for a particular Xero customer.

contact = gateway.build_contact
contact.name = "The contact's name"
contact.email = "[email protected]"
contact.phone.number = "555 123 4567"
contact.address.line_1 = "LINE 1 OF THE ADDRESS"
contact.address.line_2 = "LINE 2 OF THE ADDRESS"
contact.address.city = "WELLINGTON"
contact.address.region = "WELLINGTON"
contact.address.country = "NEW ZEALAND"
contact.address.post_code = "6021"

contact.save       

POST /api.xro/2.0/contacts

Creates a list of contacts or updates them if they have a matching contact_id, contact_number or name.
This method uses only a single API request to create/update multiple contacts.

    contacts = [XeroGateway::Contact.new(:name => 'Joe Bloggs'), XeroGateway::Contact.new(:name => 'Jane Doe')]
    result = gateway.update_contacts(contacts)

Invoice Methods

GET /api.xro/2.0/invoice (get_invoice)

Gets an invoice record for a specific Xero organisation by either id or number

    gateway.get_invoice(invoice_id_or_number)

GET /api.xro/2.0/invoices (get_invoices)

Gets all invoice records for a particular Xero customer.

    gateway.get_invoices
    gateway.get_invoices(:modified_since => 1.month.ago) # modified since 1 month ago

PUT /api.xro/2.0/invoice

Inserts an invoice for a specific organization in Xero (Currently only adding new invoices is allowed).

Invoice and line item totals are calculated automatically.

    invoice = gateway.build_invoice({
      :invoice_type => "ACCREC",
      :due_date => 1.month.from_now,
      :invoice_number => "YOUR INVOICE NUMBER",
      :reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
      :line_amount_types => "Inclusive" # "Inclusive", "Exclusive" or "NoTax"
    })
    invoice.contact.name = "THE NAME OF THE CONTACT"
    invoice.contact.phone.number = "12345"
    invoice.contact.address.line_1 = "LINE 1 OF THE ADDRESS"

    line_item = XeroGateway::LineItem.new(
      :description => "THE DESCRIPTION OF THE LINE ITEM",
      :account_code => 200,
      :unit_amount => 1000
    )

    line_item.tracking << XeroGateway::TrackingCategory.new(:name => "tracking category", :options => "tracking option")

    invoice.line_items << line_item

        invoice.create

POST /api.xro/2.0/invoice

Updates an existing invoice record.

    invoice_retrieved_from_xero.due_date = Date.today
    invoice_retrieved_from_xero.save

PUT /api.xro/2.0/invoices

Inserts multiple invoices for a specific organization in Xero (currently only adding new invoices is allowed).
This method uses only a single API request to create/update multiple contacts.

    invoices = [XeroGateway::Invoice.new(...), XeroGateway::Invoice.new(...)]
    result = gateway.create_invoices(invoices)

Credit Note Methods

GET /api.xro/2.0/credit_note (get_credit_note_by_id)

Gets an credit_note record for a specific Xero organisation

    gateway.get_credit_note_by_id(credit_note_id)

GET /api.xro/2.0/credit_note (get_credit_note_by_number)

Gets a credit note record for a specific Xero organisation

    gateway.get_credit_note_by_number(credit_note_number)

GET /api.xro/2.0/credit_notes (get_credit_notes)

Gets all credit note records for a particular Xero customer.

    gateway.get_credit_notes
    gateway.get_credit_notes(:modified_since => 1.month.ago) # modified since 1 month ago

PUT /api.xro/2.0/credit_note

Inserts a credit note for a specific organization in Xero (Currently only adding new credit notes is allowed).

CreditNote and line item totals are calculated automatically.

    credit_note = gateway.build_credit_note({
      :credit_note_type => "ACCRECCREDIT",
      :credit_note_number => "YOUR CREDIT NOTE NUMBER",
      :reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
      :line_amount_types => "Inclusive" # "Inclusive", "Exclusive" or "NoTax"
    })
    credit_note.contact.name = "THE NAME OF THE CONTACT"
    credit_note.contact.phone.number = "12345"
    credit_note.contact.address.line_1 = "LINE 1 OF THE ADDRESS"    
    credit_note.add_line_item({
      :description => "THE DESCRIPTION OF THE LINE ITEM",
      :unit_amount => 1000,
      :tax_amount => 125,
      :tracking_category => "THE TRACKING CATEGORY FOR THE LINE ITEM",
      :tracking_option => "THE TRACKING OPTION FOR THE LINE ITEM"
    })

        credit_note.create

PUT /api.xro/2.0/credit_notes

Inserts multiple credit notes for a specific organization in Xero (currently only adding new credit notes is allowed).
This method uses only a single API request to create/update multiple contacts.

    credit_notes = [XeroGateway::CreditNote.new(...), XeroGateway::CreditNote.new(...)]
    result = gateway.create_credit_notes(credit_notes)

Accounts Methods

GET /api.xro/2.0/accounts

Gets all accounts for a specific organization in Xero.

    gateway.get_accounts

For more advanced (and cached) access to the accounts list, use the following.

    accounts_list = gateway.get_accounts_list

Finds account with code of '200'

    sales_account = accounts_list.find_by_code(200)

Finds all EXPENSE accounts. For a list of valid account types see XeroGateway::Account::TYPE

   all_expense_accounts = accounts_list.find_all_by_type('EXPENSE')

Finds all accounts with tax_type == 'OUTPUT'. For a list of valid tax types see XeroGateway::Account::TAX_TYPE

   all_output_tax_accounts = accounts_list.find_all_by_tax_type('OUTPUT')

Tracking Categories Methods

GET /api.xro/2.0/tracking

Gets all tracking categories and their options for a specific organization in Xero.

    gateway.get_tracking_categories

Organisation Methods

GET /api.xero/2.0/Organisation

Retrieves organisation details for the authorised application.

    gateway.get_organisation.organisation

Currencies Methods

GET /api.xero/2.0/Currencies

Retrieves currencies in use for the authorised application.

    gateway.get_currencies.currencies

Tax Rates Methods

GET /api.xero/2.0/TaxRates

Retrieves Tax Rates in use for the authorised application.

    gateway.get_tax_rates.tax_rates