5 minute read
November 10, 2020

Exporting and Downloading Datasets

The DiVA API enables you to define a Marqeta platform dataset and export it as a compressed CSV file. You can choose between Zip or Gzip compression. After export, you use the API to download the compressed file.

Exporting a dataset as a file

You can export any dataset as a CSV file by sending a GET request to the appropriate endpoint. To construct your endpoint URL, start with the URL you would use to retrieve that same dataset in JSON format, for example:


Then insert the export_type path parameter (/csv) before the query string, for example:


By default, the resulting dataset is compressed as a gz file. You can compress it as a zip file by including the compress query parameter, for example:


Because the export operation is processed asynchronously, you should receive an immediate 202 Accepted response. The JSON-formatted response body contains a token that you will use in downloading your data-set file, for example:


Is this helpful?


Downloading the exported file

By default, the DiVA API returns 1,048,575 rows in a file export and can take several minutes to generate the file. You can increase the download limit up to 5,000,000 rows by including the max_count=5000000 parameter.

To retrieve your file, send a GET request to the /download?token={my_download_token} endpoint, where {my_download_token} is the value of the token field that was returned in response to your export request, for example:


The token value includes two filename extensions (for example, .csv.gz). You must include these extensions in your request URL.

The API returns one of these responses:

  • If the job is not finished: The 202 "Accepted" HTTP response code and a plain-text body containing the word Pending.

  • If the job is finished: The 200 "OK" HTTP response code and the file as an application/octet-stream.

  • If the job has expired: The 410 "Gone" HTTP response code. Completed jobs expire after 60 minutes.

When saving your file, use the same filename extensions you used in your URL request, for example: my_downloaded_file.csv.gz

The following example of Python code illustrates how you can download an exported report file in CSV format:


Is this helpful?


Subscribe to our developer newsletter