How to get JSON response using nodejs & axios when calling an Alphavantage endpoint?

53 Views Asked by At

I have a simple node js file where I query one alphvantage endpoint and console.log the response. Here is the code:

const axios = require('axios');

const API_KEY = 'SOME_SECRET_API_KEY';

const config = {
  headers: {
    'Content-Type': 'application/json',
    Accept: 'application/json',
    'Accept-Encoding': 'gzip, deflate, br'
  },
};

const functionName = 'TIME_SERIES_INTRADAY_EXTENDED';
const ticker = 'IBM';

axios.get(
        `https://www.alphavantage.co/query?function=${functionName}&symbol=${ticker}&interval=5min&apikey=${API_KEY}`,
        config,
      ).then((response) => console.log(response.data, "\n", typeof response.data));

In the documentation it says I should get the response in a JSON format which I do when I use postman to call the same endpoint, but here, in nodejs, I get the response as a string that looks like a CSV. Any idea why and how can I ask for the JSON response instead?

0

There are 0 best solutions below