# How to use an API call to download FastQ files from BaseSpace

BaseSpace API calls can be used to download FastQ files from BaseSpace. This approach can be adopted to download other file types as well.

The **first step** in using BaseSpace API is to generate an **access token** - the easiest way to do thisis using BaseSpace CLI.

1. Authenticate BaseSpace CLI.
2. Obtain the authorization/access token from the **CLI config file** - located in \~/.basespace/{config name}.cfg - default.cfg is the default config.

The following API call is used to **download files** from BaseSpace.

curl -X 'GET' -H 'Authorization: Bearer {Access Token}' '[https://api.basespace.illumina.com/v2/files/{File ID}/content](https://api.basespace.illumina.com/v2/files/27385661879/content)' -LOJ

The **File ID** for FastQ files is obtained from the **dataset ID** using the following endpoint. GET /datasets/{Dataset ID}/files.

Now, these API calls can be **tied together** using a JSON-parsing tool such as **jq** to download FastQ files associated with projects, runs.

For example, below is a command that can be used to download all **FastQs associated with a run**.

curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' -H 'Content-Type: application/json' '[https://api.basespace.illumina.com/v2/datasets?InputRuns=**{Run ID}**\&Limit=200\&Offset=0](https://api.basespace.illumina.com/v2/datasets?InputRuns=245379166\&Limit=200\&Offset=0)' | jq '.Items | .\[] | select(.DatasetType.Id | test("fastq")) | .HrefFiles' | xargs -I @ curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' -H 'Content-Type: application/json' @ | jq '.Items | .\[].HrefContent' | xargs -I $ curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' $ -LOJ

Similarly, the following command can be used to download all **FastQs from a project**.

curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' -H 'Content-Type: application/json' '[https://api.basespace.illumina.com/v2/datasets?ProjectID=**{Project ID}**\&Limit=200\&Offset=0](https://api.basespace.illumina.com/v2/datasets?InputRuns=245379166\&Limit=200\&Offset=0)' | jq '.Items | .\[] | select(.DatasetType.Id | test("fastq")) | .HrefFiles' | xargs -I @ curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' -H 'Content-Type: application/json' @ | jq '.Items | .\[].HrefContent' | xargs -I $ curl -X 'GET' -H 'Authorization: Bearer **{Access Token}**' $ -LOJ

Further filtering can be implemented using different features of jq. Alternatively, use BaseSpace CLI to download FastQ files in a customized fashion.

More information about BaseSpace API endpoints can be found [here](https://developer.basespace.illumina.com/docs/content/documentation/rest-api/api-reference).

\
\
\ <br>

|                                                                                                                                                                                                                                                                                                                                                                 |
| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| *For any feedback or questions regarding this article (Illumina Knowledge Article #7506), contact Illumina Technical Support* [*techsupport@illumina.com*](mailto:techsupport@illumina.com?subject=Question%2FFeedback%20Regarding%20Illumina%20Knowledge%20Article%20#000007506%20-%20Software%20\&body=Dear%20Illumina%20Technical%20Support,%0D%0A%0D%0A)*.* |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledge.illumina.com/software/cloud-software/software-cloud-software-faq-list/000007506.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
