Hello,
I am attempting to fetch Core Web Vitals data for specific domains using the Google Chrome User Experience Report (CrUX) API, but I am encountering the following error:
Error fetching data for [domain name]: 404
This error occurs despite using a newly generated and active API key. I've tried this with several domains confirmed to be present in the CrUX dataset, but all attempts result in the same 404 error.
The environment I am running this in is Google Cloud Platform's Compute Engine. I am using Python and the requests library. I also tried different patterns of query parameters, including those without specifying metrics, but to no avail.
Here is the main part of my code:
*domain is example but I got same result.
import requests
API_KEY = 'DUMMY_ DUMMY _ DUMMY'
CRUX_API_ENDPOINT = '
https://chromeuxreport.googleapis.com/v1/records:queryRecord'
domain = "
www.amazon.com"
def get_core_web_vitals(domain: str) -> dict:
params = {
'key': API_KEY,
'url': f'https://{domain}',
'metrics': ['largest_contentful_paint', 'first_input_delay', 'cumulative_layout_shift']
}
response = requests.get(CRUX_API_ENDPOINT, params=params)
if response.status_code == 200:
return response.json()
else:
print(f'Error fetching data for {domain}: {response.status_code}')
return {}
data = get_core_web_vitals(domain)
I would greatly appreciate any advice on this issue.