<p>When I visit the <code>cases_endpt</code> page you linked <a href="https://api.gdc.cancer.gov/cases" rel="nofollow noreferrer">directly</a> on Firefox v88, I get a filterable JSON file. Looking for &quot;type&quot; only comes up with &quot;disease_type&quot;, not sample or analyte:</p>
<pre><code>data    
 hits   
  0 
   disease_type &quot;Adenomas and Adenocarcinomas&quot;
  1 
   disease_type &quot;Ductal and Lobular Neoplasms&quot;
  2 
   disease_type &quot;Ductal and Lobular Neoplasms&quot;
  3 
   disease_type &quot;Adenomas and Adenocarcinomas&quot;
  4 
   disease_type &quot;Squamous Cell Neoplasms&quot;
  5 
   disease_type &quot;Adenomas and Adenocarcinomas&quot;
  6 
   disease_type &quot;Squamous Cell Neoplasms&quot;
  7 
   disease_type &quot;Adenomas and Adenocarcinomas&quot;
  8 
   disease_type &quot;Squamous Cell Neoplasms&quot;
  9 
   disease_type &quot;Ductal and Lobular Neoplasms&quot;
</code></pre>

CC BY-SA 4.0
2021-06-19T12:02:40.067Z
2021-06-19T12:02:40.067Z
gringer
<p>I have been trying to access metadata from the Genomic Data Commons; however, not all of the information I want is showing up in the resulting tsv file. How do I get sample type and analyte type to show up in the tsv file? I have tried altering what I pass as a field (towards the top of the code), or adding a different filter, but nothing seems to change what shows up in the tsv file. Any help is appreciated!</p>
<pre><code>import requests
import json

cases_endpt = &quot;https://api.gdc.cancer.gov/cases&quot;

# The 'fields' parameter is passed as a comma-separated string of single names.
fields = [
    &quot;sample_ids&quot;,
    &quot;submitter_sample_ids&quot;,
    &quot;files.cases.sample_ids&quot;,
    &quot;files.cases.submitter_sample_ids&quot;,
    &quot;files.cases.samples.sample_id&quot;,
    &quot;files.cases.samples.sample_type&quot;,
    &quot;files.cases.samples.sample_type_id&quot;,
    &quot;files.cases.samples.submitter_id&quot;,
    &quot;samples.sample_id&quot;,
    &quot;samples.sample_type&quot;,
    &quot;samples.sample_type_id&quot;,
    &quot;tissue_source_site.bcr_id&quot;,
    &quot;tissue_source_site.code&quot;,
    &quot;tissue_source_site.name&quot;,
    &quot;tissue_source_site.project&quot;,
    &quot;tissue_source_site.tissue_source_site_id&quot;,
    &quot;diagnoses.classification_of_tumor&quot;,
    &quot;diagnoses.tumor_stage&quot;,
    &quot;diagnoses.tumor_grade&quot;,
    &quot;files.cases.diagnoses.tumor_grade&quot;,
    &quot;files.cases.diagnoses.tumor_stage&quot;,
    &quot;files.cases.diagnoses.classification_of_tumor&quot;,
    &quot;files.cases.samples.tumor_code&quot;,
    &quot;files.cases.samples.tumor_code_id&quot;,
    &quot;files.cases.samples.tumor_descriptor&quot;,
    &quot;files.cases.samples.portions.slides.percent_tumor_cells&quot;,
    &quot;files.cases.samples.portions.slides.percent_tumor_nuclei&quot;,
    &quot;samples.tumor_code&quot;,
    &quot;samples.tumor_code_id&quot;,
    &quot;samples.tumor_descriptor&quot;,
    &quot;samples.portions.slides.percent_tumor_cells&quot;,
    &quot;samples.portions.slides.percent_tumor_nuclei&quot;,
    &quot;files.cases.samples.oct_embedded&quot;,
    &quot;samples.oct_embedded&quot;,
    &quot;files.cases.samples.intermediate_dimension&quot;,
    &quot;files.cases.samples.longest_dimension&quot;,
    &quot;files.cases.samples.shortest_dimension&quot;,
    &quot;samples.intermediate_dimension&quot;,
    &quot;samples.longest_dimension&quot;,
    &quot;samples.shortest_dimension&quot;,
    &quot;files.cases.samples.portions.is_ffpe&quot;,
    &quot;samples.is_ffpe&quot;,
    &quot;samples.portions.is_ffpe&quot;,
    &quot;files.cases.samples.pathology_report_uuid&quot;,
    &quot;samples.pathology_report_uuid&quot;,
    &quot;exposures.weight&quot;,
    &quot;files.cases.exposures.weight&quot;,
    &quot;files.cases.samples.current_weight&quot;,
    &quot;files.cases.samples.initial_weight&quot;,
    &quot;files.cases.samples.portions.weight&quot;,
    &quot;samples.current_weight&quot;,
    &quot;samples.initial_weight&quot;,
    &quot;samples.portions.weight&quot;,
    &quot;files.cases.samples.composition&quot;,
    &quot;samples.composition&quot;,
    &quot;files.cases.samples.freezing_method&quot;,
    &quot;files.cases.samples.time_between_clamping_and_freezing&quot;,
    &quot;files.cases.samples.time_between_excision_and_freezing&quot;,
    &quot;samples.freezing_method&quot;,
    &quot;samples.time_between_clamping_and_freezing&quot;,
    &quot;samples.time_between_excision_and_freezing&quot;,
    &quot;files.cases.samples.days_to_sample_procurement&quot;,
    &quot;samples.days_to_sample_procurement&quot;,
    &quot;files.cases.samples.preservation_method&quot;,
    &quot;samples.preservation_method&quot;,
    &quot;samples.days_to_collection&quot;,
    &quot;files.cases.samples.days_to_collection&quot;,
    &quot;files.cases.samples.portions.analytes.analyte_type&quot;,
    &quot;files.cases.samples.portions.analytes.analyte_type_id&quot;,
    &quot;files.cases.samples.portions.analytes.aliquots.analyte_type&quot;,
    &quot;files.cases.samples.portions.analytes.aliquots.analyte_type_id&quot;,
    &quot;samples.portions.analytes.analyte_type&quot;,
    &quot;samples.portions.analytes.analyte_type_id&quot;,
    &quot;samples.portions.analytes.aliquots.analyte_type&quot;,
    &quot;samples.portions.analytes.aliquots.analyte_type_id&quot;,
    ]

