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

String index out of range error from api service

ANSWERED

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?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

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 Answer
0 Votes

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
0 Votes