Skip to main content

hi

i have a question about using Amplitude Dashboard Rest API 

i want to get the data in my web project (Its using react.js, typescript ...)

So i used Fetch and also used Axios for Dashboard Rest APi

When i used  Axios, it have CORS error ( I am not using a VPN )

When i used  Fetch, it have 401 error, but same code with same key in node.js is woking.

So, could i call dashboard REST API in my web project ?

const CREDENTIALS = `${AMPLITUDE_API_KEY}:${AMPLITUDE_SECRET_KEY}`;
const ENDPOINT_URL = 'https://amplitude.com/api/2/funnels';

export async function request(eventKeys, options) {
const encodedCredentials = window.btoa(CREDENTIALS);// credentials to base64
const params = new URLSearchParams();

eventKeys.forEach((key) => params.append('e', JSON.stringify({ event_type: key })));
params.append('start', options?.start ?? dayjs().subtract(1, 'month').format('YYYYMMDD'));
params.append('end', options?.end ?? dayjs().format('YYYYMMDD'));

console.log(`${ENDPOINT_URL}?${params.toString()}`);

const response = await fetch(`${ENDPOINT_URL}?${params.toString()}`, {
method: 'GET',
mode: 'no-cors',
headers: {
Authorization: `Basic ${encodedCredentials}`,
},
});

console.log('sresponse]', response.text());

return response.text();
}

 

Be the first to reply!

Reply