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: RefreshXeroTokens
The script is under source control and can be accessed from the following repository:
Speakeasy Azure Runbook Repository
See the following article which provides an overview, inccluding how to make changes to scripts using git:
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: RefreshXeroTokens 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.