Home > Enterprise >  Difficulty with receiving data from axios get request
Difficulty with receiving data from axios get request

Time:12-01

I'm running into some problems with my axios get request. I'm trying to fetch stock information using the TwelveData API. Here is my code:

const axios = require('axios');
require('dotenv').config()


const getTickerList = async() => {
    await axios.get(`https://api.twelvedata.com/stocks?apikey=${process.env.API_KEY}&symbol=AAPL&country=US`).then(response => console.log(response.data));
}

When I execute that code, I get a really strange data response that I have attached: link to pic

I would appreciate any help or advice - thanks!

I have outlined the problem above: expected something not like that.

CodePudding user response:

This is a known bug in Axios. The fix for now is to pin your Axios version to 1.1.3.

CodePudding user response:

Try this

const getTickerList = async() => {
    await axios.get(`https://api.twelvedata.com/stocks?apikey=${process.env.API_KEY}&symbol=AAPL&country=US`,
    {
        headers: {
            'Accept-Encoding': 'application/json',
        }
    }).then(response => console.log(response.data));
}

CodePudding user response:

const axios = require("axios");

const options = {
  method: 'GET',
  url: 'https://twelve-data1.p.rapidapi.com/stocks',
  params: {exchange: 'NASDAQ', format: 'json'},
  headers: {
    'X-RapidAPI-Key': 'SIGN-UP-FOR-KEY',
    'X-RapidAPI-Host': 'twelve-data1.p.rapidapi.com'
  }
};

const getTickerList = async() => {
    axios.request(options).then(function (response) {
        console.log(response.data);
    }).catch(function (error) {
        console.error(error);
    });
}
  • Related