Los encabezados de autorización (token de portador) no se agregan a las llamadas a la API
El estado es 401 No autorizado y los encabezados no se agregan a la llamada a la API.
const axios = require('axios') let token = 'eyJ0eXAiOiJOiJIUzI1NiJ9.eyJpc3MiOiJJQ00iLCJhdWQiOiJzZXNzaW9uLW1hbm' export class classname ) async getReports () { let response try { response = await axios.get(`https://urltogo/path`), { headers: { 'Content-Type' : 'application/json', Authorization : `Bearer ${token}` } } const responseObj = { url: `GET ${`https://urltogo/path`}`, status: response.status, data: response.data } if (responseObj.data.meta.count == 1) { return responseObj.data.items[0].id } } catch (error) { const errorObj = { status: error.response?.status, data: error.response?.data } throw new Error(JSON.stringify(errorObj)) } } }Obtener error
"status":401,"data":{"message":"Unauthorized, **no authorization header value**"}}datos: error.respuesta?.datos
not sure what i am missing here in the codeDebe poner las opciones como segundo argumento del método get , no después de cerrarlo.
response = await axios.get(`https://urltogo/path`, { headers: { 'Content-Type' : 'application/json', Authorization : `Bearer ${token}` } });Actualicé la respuesta de @reyno con negrita
response = await axios.get**(**`https://urltogo/path`,{ headers: { 'Content-Type' : 'application/json', 'Authorization' : `Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ`} } **)**;