Issue
I'm trying to imitate the effect of the following curl command in NodeJS, but can't quite seem to get it to work. Any help would be appreciated.
curl href="https://url.com/rest/scripts" rel="nofollow">https://url.com/rest/scripts -H "Authorization: bearer $TOKEN"
Assuming I already have the contents of $TOKEN stored in var auth, what would be the correct format for a request, synchronous or otherwise, for mimicking the above curl command?
My current attempt looks like this, but doesn't seem to work at all:
var resData = request('GET', reqURL, auth);
EDIT: Solved, but I feel I should point out the above was using 'sync-request', hence how it was possible to store the result as a variable.
Solution
var request = require('request');
request({
method: 'GET',
url: reqURL,
headers: 'Authorization: bearer ' + auth, //assuming var auth = $token
json: true
}, function(err, response, body){
//Do whatever you want to here
});
Answered By - SKY Answer Checked By - Marilyn (WPSolving Volunteer)