The grid API allows you to export data in multiple file formats in addition to the default JSON:
- Excel (xlsx): Microsoft Excel spreadsheet
- coming soon CSV: Comma-separated values
- coming soon TSV: Tab-separated values
- coming soon Parquet: Apache Parquet file format
Getting an exported file from the Grid API is a three-step process:
- Request the export
- Wait for the export to finish
- Download the exported file
To request an export, send a POST
request to the entity's endpoint URL with the exports
suffix:
https://api.observepoint.com/v3/reports/grid/<entity-type>/exports
(API reference)
The POST
payload supports the same JSON as a normal Grid API request, with all the same columns, filters, sorting, pagination, and grouping.
Tip: pagination is not necessary with the exports API.
coming soon The export API will allow you to pass the optional field exportFileType
to specify the type of file to be exported (currently only xlsx
is supported, but csv
, tsv
, and parquet
are coming soon)
{
"columns": [
{
"columnId": "COLUMN_ID_1",
},
{
"columnId": "COLUMN_ID_2",
}
],
// Coming soon:
"exportFileType": "tsv" // specify the type of export file: xlsx, csv, tsv, parquet
}
The API will respond with an exportId
that you can use to track the export status.
{
"exportId": 123456
}
Your code will use the exportId
value in the next step.
Exports can take a few seconds or a few minutes to complete, depending on the size of the exported file.
Poll for the exports API every 5-60 seconds until the export is complete:
https://api.observepoint.com/v3/exports/?exportIds=<exportId>
The API will respond with an array of one export object, like this:
{
"exports": [
{
"exportId": 123456,
"exportStatus": "in_progress", // poll until this changes to "completed"
"exportType": "GRID_DATA_EXPORT",
"exportDownloadLink": "https://api.observepoint.com/v3/exports/68c38841-e924-4cd0-a615-ef67d2bcf103"
}
]
}
Use the URL in exportDownloadLink
to download the exported file. Following this URL will redirect you to the actual download URL for the file.
The following example shows how to do this in Python:
import requests
# Get the export download link from the /v3/exports/?exportIds=123456 JSON response
export_download_link = exports_response_json["exports"]][0]["exportDownloadLink"]
# Tip: the requests library will automatically follow the redirect
response = requests.get(export_download_link)
response.raise_for_status()
with open(f'/tmp/my-export.xlsx', 'wb') as f:
for chunk in response.iter_content():
if chunk:
f.write(chunk)
Now the file is available on your local filesystem at the location of your choice.