Help Center
< All Topics
Print

Overview

This script refreshes tokens which were originally obtained to establish a connection to the Xero package. Without the token refresh, any tokens would expire within 30 minutes after the time they were issued. By having a refresh process, other Azure runbooks can connect to Xero even if those scripts only run once per month.

Where to Find It

Name of runbook: Speakeasy-XeroAccessTokens
The script can be viewed and edited via the following link: Speakeasy-RefreshXeroAccessTokens. The script is hosted in the cloud, using Microsoft Azure, because it is run on a scheduled basis. See the following document (advanced users only!!) regarding how the script was initially created in the Azure environment: Creating a PowerShell script in Azure
Azure runbook schedules are restricted to running hourly, but we need a greater frequency of operation or the Xero tokens could expire. To achieve this, the script is scheduled to run using three schedules, XeroTokenRefreshSchedule1, XeroTokenRefreshSchedule2 and XeroTokenRefreshSchedule3, which run hourly, one on the hour, one at twenty past the hour and one at twenty to the hour. The schedules can be viewed via the following link: Speakeasy-RefreshXeroAccessTokens Schedules.
The script generates a log file which can be checked for errors. This can be seen here:

How it Works

The purpose of this script is to refresh a token (an “access token”) which provides programmatic access to data in the Xero finance package.  It achieves this by retrieving the current refresh token from the SpeakeasyXeroRefreshToken Azure Automation variable and making a call to Xero for a token refresh. If successful, Xero will respond with a new access token and refresh token. These new values are stored in their respective Azure Automation variables. If the token is not refreshed within 30 minutes, access to Xero data is prohibited – hence the reason the refresh takes place every twenty minutes. If this occurs, the SpeakeasyGetXeroTokens.ps1 script needs to be re-executed.
See the Obtaining Xero Access and Refresh Tokens page, which describes the Xero authentication process in more detail, including how the initial access and refresh token is obtained.