My api_key doesn't work

Hi, I was trying to use MPDataRetrieval to retrieve the data with my API key, but it returns 403. I’ve tried both from https://legacy.materialsproject.org/dashboar, and https://next-gen.materialsproject.org/api, but both don’t work.

api_key = 'YOUR_API_KEY'
mpdr = MPDataRetrieval(mp_api_key)
query_criteria = {'e_above_hull': {'$lte': 0.08}, 'nelements': {'$gte': 3, '$lte': 4}, 'nsites': {'$lte': 40}}
query_properties = ['material_id', 'formation_energy_per_atom', 'band_gap', 'pretty_formula', 'e_above_hull', 'elements', 'cif', 'spacegroup.number']
dataframe = mpdr.get_dataframe(
        criteria = query_criteria,
        properties = query_properties,
        )

To check if it is my api_key problem, I tried to request “'https://www.materialsproject.org/rest/v2/'tasks”, but 404 is returned. Therefore, I think it is the api_key problem?

api_key = 'YOUR_API_KEY'
base_url = 'https://www.materialsproject.org/rest/v2/'
endpoint = 'tasks'
url = base_url + endpoint
headers = {'X-API-KEY': api_key}
response = requests.get(url, headers=headers)

May anybody help me? Thank you very much!

For the first code , it returns “pymatgen.ext.matproj.MPRestError: REST query returned with error status code 403” and “pymatgen.ext.matproj.MPRestError: REST query returned with error status code 403. Content: b’{“valid_response”: false, “error”: “Invalid request method.”, “version”: {“db”: “2020_09_08”, “pymatgen”: “2022.0.8”, “rest”: “2.0”}, “created_at”: “2023-10-12T23:06:16.477742”}'”.

For the second code, “<Response [404]>”.