Reputation:
I'm working on an API that lets me test my request string online and gives me a curl
statement (so far pretty standard).
The issue is that I can't put that curl into a Node.js code.
Here's the curl:
curl -X GET --header "Accept: application/json" --header "Authorization: Bearer <my_key_here>" "https://api.<api_name>.com/stations?limit=20&searchstring=cancun*"
I tried to use Postman
to parse that url, but no success.
The company doesn't provide a module (to my knowledge) that I can call from the Node.js script.
I'm following the Node.js requests
page for my .js file.
https://nodejs.org/api/http.html#http_http_request_options_callback
var request = require('request');
request({
url: 'https://api.<api_name>.com/stations',
headers: {
'Accept': application/json,
'Authorization: Bearer': <my_key>
}
Upvotes: 0
Views: 141
Reputation: 198388
'Authorization: Bearer': <my_key>`
does the wrong thing. The header name (and thus the property name) must be Authorization
, and Bearer ....
should be the value. Thus:
'Authorization': 'Bearer <my_key_as_a_string>'
or
'Authorization': 'Bearer ' + my_key_as_a_variable
Upvotes: 2