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

# Example query 2: Count samples connected to a case

<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 2: count samples...

To count the number of samples connected to a specific case, use the following query. This example uses a case with the case ID '0004D251-3F70-4395-B175-C94C2F5B1B81' .

\##Request

[block:code]
{
  "codes": [
    {
      "code": "POST /datasets/tcga/v0/query/total HTTP/1.1\nHost: cgc-datasets-api.sbgenomics.com\nX-SBG-Auth-Token: 3210a98c1db9304ea9d9273156740f74",
      "language": "http",
      "name": "Count number of samples connected to a case"
    }
  ]
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "{\n    \"entity\": \"samples\",\n    \"hasCase\": \"0004D251-123A-45B6-B175-C94C2F5B1B81\"\n}",
      "language": "json",
      "name": "Request body"
    }
  ]
}
[/block]

\##Response body
The response shows the total number of matching samples.

[block:code]
{
  "codes": [
    {
      "code": "{\n  \"total\": 2\n}",
      "language": "json",
      "name": ""
    }
  ]
}
[/block]