1

I need to create an access token and use him to get infos from an api in multiples pages. I made the access token by this code


(async () => {
    const clientId = 'XXXXXXXXXXXX'
    const clientSecret = 'XXXXXXXXXXXXXXXXXX'
    const encodedData = Buffer.from(clientId + ':' + clientSecret).toString('base64');
    var accessToken = ''
    var response = {}
    console.log('Encoded data: ' + encodedData)
    console.log('authorization', 'Basic ' + encodedData)
    // POST request using axios with async/await
    try { 
        response = await axios.post('XXXXXXXXXXXXXXXXXXXXXXXXXXXX', {}, {
            headers: { 'Authorization': 'Basic ' + encodedData }
        });
        console.log(response.status, response.statusText, response.data.access_token);
        accessToken = response.data.access_token;
    } catch(error) {
        console.log('XXXXXXXXXXXXXXXXXXXXXXXXXXXX' , error.message);
    }

how can i use him in the pages to get the api data ?

0 Answers0