### PHP SDK getFile Example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for calling getFile. Requires OAuth2 access token and Xero tenant ID. The example uses a sample file ID. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $fileId = "4ff1e5cc-9835-40d5-bb18-09fdb118db9c"; try { $result = $apiInstance->getFile($xeroTenantId, $fileId); } catch (Exception $e) { echo 'Exception when calling FilesApi->getFile: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Initialize Composer project Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/README.md Create a new composer.json file if one does not exist. Requires Composer to be installed. Run this before installing the SDK if you don't have a composer.json file. ```bash composer init ``` -------------------------------- ### PHP SDK getInbox example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for retrieving the inbox folder. Requires OAuth2 access token and Xero tenant ID. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; try { $result = $apiInstance->getInbox($xeroTenantId); } catch (Exception $e) { echo 'Exception when calling FilesApi->getInbox: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK getFolders example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for retrieving folders. Requires OAuth2 access token and Xero tenant ID. The optional sort parameter is set to 'CreatedDateUTC DESC'. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $sort = "CreatedDateUTC DESC"; try { $result = $apiInstance->getFolders($xeroTenantId, $sort); } catch (Exception $e) { echo 'Exception when calling FilesApi->getFolders: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Install xero-php-oauth2 with Composer Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/README.md Install the xero-php-oauth2 SDK via Composer. Requires PHP 8.1 or later. Run this command in the directory containing your composer.json file. ```bash composer require xeroapi/xero-php-oauth2 ``` -------------------------------- ### PHP SDK updateFile example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for updating a file. Requires OAuth2 access token and Xero tenant ID. The $fileObject variable is expected to be defined before the call. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $fileId = "4ff1e5cc-9835-40d5-bb18-09fdb118db9c"; $idempotencyKey = "KEY_VALUE"; try { $result = $apiInstance->updateFile($xeroTenantId, $fileId, $fileObject, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling FilesApi->updateFile: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK updateFolder Example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for updating a folder. Requires OAuth2 access token, Xero tenant ID, folder ID, and optional idempotency key. The $folder variable is expected to be defined elsewhere. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $folderId = "4ff1e5cc-9835-40d5-bb18-09fdb118db9c"; $idempotencyKey = "KEY_VALUE"; try { $result = $apiInstance->updateFolder($xeroTenantId, $folderId, $folder, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling FilesApi->updateFolder: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK getEmployee example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for calling getEmployee. Requires OAuth2 access token and Xero tenant ID. The employee ID is a UUID. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $employeeID = "4ff1e5cc-9835-40d5-bb18-09fdb118db9c"; try { $result = $apiInstance->getEmployee($xeroTenantId, $employeeID); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getEmployee: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK getPayRun example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for calling the getPayRun method. Requires OAuth2 access token and Xero tenant ID. The payRunID is a UUID. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $payRunID = "4ff1e5cc-9835-40d5-bb18-09fdb118db9c"; try { $result = $apiInstance->getPayRun($xeroTenantId, $payRunID); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getPayRun: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Module setup and constants for YAML dump Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au_v2/index.html Module setup with requires, constants for character codes, escape sequences, and style constants, and exports for dump and safeDump. ```javascript var common=require("./common"),YAMLException=require("./exception"),DEFAULT_FULL_SCHEMA=require("./schema/default_full"),DEFAULT_SAFE_SCHEMA=require("./schema/default_safe"),_toString=Object.prototype.toString,_hasOwnProperty=Object.prototype.hasOwnProperty,CHAR_TAB=9,CHAR_LINE_FEED=10,CHAR_SPACE=32,CHAR_EXCLAMATION=33,CHAR_DOUBLE_QUOTE=34,CHAR_SHARP=35,CHAR_PERCENT=37,CHAR_AMPERSAND=38,CHAR_SINGLE_QUOTE=39,CHAR_ASTERISK=42,CHAR_COMMA=44,CHAR_MINUS=45,CHAR_COLON=58,CHAR_GREATER_THAN=62,CHAR_QUESTION=63,CHAR_COMMERCIAL_AT=64,CHAR_LEFT_SQUARE_BRACKET=91,CHAR_RIGHT_SQUARE_BRACKET=93,CHAR_GRAVE_ACCENT=96,CHAR_LEFT_CURLY_BRACKET=123,CHAR_VERTICAL_LINE=124,CHAR_RIGHT_CURLY_BRACKET=125,ESCAPE_SEQUENCES={};ESCAPE_SEQUENCES[0]="\\0",ESCAPE_SEQUENCES[7]="\\a",ESCAPE_SEQUENCES[8]="\\b",ESCAPE_SEQUENCES[9]="\\t",ESCAPE_SEQUENCES[10]="\\n",ESCAPE_SEQUENCES[11]="\\v",ESCAPE_SEQUENCES[12]="\\f",ESCAPE_SEQUENCES[13]="\\r",ESCAPE_SEQUENCES[27]="\\e",ESCAPE_SEQUENCES[34]='\\"',ESCAPE_SEQUENCES[92]="\\\\",ESCAPE_SEQUENCES[133]="\\N",ESCAPE_SEQUENCES[160]="\\_",ESCAPE_SEQUENCES[8232]="\\L",ESCAPE_SEQUENCES[8233]="\\P";var DEPRECATED_BOOLEANS_SYNTAX=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],STYLE_PLAIN=1,STYLE_SINGLE=2,STYLE_LITERAL=3,STYLE_FOLDED=4,STYLE_DOUBLE=5;module.exports.dump=dump,module.exports.safeDump=safeDump; ``` -------------------------------- ### PHP SDK getPayRuns example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for calling the getPayRuns method. Supports optional If-Modified-Since, where, order, and page parameters. The where parameter uses a filter string like Status=="ACTIVE". ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $ifModifiedSince = new DateTime("2020-02-06T12:17:43.202-08:00"); $where = "Status=="ACTIVE""; $order = "EmailAddress%20DESC"; $page = 56; try { $result = $apiInstance->getPayRuns($xeroTenantId, $ifModifiedSince, $where, $order, $page); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getPayRuns: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK sample for postUsageRecords Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/appstore/index.html PHP example using the Xero PHP SDK to call postUsageRecords. Requires OAuth2 access token and a GuzzleHttp client. The example sets subscriptionId and subscriptionItemId to placeholder UUIDs and an idempotency key, then calls the API and catches exceptions. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AppStoreApi( new GuzzleHttp\Client(), $config ); $subscriptionId = "00000000-0000-0000-0000-000000000000"; $subscriptionItemId = "00000000-0000-0000-0000-000000000000"; $idempotencyKey = "KEY_VALUE"; try { $result = $apiInstance->postUsageRecords($subscriptionId, $subscriptionItemId, $createUsageRecord, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling AppStoreApi->postUsageRecords: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK createProject Example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK sample for creating a project. Requires OAuth2 access token and Xero tenant ID. The idempotency key is optional but recommended for safe retries. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $idempotencyKey = "KEY_VALUE"; try { $result = $apiInstance->createProject($xeroTenantId, $projectCreateOrUpdate, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling ProjectApi->createProject: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK createPayrollCalendar example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for creating a payroll calendar. Requires OAuth2 access token and a Xero tenant ID. The example sets up a PayrollCalendar object with name, calendar type, start date, and payment date, then calls createPayrollCalendar with an idempotency key. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $idempotencyKey = "KEY_VALUE"; $startDate = new DateTime('2020-10-28'); $paymentDate = new DateTime('2020-10-30'); $payrollCalendar = new XeroAPI\XeroPHP\Models\PayrollAu\PayrollCalendar; $payrollCalendar->setName('Weekly'); $payrollCalendar->setCalendarType(XeroAPI\XeroPHP\Models\PayrollAu\CalendarType::WEEKLY); $payrollCalendar->setStartDate($startDate); $payrollCalendar->setPaymentDate($paymentDate); $payrollCalendars = []; array_push($payrollCalendars, $payrollCalendar); try { $result = $apiInstance->createPayrollCalendar($xeroTenantId, $payrollCalendar, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->createPayrollCalendar: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### getUsageRecords PHP SDK example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/appstore/index.html Gets all usage records related to the subscription. Requires OAuth2 access token and a valid subscriptionId UUID. Outputs an exception message on failure. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AppStoreApi( new GuzzleHttp\Client(), $config ); $subscriptionId = ""00000000-0000-0000-0000-000000000000""; try { $result = $apiInstance->getUsageRecords($subscriptionId); } catch (Exception $e) { echo 'Exception when calling AppStoreApi->getUsageRecords: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Get Invoice with Filters via Xero API Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/README.md Retrieves invoices with optional filters using getInvoices. The example sets statuses to DRAFT and SUBMITTED, page to 1, and leaves other filters null. It prints the total count or a message when no invoices match, and catches exceptions with a generic message. ```php $if_modified_since = new \DateTime("2019-01-02T19:20:30+01:00"); // \DateTime | Only records created or modified since this timestamp will be returned $if_modified_since = null; $where = 'Type=="ACCREC"'; // string $where = null; $order = null; // string $ids = null; // string[] | Filter by a comma-separated list of Invoice Ids. $invoice_numbers = null; // string[] | Filter by a comma-separated list of Invoice Numbers. $contact_ids = null; // string[] | Filter by a comma-separated list of ContactIDs. $statuses = array("DRAFT", "SUBMITTED");; $page = 1; // int | e.g. page=1 – Up to 100 invoices will be returned in a single API call with line items $include_archived = null; // bool | e.g. includeArchived=true - Contacts with a status of ARCHIVED will be included $created_by_my_app = null; // bool | When set to true you'll only retrieve Invoices created by your app $unitdp = null; // int | e.g. unitdp=4 – You can opt in to use four decimal places for unit amounts try { $apiResponse = $accountingApi->getInvoices($xeroTenantId, $if_modified_since, $where, $order, $ids, $invoice_numbers, $contact_ids, $statuses, $page, $include_archived, $created_by_my_app, $unitdp); if ( count($apiResponse->getInvoices()) > 0 ) { $message = 'Total invoices found: ' . count($apiResponse->getInvoices()); } else { $message = "No invoices found matching filter criteria"; } } catch (Exception $e) { echo 'Exception when calling AccountingApi->getInvoices: ', $e->getMessage(), PHP_EOL; } ``` -------------------------------- ### Create Folder with PHP SDK Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for creating a folder. Requires OAuth2 access token and Xero tenant ID. The $folder variable is expected to be defined before the call. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $idempotencyKey = "KEY_VALUE"; try { $result = $apiInstance->createFolder($xeroTenantId, $folder, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling FilesApi->createFolder: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Create Timesheet with PayrollAuV2Api in PHP Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au_v2/index.html PHP SDK example for creating a new timesheet via the PayrollAuV2Api. Requires OAuth2 access token, Xero tenant ID, and optional idempotency key. The timesheet object must include payroll calendar ID, employee ID, start date, and end date. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuV2Api( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $idempotencyKey = "KEY_VALUE"; $startDate = new DateTime('2020-10-28'); $endDate = new DateTime('2020-10-30'); $timesheet = new XeroAPI\XeroPHP\Models\PayrollAuV2\Timesheet; $timesheet->setPayrollCalendarID('00000000-0000-0000-0000-000000000000'); $timesheet->setEmployeeID('00000000-0000-0000-0000-000000000000'); $timesheet->setStartDate($startDate); $timesheet->setEndDate($endDate); try { $result = $apiInstance->createTimesheet($xeroTenantId, $timesheet, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling PayrollAuV2Api->createTimesheet: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Create Leave Application with PayrollAuApi Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP example for creating a leave application using the PayrollAuApi. Requires OAuth2 access token and Xero tenant ID. The leave application object must include employee ID, leave type ID, title, start date, and end date. The idempotency key is optional but recommended for safe retries. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $idempotencyKey = "KEY_VALUE"; $startDate = new DateTime('2020-10-28'); $endDate = new DateTime('2020-10-30'); $leaveApplication = new XeroAPI\XeroPHP\Models\PayrollAu\LeaveApplication; $leaveApplication->setEmployeeId('00000000-0000-0000-0000-000000000000'); $leaveApplication->setLeaveTypeId('00000000-0000-0000-0000-000000000000'); $leaveApplication->setTitle('Annual Leave'); $leaveApplication->setStartDate($startDate); $leaveApplication->setEndDate($endDate); try { $result = $apiInstance->createLeaveApplication($xeroTenantId, $leaveApplication, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->createLeaveApplication: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Buffer module initialization and static methods Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html Main Buffer module setup: requires base64-js, ieee754, isarray; exports Buffer, SlowBuffer, INSPECT_MAX_BYTES; sets poolSize; defines static methods isBuffer, compare, isEncoding, concat, byteLength; prototype methods toString, equals, inspect. ```javascript var base64=require("base64-js"),ieee754=require("ieee754"),isArray=require("isarray");exports.Buffer=Buffer,exports.SlowBuffer=SlowBuffer,exports.INSPECT_MAX_BYTES=50,Buffer.poolSize=8192;var rootParent={};Buffer.TYPED_ARRAY_SUPPORT=void 0!==global.TYPED_ARRAY_SUPPORT?global.TYPED_ARRAY_SUPPORT:typedArraySupport(),Buffer.TYPED_ARRAY_SUPPORT?(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array):(Buffer.prototype.length=void 0,Buffer.prototype.parent=void 0),Buffer.isBuffer=function(t){return!(null==t||!t._isBuffer)},Buffer.compare=function(t,e){if(!Buffer.isBuffer(t)||!Buffer.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,f=0,i=Math.min(r,n);i>f&&t[f]===e[f];)++f;return f!==i&&(r=t[f],n=e[f]),n>r?-1:r>n?1:0},Buffer.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(t,e){if(!isArray(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new Buffer(0);var r;if(void 0===e)for(e=0,r=0;r0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... " ``` -------------------------------- ### Xero API Request Example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html Example of making an API request to Xero using the OAuth2 token. ```php 'YOUR_CLIENT_ID', 'clientSecret' => 'YOUR_CLIENT_SECRET', 'redirectUri' => 'https://your-app.com/callback', ]); // Retrieve stored token $token = $_SESSION['xero_token']; $client->setAccessToken($token); // Make an API request $response = $client->get('https://api.xero.com/api.xro/2.0/Invoices'); $invoices = json_decode($response->getBody(), true); print_r($invoices); ?> ``` -------------------------------- ### PHP SDK sample for createAsset Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/assets/index.html Shows how to use the Xero PHP SDK to call the createAsset API. Configure OAuth2 access token and tenant ID, then create an Asset instance and pass it to the API. Requires the 'assets' scope for read-write access. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AssetApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $idempotencyKey = "KEY_VALUE"; $asset = new XeroAPI\XeroPHP\Models\Asset\Asset; $asset->setassetName('Other Computer'); $asset->setassetNumber('FA-00210'); $asset->setStatus(XeroAPI\XeroPHP\Models\Asset\AssetStatus::Draft); try { $result = $apiInstance->createAsset($xeroTenantId, $asset, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling AssetApi->createAsset: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### GET /PayRuns endpoint Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html Endpoint for retrieving a list of pay runs. Use the GET method with this path. ```http /PayRuns ``` -------------------------------- ### PHP SDK call to getSuperfundProducts Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for calling getSuperfundProducts. Requires OAuth2 access token and Xero tenant ID. Optional ABN and USI query parameters are provided. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $aBN = "40022701955"; $uSI = "OSF0001AU"; try { $result = $apiInstance->getSuperfundProducts($xeroTenantId, $aBN, $uSI); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getSuperfundProducts: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK getAssociationsCount Example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/files/index.html PHP SDK example for calling getAssociationsCount. Requires OAuth2 access token and Xero tenant ID. The $objectIds array is empty in the example; the API expects a comma-separated list of object IDs. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\FilesApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $objectIds = array() try { $result = $apiInstance->getAssociationsCount($xeroTenantId, $objectIds); } catch (Exception $e) { echo 'Exception when calling FilesApi->getAssociationsCount: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### GET /PayRuns/{PayRunID} endpoint Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html Endpoint for retrieving a single pay run by its unique PayRunID. Use the GET method with this path. ```http /PayRuns/{PayRunID} ``` -------------------------------- ### GET /subscriptions/{subscriptionId}/usage-records Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/appstore/index.html Gets all usage records related to the subscription. The endpoint requires the marketplace.billing scope and OAuth2 authentication. ```APIDOC ## [GET] /subscriptions/{subscriptionId}/usage-records ### Description Gets all usage records related to the subscription. ### Method GET ### Endpoint /subscriptions/{subscriptionId}/usage-records ### Parameters #### Path Parameters - **subscriptionId** (uuid) - Required - Unique identifier for Subscription object ### Request Example No request body required. ### Response #### Success Response (200) - **UsageRecords** (array) - List of usage records #### Response Example No response example provided. ### Scopes - **marketplace.billing** - Grant read-only access to fixed assets ### SDK Sample (PHP) ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AppStoreApi( new GuzzleHttp\Client(), $config ); $subscriptionId = "00000000-0000-0000-0000-000000000000"; try { $result = $apiInstance->getUsageRecords($subscriptionId); } catch (Exception $e) { echo 'Exception when calling AppStoreApi->getUsageRecords: ', $e->getMessage(), PHP_EOL; } ?> ``` ``` -------------------------------- ### PHP: getTimeEntries with ProjectApi Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK example for retrieving time entries for a project using the ProjectApi. Requires OAuth2 access token and Xero tenant ID. The example passes all optional query parameters (userId, taskId, invoiceId, contactId, page, pageSize, states, isChargeable, dateAfterUtc, dateBeforeUtc) and prints an exception message on failure. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $userId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $taskId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $invoiceId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $contactId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $page = 1; $pageSize = 10; $states = array() $isChargeable = true; $dateAfterUtc = new DateTime("2013-10-20T19:20:30+01:00"); $dateBeforeUtc = new DateTime("2013-10-20T19:20:30+01:00"); try { $result = $apiInstance->getTimeEntries($xeroTenantId, $projectId, $userId, $taskId, $invoiceId, $contactId, $page, $pageSize, $states, $isChargeable, $dateAfterUtc, $dateBeforeUtc); } catch (Exception $e) { echo 'Exception when calling ProjectApi->getTimeEntries: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK call to getProjects Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK sample for calling the getProjects endpoint. Requires OAuth2 access token and Xero-Tenant-Id. The example sets up the ProjectApi client and calls getProjects with optional query parameters. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectIds = array() $contactID = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $states = "states_example"; $page = 1; $pageSize = 100; try { $result = $apiInstance->getProjects($xeroTenantId, $projectIds, $contactID, $states, $page, $pageSize); } catch (Exception $e) { echo 'Exception when calling ProjectApi->getProjects: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK call to getAssetSettings Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/assets/index.html PHP SDK example for calling AssetApi::getAssetSettings. Requires OAuth2 access token and xero-tenant-id header. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AssetApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; try { $result = $apiInstance->getAssetSettings($xeroTenantId); } catch (Exception $e) { echo 'Exception when calling AssetApi->getAssetSettings: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP: getProject Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK sample for retrieving a single project using the ProjectApi. Requires OAuth2 access token and Xero tenant ID. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; try { $result = $apiInstance->getProject($xeroTenantId, $projectId); } catch (Exception $e) { echo 'Exception when calling ProjectApi->getProject: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK sample for getLeaveApplicationsV2 Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK sample for retrieving leave applications using the PayrollAuApi. Configure OAuth2 access token, set the Xero tenant ID, and optionally provide If-Modified-Since, where, order, and page parameters. The call returns up to 100 objects per page. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $ifModifiedSince = new DateTime("2020-02-06T12:17:43.202-08:00"); $where = "Status==\"ACTIVE\""; $order = "EmailAddress%20DESC"; $page = 56; try { $result = $apiInstance->getLeaveApplicationsV2($xeroTenantId, $ifModifiedSince, $where, $order, $page); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getLeaveApplicationsV2: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Create an account with AccountingApi->createAccount Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/README.md Shows how to create an account using the AccountingApi. Requires an OAuth2 access token and a Xero tenant ID. The account is configured with code, name, type EXPENSE, and description, then passed to createAccount. Exceptions are caught and printed. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "YOUR_XERO_TENANT_ID"; $account = new XeroAPI\XeroPHP\Models\Accounting\Account; $account->setCode('123456'); $account->setName('FooBar'); $account->setType(XeroAPI\XeroPHP\Models\Accounting\AccountType::EXPENSE); $account->setDescription('Hello World'); try { $result = $apiInstance->createAccount($xeroTenantId, $account); } catch (Exception $e) { echo 'Exception when calling AccountingApi->createAccount: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK getEmployees example Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/payroll_au/index.html PHP SDK example for calling getEmployees with optional filters: If-Modified-Since, where, order, and page. The page parameter limits results to 100 employees per call. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\PayrollAuApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $ifModifiedSince = new DateTime("2020-02-06T12:17:43.202-08:00"); $where = "Status=="ACTIVE""; $order = "EmailAddress%20DESC"; $page = 56; try { $result = $apiInstance->getEmployees($xeroTenantId, $ifModifiedSince, $where, $order, $page); } catch (Exception $e) { echo 'Exception when calling PayrollAuApi->getEmployees: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP: getTasks Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK example for retrieving all project tasks using the ProjectApi. Requires OAuth2 access token and Xero tenant ID. Supports pagination via page and pageSize, and filtering by taskIds and chargeType. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $page = 1; $pageSize = 10; $taskIds = "taskIds_example"; $chargeType = ; try { $result = $apiInstance->getTasks($xeroTenantId, $projectId, $page, $pageSize, $taskIds, $chargeType); } catch (Exception $e) { echo 'Exception when calling ProjectApi->getTasks: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### PHP SDK: getTimeEntry Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK example for calling the getTimeEntry endpoint. Requires OAuth2 access token and Xero tenant ID. The example uses placeholder values for projectId and timeEntryId. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $timeEntryId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; try { $result = $apiInstance->getTimeEntry($xeroTenantId, $projectId, $timeEntryId); } catch (Exception $e) { echo 'Exception when calling ProjectApi->getTimeEntry: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Update project with Xero PHP SDK (ProjectApi->updateProject) Source: https://github.com/xeroapi/xero-php-oauth2/blob/master/docs/v2/projects/index.html PHP SDK sample for updating a specific project. Requires OAuth2 access token, Xero tenant ID, project ID, and optional idempotency key. The call uses ProjectApi->updateProject and catches exceptions. ```php setAccessToken( 'YOUR_ACCESS_TOKEN' ); $apiInstance = new XeroAPI\XeroPHP\Api\ProjectApi( new GuzzleHttp\Client(), $config ); $xeroTenantId = "xeroTenantId_example"; $projectId = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; $idempotencyKey = "KEY_VALUE"; try { $apiInstance->updateProject($xeroTenantId, $projectId, $projectCreateOrUpdate, $idempotencyKey); } catch (Exception $e) { echo 'Exception when calling ProjectApi->updateProject: ', $e->getMessage(), PHP_EOL; } ?> ```