I am attempting to do a GET request to an external API using node-fetch. When I run the code, I get the below error:
UnhandledPromiseRejectionWarning: TypeError: Bearer [api key] is not a legal HTTP header value
The Bearer key is in JWT format and it is located in an external config file for privacy.
Here is my code:
let api_config = require('./api_config.json');
const fetch = require("node-fetch");
fetch(api_config.API_Domain + api_config.SUBJECTCODES_OPTIONS_URI, {
method: 'GET',
headers: {
'Authorization': "Bearer " + api_config.API_Key,
"Content-type": "application/json",
"Accept": "application/json",
}
}).then(res => res.json())
.then(json => console.log(json))