import requests


def connect_to_endpoint(url, headers, params, next_token=None) -> dict:
    """
    The GET request of the API reponse

    Parameters
    ----------
    url : str
        The URL end point that is conected too
    headers : dict
        The authorisation token {"Authorization": f"Bearer {bearer_token}"}
    params : dict
        The query payload that the API requests
    next_token : str/None, optional
        DESCRIPTION. The default is None. But can be used to scroll through
        the reponses if the API has more matches than the maximum number of
        results returned

    Returns
    -------
    response.json() : dict
        The response resposne of the API
    """
    params["next_token"] = next_token
    response = requests.request("GET", url, headers=headers, params=params)
    if response.status_code != 200:
        print("Endpoint Response Code: " + str(response.status_code))
        raise Exception(response.status_code, response.text)
    return response.json()