Hi Team,
I am using axios to connect to Metabase API to I can get JSON response for question id. I am using following code but it doesn’t work while getting JSON response. I am able to get the token but not able to JSON response for particular question id.
const axios = require(‘axios’);
// Call Metabase rest API to get token
axios.post(‘http://localhost:3000/api/session’,
{
username: ‘uname’,
password: ‘pwd’
})
.then(function (response) {
console.log('The token is : ’ + response.data.id);
axios.defaults.headers.post[‘Content-Type’] = ‘application/json’;
axios.defaults.headers.post[‘X-Metabase-Session’] = response.data.id;
axios.post(‘http://localhost:3000/api/card/39/query/json’)
.then((res) => {
console.log("The Metabase API to get JSON : “, res);
})
.catch((err) => {
console.log(” The error occurred while get Metabase JSON response : ", err);
})
})
.catch(function (error) {
console.log(error);
});
I either get 401 unauthorized or now I am getting status code 500
04-22 18:10:24 ERROR middleware.log :: POST /api/card/39/query/json 500 3.1 ms (3 DB calls)
{:message nil, :type java.lang.NullPointerException, :stacktrace [nil]}