def METHOD_NAME(
    sorted_keys: ZoneKey,
    session: Optional[Session],
    target_datetime: Optional[datetime],
    logger: Logger,
) -> dict:
    """
    Helper function to fetch data from the API.
    """
    ses = session or Session()
    if target_datetime and target_datetime.tzinfo:
        # Data source doesn't support timezone aware
        # datetimes.
        target_datetime = target_datetime.replace(tzinfo=None)
    price_area = EXCHANGE_MAPPING[sorted_keys]["priceArea"]
    params = {
        "limit": 500,
        "filter": '{"PriceArea":"DK1"}'
        if price_area == "DK1"
        else '{"PriceArea":"DK2"}',
        "start": target_datetime.strftime("%Y-%m-%d") if target_datetime else None,
        "end": (target_datetime + timedelta(days=1)).strftime("%Y-%m-%d")
        if target_datetime
        else None,
    }
    response: Response = ses.get(
        "https://api.energidataservice.dk/dataset/ElectricityProdex5MinRealtime",
        params=params,
    )
    if response.ok:
        data = response.json()
        if data["total"] == 0:
            raise ParserException(
                parser="DK.py",
                zone_key=sorted_keys,
                message=f"No exchange data was returned for {target_datetime.date() or datetime.now().date()}",
            )
        else:
            return data
    else:
        raise ParserException(
            parser="DK.py",
            zone_key=sorted_keys,
            message=f"No exchange data was returned for {target_datetime.date() or datetime.now().date()}",
        )