fields = ','.join(fields)

filters = {
    &quot;op&quot;: &quot;in&quot;,
    &quot;content&quot;: {&quot;field&quot;: &quot;cases.project.project_id&quot;,
                &quot;value&quot;: [&quot;TCGA-BRCA&quot;]},
}

params = {&quot;filters&quot;: json.dumps(filters),
          &quot;format&quot;: &quot;TSV&quot;,
          &quot;size&quot;: &quot;12000&quot;}

response = requests.get(cases_endpt, params=params)
content = str(response.content, &quot;utf-8&quot;)

with open(&quot;addingsampletype5.tsv&quot;, &quot;w&quot;) as file:
    file.write(content)
</code></pre>

<data-retrieval><api><python>
querying gdc metadata issues with resulting fields
# querying gdc metadata issues with resulting fields

(Asked by: username_0 on 2021-06-17)

I have been trying to access metadata from the Genomic Data Commons; however, not all of the information I want is showing up in the resulting tsv file. How do I get sample type and analyte type to show up in the tsv file? I have tried altering what I pass as a field (towards the top of the code), or adding a different filter, but nothing seems to change what shows up in the tsv file. Any help is appreciated!
import requests
import json

cases_endpt = "https://api.gdc.cancer.gov/cases"

# The 'fields' parameter is passed as a comma-separated string of single names.
fields = [
    "sample_ids",
    "submitter_sample_ids",
    "files.cases.sample_ids",
    "files.cases.submitter_sample_ids",
    "files.cases.samples.sample_id",
    "files.cases.samples.sample_type",
    "files.cases.samples.sample_type_id",
    "files.cases.samples.submitter_id",
    "samples.sample_id",
    "samples.sample_type",
    "samples.sample_type_id",
    "tissue_source_site.bcr_id",
    "tissue_source_site.code",
    "tissue_source_site.name",
    "tissue_source_site.project",
    "tissue_source_site.tissue_source_site_id",
    "diagnoses.classification_of_tumor",
    "diagnoses.tumor_stage",
    "diagnoses.tumor_grade",
    "files.cases.diagnoses.tumor_grade",
    "files.cases.diagnoses.tumor_stage",
    "files.cases.diagnoses.classification_of_tumor",
    "files.cases.samples.tumor_code",
    "files.cases.samples.tumor_code_id",
    "files.cases.samples.tumor_descriptor",
    "files.cases.samples.portions.slides.percent_tumor_cells",
    "files.cases.samples.portions.slides.percent_tumor_nuclei",
    "samples.tumor_code",
    "samples.tumor_code_id",
    "samples.tumor_descriptor",
    "samples.portions.slides.percent_tumor_cells",
    "samples.portions.slides.percent_tumor_nuclei",
    "files.cases.samples.oct_embedded",
    "samples.oct_embedded",
    "files.cases.samples.intermediate_dimension",
    "files.cases.samples.longest_dimension",
    "files.cases.samples.shortest_dimension",
    "samples.intermediate_dimension",
    "samples.longest_dimension",
    "samples.shortest_dimension",
    "files.cases.samples.portions.is_ffpe",
    "samples.is_ffpe",
    "samples.portions.is_ffpe",
    "files.cases.samples.pathology_report_uuid",
    "samples.pathology_report_uuid",
    "exposures.weight",
    "files.cases.exposures.weight",
    "files.cases.samples.current_weight",
    "files.cases.samples.initial_weight",
    "files.cases.samples.portions.weight",
    "samples.current_weight",
    "samples.initial_weight",
    "samples.portions.weight",
    "files.cases.samples.composition",
    "samples.composition",
    "files.cases.samples.freezing_method",
    "files.cases.samples.time_between_clamping_and_freezing",
    "files.cases.samples.time_between_excision_and_freezing",
    "samples.freezing_method",
    "samples.time_between_clamping_and_freezing",
    "samples.time_between_excision_and_freezing",
    "files.cases.samples.days_to_sample_procurement",
    "samples.days_to_sample_procurement",
    "files.cases.samples.preservation_method",
    "samples.preservation_method",
    "samples.days_to_collection",
    "files.cases.samples.days_to_collection",
    "files.cases.samples.portions.analytes.analyte_type",
    "files.cases.samples.portions.analytes.analyte_type_id",
    "files.cases.samples.portions.analytes.aliquots.analyte_type",
    "files.cases.samples.portions.analytes.aliquots.analyte_type_id",
    "samples.portions.analytes.analyte_type",
    "samples.portions.analytes.analyte_type_id",
    "samples.portions.analytes.aliquots.analyte_type",
    "samples.portions.analytes.aliquots.analyte_type_id",
    ]

