Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Make a GET request to API

I am using node.js with express, and I am able to login via OAuth2, and recieve a token back. I am then logged in to my app with the proper auth credentials, and I would like to make a simple GET request to the API, but the request I make comes back with:

 

"GET https://api.fitbit.com/1/foods/30414.json 401 (Unauthorized)"

 

I have tried multiple different API GET requests, and they all come back with the same 401 error. 

 

Could you possibly give me a working example of a GET request written in javascript? I cannot figure out what headers or parameters I need to attach to my GET request in order to be granted access. 

 

I have tried a few iterations of:

 

$scope.getFitBitProfile = function (){
$http.get('https://api.fitbit.com/1/foods/30414.json',{
Authorization: 'Bearer <access token I was given back from signing in>'
}).success( function (data) {
console.log(data);
})
.error( function () {
console.log('Search error');
});
}

 

and it just hits the console.log('Search error') everytime. Any advice?

Best Answer
0 Votes
1 REPLY 1

If you can log in and get an access token but get a 401 when requesting resources it sounds like you need to specify the scope required for the end point you are looking for when getting a request token. Each end point now (for OAuth2) needs to have the specified scope authorized by the user -

https://dev.fitbit.com/docs/oauth2/#scope

 

Best Answer
0 Votes