Search API Connector Documentation

Print

Import Xero Data to Google Sheets

premium

In this guide, we’ll walk through how to pull Xero accounting data data directly into Google Sheets, using the API Connector add-on for Sheets.

Contents

What Does This Integration Do?

This integration pulls accounting data from Xero’s Accounting API into Google Sheets. It enables the following scopes: openid, email, profile, offline_access, accounting.reports.read, accounting.transactions.read, accounting.settings.read, and accounting.contacts.read.

xero-img13

Before You Begin

Click here to install the API Connector add-on from the Google Marketplace.

Part 1: Connect to the Xero API

If you haven’t connected to the Xero API before, you’ll first need to initiate the connection.

  1. Open up Google Sheets and click Add-ons > API Connector > Manage Connections.
  2. In the list of available connections, find Xero and click Connect.
    xero-oauth2-img1
  3. You will be directed to Xero and asked to Allow Access.
    xero-oauth2-img2
  4. You’ll then be returned to your Google Sheet, and can verify that your Xero connection is active in the Connections screen.

Part 2: Create Your Xero API Request URL

For our first request, we’ll get your Xero tenant ID, since you’ll need this to create subsequent requests.

  • API root: https://api.xero.com
  • Endpoint: /connections

Putting it all together, we get the full API Request URL.

https://api.xero.com/connections

Part 3: Pull Xero API Data into Sheets

Now let’s enter our URL into API Connector and import Xero data into Google Sheets.

  1. Back in the Create Request interface, enter the Request URL we just created above.
    xero-oauth2-img4
  2. You don’t need any headers so just leave that section blank.
  3. Under Authentication, choose Xero from the dropdown menu.
    xero-oauth2-img5
  4. Create a new tab and click ‘Set current’ to use that tab as your data destination.
  5. Name your request and click Run. A moment later you’ll see some information about your Xero account populate your sheet. Pay special attention to the value located in the tenantId field as you’ll need it in future requests.
    xero-oauth2-img6
  6. All subsequent requests need to add the tenant ID as a header, where the key is xero-tenant-id and the value is your tenant ID, like this:
    xero-oauth2-img7
  7. We’ll show that again in the next section. Let’s start pulling in data about your Xero account!

Part 4: Example API URLs

You can access the Xero Accounting API documentation here, but if you just want to get started, you can try the following example URLs.

  • Invoices
    https://api.xero.com/api.xro/2.0/Invoices
    xero-oauth2-img8
  • Accounts
    https://api.xero.com/api.xro/2.0/Accounts
    xero-oauth2-img9
  • Bank Transactions
    https://api.xero.com/api.xro/2.0/BankTransactions
  • Contacts
    https://api.xero.com/api.xro/2.0/Contacts
  • Items
    https://api.xero.com/api.xro/2.0/Items
  • Payments
    https://api.xero.com/api.xro/2.0/Payments

Part 5: Handle Pagination

Xero limits the number of records returned in each request. By default, only 100 records will be returned unless you use the ‘page’ parameter as described in their documentation.

xero-oauth2-img10

To access more than 100 records, loop through pages automatically with pagination handling, like this:

  • API URL: enter your request URL as usual
  • Pagination type: page parameter
  • Page parameter: page
  • Number of pages: enter the number of pages you’d like to fetch
    xero-oauth2-img11

FAQ

  • How do I disconnect from Xero?
    To disconnect from Xero, click the Manage Connections link and click Disconnect next to the Xero connection.
  • What doesn’t your integration do?
    This integration does not push data from Google Sheets to Xero. It is a one-way connection that pulls data from Xero to Sheets.
  • When and how does data get pulled into Sheets?
    Data can be pulled into Sheets by opening your request and manually clicking Run, which will refresh your sheet with the latest data from Xero’s API. Alternatively, you can enable scheduling and automatically refresh requests at the cadence you select (up to 1x an hour).
  • Can I run scheduled updates more than once an hour?
    Scheduled triggers can not run more than once an hour. This limit is set by Google and applies to all Sheets add-ons.
  • How much data can I pull into Sheets?
    There is no specific limit on the amount of data you can pull from Xero’s API into Google Sheets. However, Google Sheets only lets requests run for 6 minutes per execution, so very large requests may time out and fail to complete. If you experience issues, please limit requests where possible (e.g. use append mode to fetch new data instead of fetching the entire data set each time).
Previous Import WordPress Data to Google Sheets
Next Import YouTube Analytics Data to Google Sheets

8 thoughts on “Import Xero Data to Google Sheets”

  1. Hi there – I’ve been trying to get a custom OAuth2 connection to work with Workflowmax, which is owned by xero. I see that you have a xero connector but it doesn’t seem to apply to workflowmax. Any tips on how I would configure a custom connector?

    So far I have a client id, and secret and I think I have the authentication URL right but i’m not sure how to build the token URL or how to use the token in the header of a subsequent request.

    Reply
    • Hey Jay, if you’re using OAuth2 you shouldn’t need to manually add any tokens to your headers. The authorization and token URLs should be provided in the Workflowmax docs (I just checked and it looks like authorization URL = https://login.xero.com/identity/connect/authorize?scope=workflowmax&offline_access and token URL = https://identity.xero.com/connect/token). Can you please try that and let me know how it goes?

      Reply
      • Thanks for your quick response!

        The two URLs you’ve identified are what I have configured so that’s good and I think it’s working. When I click on the ‘connect’ button it authenticates against xero and returns to the google sheet as expected.

        Given that i’m using the OAuth2 connector you indicated that I don’t need to do the token refresh. And of course, you’re right! I just re-read how to make calls to the API and I was missing a header for the tenant id. I’ve added that and it’s working as expected now.

        Thanks for your help!

  2. I am busy working on this and would like to limit the results of the Xero Items API calls. It’s working perfectly except for the sales details unit price.

    Can anyone see anything wrong with this
    Items[*].{Code:Code,Description:Description,QuantityOnHand:QuantityOnHand,Xero_Price:SalesDetails[*].unitPrice,IsTrackedAsInventory:IsTrackedAsInventory}

    Thanks

    Reply
    • Hey Andrew, the problem is that SalesDetails is an object, not an array. Please try this instead:
      Items[*].{Code:Code,Description:Description,QuantityOnHand:QuantityOnHand,Xero_Price:SalesDetails.UnitPrice,IsTrackedAsInventory:IsTrackedAsInventory}

      Reply
    • Do you mean the P&L report described here? https://developer.xero.com/documentation/api/accounting/reports#profit-and-loss
      In that case you’d create a request like https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=+++Sheet1!A1+++&toDate=+++Sheet1!A2+++, where you reference the date cells in your sheet as described here.

      As an aside, Xero sends this report data back in a way that doesn’t work well with Sheets, so you can also restructure the data with the following JMESPath (just copy and paste this into the JMESPath field before running): Reports[].Rows[].Rows[].{Category:Cells[0],Values:Cells[1]}

      Reply

Leave a Comment

Table of Contents