fields = ','.join(fields)

filters = {
    "op": "in",
    "content": {"field": "cases.project.project_id",
                "value": ["TCGA-BRCA"]},
}

params = {"filters": json.dumps(filters),
          "format": "TSV",
          "size": "12000"}

response = requests.get(cases_endpt, params=params)
content = str(response.content, "utf-8")

with open("addingsampletype5.tsv", "w") as file:
    file.write(content)

**Tags:** data-retrieval, api, python

---

## 1 answers

### Answer by username_1 on 2021-06-19. Score: 0

When I visit the cases_endpt page you linked directly on Firefox v88, I get a filterable JSON file. Looking for "type" only comes up with "disease_type", not sample or analyte:
data    
 hits   
  0 
   disease_type "Adenomas and Adenocarcinomas"
  1 
   disease_type "Ductal and Lobular Neoplasms"
  2 
   disease_type "Ductal and Lobular Neoplasms"
  3 
   disease_type "Adenomas and Adenocarcinomas"
  4 
   disease_type "Squamous Cell Neoplasms"
  5 
   disease_type "Adenomas and Adenocarcinomas"
  6 
   disease_type "Squamous Cell Neoplasms"
  7 
   disease_type "Adenomas and Adenocarcinomas"
  8 
   disease_type "Squamous Cell Neoplasms"
  9 
   disease_type "Ductal and Lobular Neoplasms"


---

