reports

The following methods allow for interaction with the ZBI Reports API endpoints.

Methods are accessible via zbi.reports

Copyright (c) 2023, Zscaler Inc.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class ReportsAPI

Bases: APIClient

A Client object for the Business Insights Reports resource.

Provides operations to list available reports and download report files from Zscaler Business Insights.

download_report(file_name, report_type, sub_type='CustomDataFeed', compression=None, save_path=None)

Downloads a specific report file from Business Insights.

Sends a POST request to /bi/api/v1/report/download with a JSON body and accepts binary (application/octet-stream) response.

Parameters:
  • file_name (str) – The file name of the report to download (server-side identifier).

  • report_type (str) – The report type. One of: APPLICATION, DATA_EXPLORER, WORKPLACE.

  • sub_type (str, optional) – The report subtype. One of: CustomDataFeed, ScheduledReports, SaveAndSchedule. Defaults to CustomDataFeed.

  • compression (str, optional) – Compression type. Only gzip is supported.

  • save_path (str, optional) – Local path to save the downloaded file. Defaults to file_name.

Returns:

Path to the saved file.

Return type:

str

Raises:
  • ValueError – If file_name is empty or types are invalid.

  • Exception – If the request fails or response is invalid.

Examples

Download an APPLICATION report:

>>> path = client.zbi.reports.download_report(
...     file_name="my-report.csv",
...     report_type="APPLICATION",
...     sub_type="CustomDataFeed",
...     save_path="./reports/my-report.csv"
... )
>>> print(f"Report saved to {path}")
list_reports(query_params=None)

Retrieves a list of available reports.

Parameters:

query_params (dict, optional) –

Map of query parameters.

[query_params.reportType] (str): Type of report. One of: APPLICATION, DATA_EXPLORER, WORKPLACE. Default: APPLICATION.

[query_params.subType] (str): Subtype of report. One of: CustomDataFeed, ScheduledReports, SaveAndSchedule. Default: CustomDataFeed.

[query_params.startTime] (int): Report start time as Unix timestamp (seconds). Defaults to midnight UTC of the 1st day of the previous month.

[query_params.endTime] (int): Report end time as Unix timestamp (seconds). Defaults to current time.

[query_params.reportName] (str): Filter by report name (optional).

Returns:

(list of report dicts, Response, error).

Return type:

tuple

Examples

List all DATA_EXPLORER reports:

>>> reports, _, err = client.zbi.reports.list_reports(
...     query_params={
...         "reportType": "DATA_EXPLORER",
...         "subType": "SaveAndSchedule"
...     }
... )
>>> if err:
...     print(f"Error: {err}")
>>> for r in reports:
...     print(r)

Client-side filtering with JMESPath:

The response object supports client-side filtering and projection via resp.search(expression). See the JMESPath documentation for expression syntax.