---
agentTools:
  projectIndex: https://docs.cancergenomicscloud.org/llms.txt
---

# Example query 5: Complex example for filtering TCGA data

<a href="query-datasets" style="color:#132c56">QUERY DATASETS</a> > <a href="about-the-datasets-api" style="color:#132c56">About the Datasets API</a> > <a href="query-via-the-datasets-api" style="color:#132c56">Query via the Datasets API</a> > Example query 5: Complex example...

Complex queries are well-suited to the Datasets API.

For instance, use the following query to obtain all cases that have a sample with a Primary tumor sample type of portion number 11, a new tumor anatomic site of the liver or pancreas, and a new tumor event type containing the word "recurrence".

\##Request

[block:code]
{
  "codes": [
    {
      "code": "POST /datasets/tcga/v0/query HTTP/1.1\nHost: cgc-datasets-api.sbgenomics.com\nX-SBG-Auth-Token: 3210a98c1db9304ea9d9273156740f74",
      "language": "http",
      "name": "Complex query"
    }
  ]
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "{\n    \"entity\": \"cases\",\n    \"hasSample\": {\n        \"hasSampleType\": \"Primary Tumor\",\n        \"hasPortion\": {\n            \"hasPortionNumber\":11\n            }\n        },\n    \"hasNewTumorEvent\": {\n        \"hasNewTumorAnatomicSite\": [\"Liver\", \"Pancrease\"],\n        \"hasNewTumorEventType\":{\n            \"filter\": {\n                \"contains\":\"Recurrence\"\n            }\n        }\n    }\n}",
      "language": "json",
      "name": "Request body"
    }
  ]
}
[/block]

\##Response body

This request returns the response below. Note that it contains 79 cases objects: one for each case matching the query above.

[block:code]
{
  "codes": [
    {
      "code": "{\n  \"_embedded\": {\n    \"cases\": [\n      {\n        \"label\": \"0304D251-123A-456B-B175-C94C2F5B1B81\",\n        \"id\": \"0304D251-123A-456B-B175-C94C2F5B1B81\",\n        \"_links\": {\n          \"self\": {\n            \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/0304D251-123A-456B-B175-C94C2F5B1B81\"\n          }\n        }\n      },\n      {\n        \"label\": \"001867AA-36D0-463F-7890-DEC7043B4F2E\",\n        \"id\": \"001867AA-36D0-463F-7890-DEC7043B4F2E\",\n        \"_links\": {\n          \"self\": {\n            \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/001867AA-36D0-463F-7890-DEC7043B4F2E\"\n          }\n        }\n      },\n      {\n        \"label\": \"03DF105E-123A-4577-BFDB-9634758D778E\",\n        \"id\": \"03DF105E-123A-4577-BFDB-9634758D778E\",\n        \"_links\": {\n          \"self\": {\n            \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/03DF105E-123A-4577-BFDB-9634758D778E\"\n          }\n        }\n      },\n    <snip>\n    ]\n  },\n  \"count\": 79\n}",
      "language": "json"
    }
  ]
}
[/block]

For each case returned, the response lists:

* Its TCGA `label`
* Its TCGA `id`
* Its `href`: this is a path that can be used to obtain full information about the case.

\##Secondary request
Use a `GET` request to the `href` path obtain this information, as shown below.

[block:code]
{
  "codes": [
    {
      "code": "GET /datasets/tcga/v0/cases/0004D251-3F70-4395-B175-C94C2F5B1B81 HTTP/1.1\nHost: cgc-datasets-api.sbgenomics.com\nX-SBG-Auth-Token: 3210a98c1db9304ea9d9273156740f74",
      "language": "http",
      "name": "Secondary request"
    }
  ]
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "{\n  \"hasNewTumorEventAfterInitialTreatment\": \"YES\",\n  \"hasPriorDiagnosis\": \"No\",\n  \"hasPathologicT\": \"T1\",\n  \"hasIcdO3Site\": \"C22.0\",\n  \"hasDaysToLastFollowUp\": 2405,\n  \"hasInvestigation\": \"TCGA-LIHC\",\n  \"hasGender\": \"MALE\",\n  \"hasYearOfDiagnosis\": 2007,\n  \"hasID\": \"TCGA-DD-AAVP\",\n  \"hasProgram\": \"TCGA\",\n  \"hasAgeAtDiagnosis\": 48,\n  \"hasEthnicity\": \"NOT HISPANIC OR LATINO\",\n  \"hasPathologicN\": \"N0\",\n  \"hasPathologicStage\": \"Stage I\",\n  \"hasPrimarySite\": \"Liver\",\n  \"hasVitalStatus\": \"Alive\",\n  \"_links\": {\n    \"hasNewTumorEvent\": {\n      \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/0304D251-123A-456B-B175-C94C2F5B1B81/new_tumor_events\"\n    },\n    \"self\": {\n      \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/0304D251-123A-456B-B175-C94C2F5B1B81\"\n    },\n    \"hasSample\": {\n      \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/0304D251-123A-456B-B175-C94C2F5B1B81/samples\"\n    },\n    \"hasFile\": {\n      \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/cases/0304D251-123A-456B-B175-C94C2F5B1B81/files\"\n    }\n  },\n  \"hasBatchNumber\": \"425\",\n  \"label\": \"0304D251-123A-456B-B175-C94C2F5B1B81\",\n  \"hasHistologicalDiagnosis\": \"Hepatocellular Carcinoma\",\n  \"hasRace\": \"ASIAN\",\n  \"hasIcdO3Histology\": \"8170/3\",\n  \"hasTumorStatus\": \"TUMOR FREE\",\n  \"id\": \"0304D251-123A-456B-B175-C94C2F5B1B81\",\n  \"hasIcd10\": \"C22.0\",\n  \"hasPerformanceStatusScoreECOG\": \"0\",\n  \"hasDiseaseType\": \"Liver Hepatocellular Carcinoma\"\n}",
      "language": "json",
      "name": "Response body"
    }
  ]
}
[/block]