2

ok so i'm trying to make an api call using netlify functions and if i try calling another api that does not require headers it works perfectly but when i include headers the promise returns as 'undefined'

const axios = require("axios");

exports.handler = async function (event, context) {
 
   const { id } = event.queryStringParameters;
   const url = `https://youtube-mp36.p.rapidapi.com/dl?id=${id}`
   try {
     const {data} = axios.get(url, {
       headers: {
        "x-rapidapi-host": "youtube-mp36.p.rapidapi.com",
        "x-rapidapi-key": `${process.env.REACT_APP_RAPID_KEY}`
        }
      });
      console.log(data)
     return {
       statusCode: 200,
       body: JSON.stringify(data),
     };
   } catch (err) {
       const {statusCode, statusText, headers, data} = err.response;
     return {
       statusCode: 500,
       body: JSON.stringify({ statusCode, statusText, headers, data }),
     };
   }
 };

this is my code so far any help would honestly be appreciated

maesstro
  • 49
  • 7

0 Answers0