08-12-2015 09:22
08-12-2015 09:22
I'm receiving this error from the fitbit api web service when making a post request to retrieve the user's access token and refresh token. Is there something I'm doing wrong or something missing? I'm using a javascript based ajax api to make the call from my node server. The set methods just adds the header info and the query methods add the query params:
request
.post(fitbitApiSite + '/oauth2/token')
.set('Authorization', 'Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=')
.set('Content-Type', 'application/x-www-form-urlencoded')
.query({client_id: clientId})
.query({grant_type: 'authorization_code'})
.query({redirect_uri: website + '/api/fitbit/callback'})
.query({code: authCode})
.end(function(error, result) {
if(error) {
console.log('error from token request: ' + error);
} else {
console.log(result);
}
});The raw error is (I've modifed the codes with placeholders):
error:
{ [Error: cannot POST /oauth2/token?client_id=<clientId>&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Ffitbit%2Fcallback&code=<user-auth-code> (500)]
status: 500,
text: '{"errors":[{"errorType":"request","fieldName":"n/a","message":"String index out of range: -1"}],"success":false}',
method: 'POST',
path: '/oauth2/token?client_id=<clientId>&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Ffitbit%2Fcallback&code=<user-auth-code>' },Do you know what is causing this error?
Answered! Go to the Best Answer.
Best Answer08-12-2015 09:58 - edited 08-12-2015 10:16
08-12-2015 09:58 - edited 08-12-2015 10:16
Ok, I think I know what it is. I missed processing the authorization header. I'll give that a try.
Edit: that was the issue.
Best Answer08-12-2015 09:58 - edited 08-12-2015 10:16
08-12-2015 09:58 - edited 08-12-2015 10:16
Ok, I think I know what it is. I missed processing the authorization header. I'll give that a try.
Edit: that was the issue.
Best Answer01-21-2016 15:58
01-21-2016 15:58
Ive been getting a similar error from sleep when I call from a time when there was no data? but not at other times most of the time? Its all very mysterious.
this is where it seems to be failing: "sleep=output["sleep"][0]["minuteData"]"
any advice? note that this is intermittant and I can most of the time get the data with no problems
Best Answer