Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Introduction

To export query data using APIs and obtain a CSV file, 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.

  1. Initiating 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.

  2. Download CSV API: Once the export is scheduled, this API enables you to retrieve the exported CSV file containing the queried data. It completes the export process by providing you with a downloadable link or directly fetching the 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.

Exporting query data

Method

POST

URL

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

Body

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

Response

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

Parameters

Attribute

Description

Allowed values

drivingForm

The search perspective is determined by the driving form. If left empty, it defaults to "Participant."

(For instance, when the driving form is set to "Participant," the root table becomes 'catissue_coll_prot_reg,' which is then joined with other tables. Similarly, if the driving form is set to "Specimen," the root table will be 'catissue_specimen,' which will also be joined with other tables.)

Participant, Specimen

cpId

When exporting for a single CP, include its CPID. For exporting all or multiple CPs, use a value of -1.

Integer only

aql

A valid AQL query for exporting data to a CSV file.

String

wideRowMode

  • Default value is OFF, meaning multi-valued attributes result in a single row.

  • Other permitted values are SHALLOW and DEEP. Experiment to determine which option best suits your use case.

DEEP, SHALLOW, OFF

dataFile

Handle or file ID to use for downloading the exported CSV file.

string

Completed

Boolean indicating whether the exported CSV file can be downloaded right away.

true, false

Download Exported Data File

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":"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

Below is attached a zip file, which includes the bash script along with a config file. Download the zip file.

How to run

  1. Extract the zip file.

unzip export-query-data.zip
  1. Navigate the directory.

cd export-query-data
  1. Open query-details.config file and add valid values

  2. Make the script executable.

chmod +x export-query-data.sh
  1. Run the script.

./export-query-data.sh query-details.config
  • No labels