I am trying to get the data from mixpanel into my react project. I have below code. But I am getting unauthorized error. can someone help me with the call
const API_SECRET = 'api secret';
const API_KEY = 'project token';
const apiUrl = 'https://data.mixpanel.com/api/2.0/export?from_date=2023-11-05&to_date=2023-11-08'
fetch(apiUrl, {
mode: 'no-cors',
headers: {
accept: 'application/json',
Authorization: `Basic ${btoa(`${API_KEY}:${API_SECRET}`)}`,
}
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(data => {
// Handle the data from the API response
console.log('API Response:', data);
})
.catch(error => {
// Handle errors here
console.error('Error:', error);
});