import requests
import logging


def get_project_name(ID, endpoint_api_key=None, endpoint=None):
    """
    Get the unique project name given the project id
    :param ID: project id
    :return: project name
    """
    url_format = "{}/admin/projects/{}"
    headers = {"x-api-key": endpoint_api_key}
    res = requests.get(url_format.format(endpoint, ID), headers=headers)
    if res.status_code == 200:
        records = res.json()
        return records["name"]
    else:
        logging.error("Failed to query project `{}`. Error: {}".format(ID, res.json()))
        return None