PHPackages                             pedalme/xero-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pedalme/xero-php

ActiveLibrary

pedalme/xero-php
================

A client implementation of the Xero API, with a cleaner OAuth interface and ORM-like abstraction.

v1.9.0(6y ago)020MITPHPPHP &gt;=5.6.0

Since Jan 27Pushed 6y agoCompare

[ Source](https://github.com/pedalme/xero-php)[ Packagist](https://packagist.org/packages/pedalme/xero-php)[ Docs](https://github.com/calcinai/xero-php)[ RSS](/packages/pedalme-xero-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (56)Used By (0)

XeroPHP
-------

[](#xerophp)

[![Build Status](https://camo.githubusercontent.com/1ffa726382f5b34219e4e753bd725ee37a1b4ae0c190dca7d18446066afd76fc/68747470733a2f2f7472617669732d63692e6f72672f63616c63696e61692f7865726f2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/calcinai/xero-php)[![Latest Stable Version](https://camo.githubusercontent.com/ed939fe9f09a4f9fa591f033f2982a21bb732755806c9b72050947c2e0bcf60e/68747470733a2f2f706f7365722e707567782e6f72672f63616c63696e61692f7865726f2d7068702f762f737461626c65)](https://packagist.org/packages/calcinai/xero-php)[![Total Downloads](https://camo.githubusercontent.com/67f29fd22d0f9eccb6586e67feff18c471dcdde32b6755f124e6e38a5468112b/68747470733a2f2f706f7365722e707567782e6f72672f63616c63696e61692f7865726f2d7068702f646f776e6c6f616473)](https://packagist.org/packages/calcinai/xero-php)

A client library for the [Xero API](http://developer.xero.com), including an OAuth interface and ORM-like abstraction.

This is loosely based on the functional flow of XeroAPI/XeroOAuth-PHP, but is split logically into more of an OO design.

This library has been tested with Private, Public and Partner applications.

Requirements
------------

[](#requirements)

- PHP 5.5+
- php\_curl extension - ensure a recent version (7.30+)
- php\_openssl extension

Setup
-----

[](#setup)

Using composer:

```
composer require calcinai/xero-php
```

Otherwise just download the package and add it to your autoloader. Namespaces are PSR-4 compliant.

Usage
-----

[](#usage)

All the examples below refer to models in the `XeroPHP\Models\Accounting` namespace. Additionally, there are models for `PayrollAU`, `PayrollUS`, `Files`, and `Assets`

Create a XeroPHP instance (sample config included):

```
$xero = new \XeroPHP\Application\PrivateApplication($config);
```

Load a collection of objects and loop through them

```
$contacts = $xero->load(Contact::class)->execute();

foreach ($contacts as $contact) {
    print_r($contact);
}
```

Load collection of objects, for a single page, and loop through them [(Why?)](https://developer.xero.com/documentation/auth-and-limits/xero-api-limits#Systemlimits)

```
$contacts = $xero->load(Contact::class)->page(1)->execute();

foreach ($contacts as $contact) {
    print_r($contact);
}
```

Search for objects meeting certain criteria

```
$xero->load(Invoice::class)
    ->where('Status', Invoice::INVOICE_STATUS_AUTHORISED)
    ->where('Type', Invoice::INVOICE_TYPE_ACCREC)
    ->execute();
```

Load something by its GUID

```
$contact = $xero->loadByGUID(Contact::class, $guid);
```

Or create &amp; populate it

```
$contact = new Contact($xero);

$contact->setName('Test Contact')
    ->setFirstName('Test')
    ->setLastName('Contact')
    ->setEmailAddress('test@example.com');
```

Save it

```
$contact->save();
```

If you have created a number of objects of the same type, you can save them all in a batch by passing an array to `$xero->saveAll()`.

From v1.2.0+, Xero context can be injected directly when creating the objects themselves, which then exposes the `->save()` method. This is necessary for the objects to maintain state with their relations.

Saving related models

If you are saving several models at once, by default additional model attributes are not updated. This means if you are saving an invoice with a new contact, the contacts `ContactID` is not updated. If you want the related models attributes to be updated you can pass a boolean flag with `true` to the save method.

```
$xero->save($invoice, true);
```

Nested objects

```
$invoice = $xero->loadByGUID(Invoice::class, '[GUID]');
$invoice->setContact($contact);
```

Attachments

```
$attachments = $invoice->getAttachments();
foreach ($attachment as $attachment) {
    //Do something with them
    file_put_contents($attachment->getFileName(), $attachment->getContent());
}

//You can also upload attachemnts
$attachment = Attachment::createFromLocalFile('/path/to/image.jpg');
$invoice->addAttachment($attachment);
```

To set the `IncludeOnline` flag on the attachment, pass `true` as the second parameter for `->addAttachment()`.

PDF - Models that support PDF export will inherit a `->getPDF()` method, which returns the raw content of the PDF. Currently this is limited to Invoices and CreditNotes.

Refer to the [examples](examples) for more complex usage and nested/related objects. There's also [a sample PHP app](https://github.com/XeroAPI/xero-php-sample-app) using this library.

Webhooks
--------

[](#webhooks)

If you are receiving webhooks from Xero there is `Webhook` class that can help with handling the request and parsing the associated event list.

```
$webhook = new Webhook($application, $request->getContent());

/**
 * @return int
 */
$webhook->getFirstEventSequence();

/**
 * @return int
 */
$webhook->getLastEventSequence();

/**
 * @return \XeroPHP\Webhook\Event[]
 */
$webhook->getEvents();
```

See: [Webhooks documentation](https://developer.xero.com/documentation/webhooks/overview)

### Validating Webhooks

[](#validating-webhooks)

To ensure the webhooks are coming from Xero you should validate the incoming request header that Xero provides.

```
if (! $webhook->validate($request->headers->get('x-xero-signature'))) {
    throw new Exception('This request did not come from Xero');
}
```

See: [Signature documentation](https://developer.xero.com/documentation/webhooks/configuring-your-server#intent)

Handling Errors
---------------

[](#handling-errors)

Your request to Xero may cause an error which you will want to handle. You might run into errors such as:

- `HTTP 400 Bad Request` by sending invalid data, like a malformed email address.
- `HTTP 503 Rate Limit Exceeded` by hitting the API to quickly in a short period of time.
- `HTTP 400 Bad Request` by requesting a resource that does not exist.

These are just a couple of examples and you should read the official documentation to find out more about the possible errors.

### Thrown exceptions

[](#thrown-exceptions)

This library will parse the response Xero returns and throw an exception when it hits one of these errors. Below is a table showing the response code and corresponding exception that is thrown:

HTTP CodeException400 Bad Request`\XeroPHP\Remote\Exception\BadRequestException`401 Unauthorized`\XeroPHP\Remote\Exception\UnauthorizedException`403 Forbidden`\XeroPHP\Remote\Exception\ForbiddenException`403 ReportPermissionMissingException`\XeroPHP\Remote\Exception\ReportPermissionMissingException`404 Not Found`\XeroPHP\Remote\Exception\NotFoundException`500 Internal Error`\XeroPHP\Remote\Exception\InternalErrorException`501 Not Implemented`\XeroPHP\Remote\Exception\NotImplementedException`503 Rate Limit Exceeded`\XeroPHP\Remote\Exception\RateLimitExceededException`503 Not Available`\XeroPHP\Remote\Exception\NotAvailableException`503 Organisation offline`\XeroPHP\Remote\Exception\OrganisationOfflineException`See: [Response codes and errors documentation](https://developer.xero.com/documentation/api/http-response-codes)

### Handling exceptions

[](#handling-exceptions)

To catch and handle these exceptions you can wrap the request in a try / catch block and deal with each exception as needed.

```
try {
    $xero->save($invoice);
} catch (NotFoundException $exception) {
    // handle not found error
} catch (RateLimitExceededException $exception) {
    // handle rate limit error
}
```

See: [Working with exceptions](https://secure.php.net/manual/en/language.exceptions.php)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 64.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~108 days

Total

48

Last Release

2390d ago

Major Versions

v1.4.1 → 2.0.x-dev2016-12-01

PHP version history (3 changes)v1.2.3PHP &gt;=5.4.0

v1.3.2PHP &gt;=5.5.0

v1.9.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c0a407c9366a994d2a1d1b1d7947e26f89fa2ace4f82039bc33a958b4ce9919?d=identicon)[robertfranksargent](/maintainers/robertfranksargent)

---

Top Contributors

[![calcinai](https://avatars.githubusercontent.com/u/2415868?v=4)](https://github.com/calcinai "calcinai (417 commits)")[![timacdonald](https://avatars.githubusercontent.com/u/24803032?v=4)](https://github.com/timacdonald "timacdonald (93 commits)")[![coop182](https://avatars.githubusercontent.com/u/1443208?v=4)](https://github.com/coop182 "coop182 (16 commits)")[![M1ke](https://avatars.githubusercontent.com/u/1226123?v=4)](https://github.com/M1ke "M1ke (14 commits)")[![Josh-G](https://avatars.githubusercontent.com/u/487384?v=4)](https://github.com/Josh-G "Josh-G (14 commits)")[![Healyhatman](https://avatars.githubusercontent.com/u/13272508?v=4)](https://github.com/Healyhatman "Healyhatman (11 commits)")[![Synchro](https://avatars.githubusercontent.com/u/81561?v=4)](https://github.com/Synchro "Synchro (10 commits)")[![mhlavac](https://avatars.githubusercontent.com/u/743421?v=4)](https://github.com/mhlavac "mhlavac (7 commits)")[![lunchboffin](https://avatars.githubusercontent.com/u/3990871?v=4)](https://github.com/lunchboffin "lunchboffin (5 commits)")[![sketchthat](https://avatars.githubusercontent.com/u/5913727?v=4)](https://github.com/sketchthat "sketchthat (5 commits)")[![wobinb](https://avatars.githubusercontent.com/u/15114287?v=4)](https://github.com/wobinb "wobinb (4 commits)")[![davidwindell](https://avatars.githubusercontent.com/u/1720090?v=4)](https://github.com/davidwindell "davidwindell (4 commits)")[![direvus](https://avatars.githubusercontent.com/u/312229?v=4)](https://github.com/direvus "direvus (4 commits)")[![iveoles](https://avatars.githubusercontent.com/u/1750634?v=4)](https://github.com/iveoles "iveoles (4 commits)")[![jeremyj11](https://avatars.githubusercontent.com/u/15713461?v=4)](https://github.com/jeremyj11 "jeremyj11 (4 commits)")[![SidneyAllen](https://avatars.githubusercontent.com/u/595967?v=4)](https://github.com/SidneyAllen "SidneyAllen (4 commits)")[![theshelf](https://avatars.githubusercontent.com/u/5120570?v=4)](https://github.com/theshelf "theshelf (4 commits)")[![robertsargent](https://avatars.githubusercontent.com/u/44968981?v=4)](https://github.com/robertsargent "robertsargent (3 commits)")[![wbercx](https://avatars.githubusercontent.com/u/2244710?v=4)](https://github.com/wbercx "wbercx (3 commits)")[![jszobody](https://avatars.githubusercontent.com/u/203749?v=4)](https://github.com/jszobody "jszobody (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pedalme-xero-php/health.svg)

```
[![Health](https://phpackages.com/badges/pedalme-xero-php/health.svg)](https://phpackages.com/packages/pedalme-xero-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
