PHPackages                             fooman/xero-php-oauth2 - 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. fooman/xero-php-oauth2

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

fooman/xero-php-oauth2
======================

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

8.0.0-p2(2mo ago)02.5kMITPHPPHP &gt;=7.1 &lt;8.5CI passing

Since Aug 13Pushed 2mo agoCompare

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

READMEChangelogDependencies (6)Versions (90)Used By (0)

xero-php-oauth2
===============

[](#xero-php-oauth2)

[![Latest Stable Version](https://camo.githubusercontent.com/383da6859a071e4c2a475ae8ab669f659c398462382e7e2431cfd4f231ebd341/687474703a2f2f706f7365722e707567782e6f72672f7865726f6170692f7865726f2d7068702d6f61757468322f76)](https://packagist.org/packages/xeroapi/xero-php-oauth2)[![Total Downloads](https://camo.githubusercontent.com/4be0ff41340091db1a2fccf066530088c993faaad00e469b084b2f4676c52f5b/687474703a2f2f706f7365722e707567782e6f72672f7865726f6170692f7865726f2d7068702d6f61757468322f646f776e6c6f616473)](https://packagist.org/packages/xeroapi/xero-php-oauth2)[![Github forks](https://camo.githubusercontent.com/9aa1ce1b200486963827b7514a9159856835f8d29190397c2cf8041a47560499/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f5865726f4150492f7865726f2d7068702d6f61757468322e737667)](https://github.com/XeroAPI/xero-php-oauth2/network)[![Github stars](https://camo.githubusercontent.com/6c0cc1123e7ee211e9460ad1ff1daab98915b6db7b59934f390a59516b9ff360/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f5865726f4150492f7865726f2d7068702d6f61757468322e737667)](https://github.com/XeroAPI/xero-php-oauth2/stargazers) [![License](https://camo.githubusercontent.com/928969a3010ab105b89ef250bcf38c6c4ffaab17546b80c36474aa5a614756d5/687474703a2f2f706f7365722e707567782e6f72672f7865726f6170692f7865726f2d7068702d6f61757468322f6c6963656e7365)](https://packagist.org/packages/xeroapi/xero-php-oauth2)

The `xero-php-oauth2` SDK makes it easy for developers to access Xero's APIs in their **PHP** code, and build robust applications and software using small business &amp; general ledger accounting data.

Table of Contents
=================

[](#table-of-contents)

- [API Client documentation](#api-client-documentation)
- [Sample Applications](#sample-applications)
- [Xero Account Requirements](#xero-account-requirements)
- [Installation](#installation)
- [Authentication](#authentication)
- [Configuration](#configuration)
- [Custom Connections](#custom-connections)
- [API Clients](#api-clients)
- [SDK conventions](#sdk-conventions)
- [Contributing](#contributing)

---

API Client documentation
------------------------

[](#api-client-documentation)

This SDK supports full method coverage for the following Xero API sets:

API SetDescription[`Accounting methods`](https://xeroapi.github.io/xero-php-oauth2/docs/v2/accounting/index.html)The Accounting API exposes accounting functions of the main Xero application *(most commonly used)*[Assets](https://xeroapi.github.io/xero-php-oauth2/docs/v2/assets/index.html)The Assets API exposes fixed asset related functions of the Xero Accounting application[Files](https://xeroapi.github.io/xero-php-oauth2/docs/v2/files/index.html)The Files API provides access to the files, folders, and the association of files within a Xero organisation[Projects](https://xeroapi.github.io/xero-php-oauth2/docs/v2/projects/index.html)Xero Projects allows businesses to track time and costs on projects/jobs and report on profitability[Payroll (AU)](https://xeroapi.github.io/xero-php-oauth2/docs/v2/payroll_au/index.html)The (AU) Payroll API exposes payroll related functions of the payroll Xero application[Payroll (UK)](https://xeroapi.github.io/xero-php-oauth2/docs/v2/payroll_uk/index.html)The (UK) Payroll API exposes payroll related functions of the payroll Xero application[Payroll (NZ)](https://xeroapi.github.io/xero-php-oauth2/docs/v2/payroll_nz/index.html)The (NZ) Payroll API exposes payroll related functions of the payroll Xero application[Object Model Documentation](https://github.com/XeroAPI/xero-php-oauth2/tree/master/doc)Additional format of method docs, as well as full object model and field definition documentation can be found by clicking through the desired file paths[![drawing](https://camo.githubusercontent.com/820a3fb4dcd4a5b641d1a767a7f1b1df4319293b6672ab56f37a1b89abb3bc00/68747470733a2f2f692e696d6775722e636f6d2f37764f4e564f522e706e67)](https://camo.githubusercontent.com/820a3fb4dcd4a5b641d1a767a7f1b1df4319293b6672ab56f37a1b89abb3bc00/68747470733a2f2f692e696d6775722e636f6d2f37764f4e564f522e706e67)

---

Sample Applications
-------------------

[](#sample-applications)

Sample apps can get you started quickly with simple auth flows and advanced usage examples.

Sample AppDescription[`starter-app`](https://github.com/XeroAPI/Xero-php-oauth2-starter)Basic getting started code samples[`full-app`](https://github.com/XeroAPI/Xero-php-oauth2-app)Complete app with more complex examples[`custom-connections-starter`](https://github.com/XeroAPI/xero-php-oauth2-custom-connections-starter)Basic app showing Custom Connections - a Xero [premium option](https://developer.xero.com/documentation/oauth2/custom-connections) for building M2M integrations to a single orgs---

Xero Account Requirements
-------------------------

[](#xero-account-requirements)

- Create a [free Xero user account](https://www.xero.com/us/signup/api/)
- Login to your Xero developer [dashboard](https://developer.xero.com/app/manage) and create an API application
- Copy the credentials from your API app and store them using a secure ENV variable strategy
- Decide the [neccesary scopes](https://developer.xero.com/documentation/oauth2/scopes) for your app's functionality

Installation
============

[](#installation)

To install this SDK in your project we recommend using [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) (For OSX we recommend using [Homebrew](https://formulae.brew.sh/formula/composer)).

All third party libraries dependencies managed with Composer and the SDK requires `PHP 5.6` and later.

To install the bindings via [Composer](http://getcomposer.org/), and add the xero-php-oauth2 sdk to your `composer.json` and navigate to where your composer.json file is and run the command:

```
composer require xeroapi/xero-php-oauth2

```

If no `composer.json` file exists, create one by running the following command. You'll need [Composer](http://getcomposer.org/) installed.

```
composer init

```

### Configure PHPStorm

[](#configure-phpstorm)

We've received feedback that PHPStorm IDE default file size is too small to load the AccountingApi class.

"PHPStorm seems unable to resolve the XeroAPI\\XeroPHP\\Api\\AccountingApi class. It just shows Undefined class 'AccountingApi' and therefore can't autocomplete any of the methods etc."

To fix this, add the following to the idea.properties file to increase this limit to 5000 kilobytes

idea.max.intellisense.filesize=5000

Instructions here for [configuring PHPStorm](https://www.jetbrains.com/help/phpstorm/tuning-the-ide.html#configure-platform-properties) platform properties on Mac/Windows/Linux

### Laravel

[](#laravel)

Xero doesn't offer support on how to use of our SDKs in different frameworks, etc. We had a recommendation by Matt @hailwood in our developer community. They integrates xero-php-oauth2 and Laravel using the following package.

-
-

---

Authentication
--------------

[](#authentication)

Below is starter code with the authorization flow. You can use the code below by creating 4 separate PHP files and securely replacing your **CLIENT\_ID, CLIENT\_SECRET and REDIRECT\_URI**

All API requests go through Xero's OAuth2.0 gateway and require a valid `access_token` to be set on the `client` which appends the `access_token` [JWT](https://jwt.io/) to the header of each request.

If you are making an API call for the first time the code below shows the auth flow using 4 separate PHP files and will work with these secure credentials replaced with your own:

- **CLIENT\_ID**
- **CLIENT\_SECRET**
- **REDIRECT\_URI**

> You can also see usage of the sdk in our [sample app](https://github.com/XeroAPI/xero-php-oauth2-starter).

### Important

[](#important)

The RedirectURI (ex. ) in your code needs to point to the callback.php file and match the RedirectURI you set when creating your Xero app.

1. Point your browser to authorization.php, you'll be redirected to Xero where you'll login and select a Xero org to authorize. We recommend the **Demo Company** org, since this code can modify data in the org you connect to.
2. Once complete, you'll be returned to your app to the redirect URI which should point to the callback.php.
3. In callback.php, you'll obtain an access token which we'll use in authorizedResource.php to create, read, update and delete information in the connected Xero org.

### authorization.php

[](#authorizationphp)

```
