import requests


def get_download_id(pql_query: str,
                    datatype: str = "ssm",
                    output_format: str = "TSV") -> str:
    """
    Calls an ICGC Data Portal API to retrieve a download ID for the dataset
    specified by a PQL query, a data type, and an output format.

    :param pql_query: PQL query to retrieve the dataset of interest.
    :param datatype: data types e.g., "ssm" for simple somatic mutation,
        "donor" for clinical dataset, "cnsm" for copy number somatic mutation,
        etc.
    :param output_format: output data format. Supported formats: ["json", "TSV"].
    :return: a download ID
    """
    info = f"[{{\"key\":\"{datatype}\", \"value\":\"{output_format}\"}}]"
    url = f"https://dcc.icgc.org/api/v1/download/submitPQL?pql={pql_query}&info={info}"

    response = requests.get(url)
    if response.status_code != 200:
        raise IOError(f"GET {url} resulted in status code {response.status_code}")

    return response.json()["downloadId"]