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

Fitbit integration with servicenow giving HTTP Error 401 - Unauthorized error

I am trying to integrate fitbit with servicenow but getting 

HTTP Error 401 - Unauthorized

error while getting the OAuth token please let me what could be the issue here. 

Best Answer
8 REPLIES 8

Hi @shugufta 

 

Would you please provide the endpoint and headers that you're executing when getting the 401 error.   Please do not include any sensitive data like auth codes, tokens, client ids, secrets, etc.

 

Best,

Gordon

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer

Hi Gordon,

Once I click the "https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=clientID&redirect_uri=https://dev63919.service-now.com/oauth_redirect.do&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight"  link, it gives below error.

Your OAuth redirect failed. Please check if the redirect URL setup in your OAuth configuration matches your ServiceNow instance URL.

Also the response_type=code is not getting generated.

 

Kindly suggest on how we can get the code.

 

Thanks & Regards,

Shugufta.

 

Best Answer

Hi @shugufta 

 

Thank you.   Try specifying your redirect URL as "https%3A%2F%2Fdev63919.service-now.com%2Foauth_redirect.do"

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Hi @Gordon-C 

 

This is the redirect URL https://dev63919.service-now.com/oauth_redirect.do

Best Answer
0 Votes

In your code, please specify the redirect URL as https%3A%2F%2Fdev63919.service-now.com%2Foauth_redirect.do instead of https://dev63919.service-now.com/oauth_redirect.do

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes

Even then I am redirected to same page. When I test getting below response

 

 {"success":false,"errors":[{"errorType":"invalid_token","message":"Access token invalid: null. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}]}

Best Answer

My main issue is it is not generating the code and giving me the response as below. I have given response_type=code here

{"errors":[{"errorType":"invalid_request","message":"Missing parameters: code Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}

Best Answer
0 Votes

Hi @shugufta 

 

It seems you have several errors here, and we should address them one at a time.  I'm not sure if your first error not being resolved is resulting in the other errors being generated.

 

I believe the first problem is when executing https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=clientID&redirect_uri=https://d... you receive the error 

Your OAuth redirect failed. Please check if the redirect URL setup in your OAuth configuration matches your ServiceNow instance URL.

 

I believe this is because your application need to specify the redirect URL as redirect URL as https%3A%2F%2Fdev63919.service-now.com%2Foauth_redirect.do instead ofhttps://dev63919.service-now.com/oauth_redirect.do.   However, the redirect URL in the dev.fitbit.com application configuration needs to be https://dev63919.service-now.com/oauth_redirect.do.

 

Once the user redirects back to your application, the redirect URL will have an authorization code.   

 

ex. https://www.exampleapp.com/callback?code=6ec38fd5d19a5a3f85a021f673e15ae04e9293#_=_

 

You need to swap out the code for the access token.

 

example

POST https://api.fitbit.com/oauth2/token

Authorization: Basic <basic_token>

clientId=<client_id>&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fwww.exampleapp.com%2Fcallback"

&code=6ec38fd5d19a5a3f85a021f673e15ae04e9293

 

The response should provide you with the access_token.   The OAuth 2.0 Tutorial can walk you through this process using your application settings.  See https://dev.fitbit.com/build/reference/web-api/troubleshooting-guide/debugging-tools/#oauth-2-0-tuto....

 

If you're doing these steps as I've described, please provide the URL and error message that you're receiving.   

 

 

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes