PHPackages                             mradcliffe/xeroclient - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mradcliffe/xeroclient

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mradcliffe/xeroclient
=====================

Provides a Guzzle client for use with the Xero Accounting and Payroll APIs.

0.6.1(3mo ago)215.0k↑575%2[2 issues](https://github.com/mradcliffe/xeroclient/issues)MITPHPPHP ^8.3CI passing

Since Nov 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mradcliffe/xeroclient)[ Packagist](https://packagist.org/packages/mradcliffe/xeroclient)[ RSS](/packages/mradcliffe-xeroclient/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (12)Versions (23)Used By (0)

Xero Client
===========

[](#xero-client)

xeroclient is a PHP library that extends Guzzle to provide integration with the [Xero API](https://developer.xero.com). It is primarily used as an API layer for your own project. It supports connecting to the Accounting API, Payroll API and File API URLs as either a private, public or partner application although implementation and storage of OAuth2 configuration is up to the implementing software. xeroclient aims to abide by the following criteria in regard to Xero integration:

1. Abides by the PSR-2 standard.
2. Uses contemporary PHP libraries such as Guzzle.
3. Is lightweight and pluggable into a variety of frameworks that do normalization and data modeling their own way.
4. Is testable.

Ultimately it is up to the software that uses xeroclient to deal with [serialization](http://symfony.com/doc/current/components/serializer.html), data modeling, OAuth2 redirect work flow, and configuration or content management.

[![Build Status](https://github.com/mradcliffe/xeroclient/workflows/code-quality/badge.svg)](https://github.com/mradcliffe/xeroclient/workflows/code-quality/badge.svg)

**Please see [CONTRIBUTING](./CONTRIBUTING.md) for more information about contributing to this project including Code of Conduct, Accountability, and How to get started.**

Dependencies
------------

[](#dependencies)

- PHP 8.3 or greater
- [league/oauth2-client](https://packagist.org/packages/league/oauth2-client)
- [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle)

Usage
-----

[](#usage)

### Request an access token from Xero API using OAuth2.

[](#request-an-access-token-from-xero-api-using-oauth2)

```
// Create a new provider.
$provider = new \Radcliffe\Xero\XeroProvider([
    'clientId' => 'my consumer key',
    'clientSecret' => 'my consumer secret',
    'redirectUri' => 'https://example.com/path/to/my/xero/callback',
    // This will always request offline_access.
    'scopes' => \Radcliffe\Xero\XeroProvider::getValidScopes('accounting'),
]);

// Gets the URL to go to get an authorization code from Xero.
$url = $provider->getAuthorizationUrl();
```

### Create with a guzzle client from an authorization code (see above)

[](#create-with-a-guzzle-client-from-an-authorization-code-see-above)

```
$client = \Radcliffe\Xero\XeroClient::createFromToken('my consumer key', 'my consumer secret', $code, 'authorization_code', 'accounting');
// Store the access token for the next 30 minutes or so if making additional requests.
$tokens = $client->getRefreshedToken();
```

### Create with a guzzle client with an access token

[](#create-with-a-guzzle-client-with-an-access-token)

```
$client = \Radcliffe\Xero\XeroClient::createFromToken(
	'my consumer key',
	'my consumer secret',
	'my access token',
	null,
	'accounting',
	[],
	[],
	'https://example.com/path/to/my/xero/callback'
);
```

### Create with a guzzle client with a refresh token

[](#create-with-a-guzzle-client-with-a-refresh-token)

Access tokens expire after 30 minutes so you can create a new client with a stored refresh token too.

```
$client = \Radcliffe\Xero\XeroClient::createFromToken(
	'my consumer key',
	'my consumer secret',
	'my request token',
	'refresh_token',
	'accounting',
	[],
	[],
	'https://example.com/path/to/my/xero/callback'
);
// Get the refreshed tokens and store it somewhere.
$tokens = $client->getRefreshedToken();
```

### Use the client instance to make requests

[](#use-the-client-instance-to-make-requests)

```
try {
	$options = [
		'query' => ['where' => 'Name.StartsWith("John")'],
		'headers' => ['Accept' => 'application/json'],
	];
	$response = $client->request('GET', 'Accounts', $options);

	// Or use something like Symfony Serializer component.
	$accounts = json_decode($response->getBody()->getContents());
} catch (\GuzzleHttp\Exception\ClientException $e) {
	echo 'Request failed because of ' . $e->getResponse()->getStatusCode();
}
```

### Error handling

[](#error-handling)

If the configured client does not have a valid Xero API URL or if an auth\_token is not provided, then XeroRequestException is thrown as part of the Guzzle request.

Previously XeroClient would throw an exception on instantiation, but this is no longer the case. If the initialize method is used directly, XeroClient will probably fail for other reasons.

### Use with a legacy OAuth1 application

[](#use-with-a-legacy-oauth1-application)

Please see the 0.2 branch and versions &lt; 0.3.0.

### Xero Helper Trait

[](#xero-helper-trait)

The XeroHelperTrait provides some useful methods to attach to your classes for dealing with various Xero API query parameters and headers.

License
-------

[](#license)

- This software is primarily licensed under the MIT license.
- Exception is granted to use the software under the GPLv2 license.

Alternate libraries
-------------------

[](#alternate-libraries)

- [xero-php-oauth2](https://github.com/XeroAPI/xero-php-oauth2) provides an auto-generated SDK for accessing the Xero API that injects Guzzle into each model.
- [xero-php](https://github.com/calcinai/xero-php) provides an all-in-one solution based on data model assumptions using Curl for PHP 5.3 applications.
- [PHP-Xero](https://github.com/drpitman/PHP-Xero) provides OAuth1 and Xero classes in the global namespace. Horribly outdated and should not be used. I have a [fork](https://github.com/mradcliffe/PHP-Xero).
- [XeroBundle](https://github.com/james75/XeroBundle) provides a Symfony2 Bundle that is the inspiration for this lightweight library. It is possible to wrap your own factory class to ignore the Symfony2 bundle configuration. Currently broken (my fault) unless you use [my fork](https://github.com/mradcliffe/XeroBundle).
- [XeroOAuth-PHP](https://github.com/XeroAPI/XeroOAuth-PHP) provides OAuth1 and Xero classes in the global namespace and maintained by the Xero API team for older PHP 5.3 applications.
- [Xero API](https://drupal.org/project/xero) provides a Drupal module that integrates with the Xero API. In Drupal 8 this depends on this library or XeroBundle above.
- There are numerous other libraries providing custom code.

Affiliation
-----------

[](#affiliation)

This library is not affiliated with Xero Limited.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance63

Regular maintenance activity

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 94.9% 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 ~172 days

Recently: every ~165 days

Total

21

Last Release

85d ago

PHP version history (5 changes)0.2.0PHP ^7.0

0.3.6PHP ^7 || ^8

0.4.0PHP ^8

0.5.0PHP ^8.1

0.6.1PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a9b59b512e724e913b2dfe1a10f7e70dbf7f60dc00330c7be2478159ced9061?d=identicon)[mradcliffe](/maintainers/mradcliffe)

---

Top Contributors

[![mradcliffe](https://avatars.githubusercontent.com/u/328497?v=4)](https://github.com/mradcliffe "mradcliffe (37 commits)")[![alexfinnarn](https://avatars.githubusercontent.com/u/3640707?v=4)](https://github.com/alexfinnarn "alexfinnarn (2 commits)")

---

Tags

guzzlephp-libraryxero-api

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mradcliffe-xeroclient/health.svg)

```
[![Health](https://phpackages.com/badges/mradcliffe-xeroclient/health.svg)](https://phpackages.com/packages/mradcliffe-xeroclient)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.7M18](/packages/xeroapi-xero-php-oauth2)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)

PHPackages © 2026

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