xero-api

Profit and Loss Raw time series data for a specified period with Xero APIs


I want to get the raw time series data for all the charts for Profit and Loss and Balance Sheet. I went through the API documentation and could only find report/summary data for P&L and BS. Is there a way I can fetch all the data for all the charts/categories.

For example: If I request the ProfitAndLoss data then I should get the data shown below in json format.

A sample time series financial data for a company


Solution

  • https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=2020-08-01&toDate=2021-07-31&periods=11&timeframe=MONTH

    should return JSON that gets what you want.

    From Xero ProfitAndLoss endpoint docs

    Edit to modify API query:

    Should be:

    https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=2021-08-01&toDate=2021-08-31&periods=11&timeframe=MONTH

    Xero has quirky way to retrieve data. The modified query basically says get Aug 2021 and compare it to the previous 11 monthly periods eg all the way back to Sep 2020. This is the way the Xero UI reporting works too. The result is a table with columns for Aug 2021, Jul 2021, Jun 2021, May 2021, Apr 2021, Mar 2021, Feb 2021, Jan 2021, Dec 2020, Nov 2020, Oct 2020, Sep 2020, and rows for each account values by month.

    Also note that you should choose a month with 31 days as the first month to compare to, else another Xero quirk will truncate all compared periods to how ever many days your start month has eg 30 days if you choose Sep to start.

    The first query retrieves a not quite cumulative, read forward result, which to my mind is not useful at all.