Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
stylenone

Introduction

To export query data using APIs and obtain a CSV file, a A two-step process is required . First, you'll utilize an API to initiate the query export, and then another API to download the resulting CSV file.

...

to export query data as CSV using APIs.

  1. Run query export API: This API initiates the export process. It allows you to specify the query data you want to export and sets up the necessary parameters for the export operation.Download CSV API: Once the export is scheduled, this AQL and other parameters. The query is run in the background and might take a few seconds or minutes to run.

(Steps to get a query AQL: https://openspecimen.atlassian.net/l/cp/DpHj1PNV)

  1. Download CSV: This API enables you to retrieve the

...

  1. CSV file

...

We've provided a sample code for utilizing these APIs daily. By examining this code, you can seamlessly integrate it into your preferred programming language.

...

  1. . Since the query might still be running, you will have to run this in a loop.

See the example code below.

Exporting Query Data

Method

POST

URL

http[s]://<server_url>/rest/ng/query/export

Body

Code Block
{
    "drivingForm": "<DRIVING_FORM>",
    "cpId": <CP_ID>,
    "aql": "<AQL>",
    "wideRowMode": "<DEEP/SHALLOW/OFF>"
}

Response

Code Block
{
  "dataFile": "query_0_61e59bc2-9350-47db-9af8-a1e7a3b65bc2",
  "completed": false
}

...

Method

GET

URL

http[s]://<server_url>rest/ng/query/export?fileId=<dataFile>

Response

Case 1:

When export data file is not ready, you will get HTTP response code 400 with the below message.

Code Block
[
  {
    "code":"QUERY_EXPORT_DATA_IN_PROGRESS",
    "message":"The query result data export is in progress. Retry downloading the file after some time."
  }
]

Case 2:

When the exported data file is ready, you will receive an HTTP response code 200 along with the ZIP binary stream included in the response body.

Sample

...

Code

Attached zip file , which includes the bash a shell script along with a config file. Download the zip fileThis is for reference; you can use similar logic in the programming language of your choice.

View file
nameexport-query-data.zip

...