02-07-2022 18:16
02-07-2022 18:16
Hello Fitbit dev team,
I'm having some issues creating a subscription after verifying my subscriber endpoint and authenticating a user via the implicit grant flow.
Once the user is authenticated, the user's access token is used to call the create a subscription api.
However, when calling this endpoint with my configurations I am receiving this error message: 'Authorization Error: Invalid authorization token type' .
Here is the code I used to call the POST request endpoint:
const headers: {
"Authorization": `Bearer <accessCode>`,
"X-Fitbit-Subscriber-Id": "1",
"content-length": "32"
};
const url = https://api.fitbit.com/1/user/-/apiSubscriptions/test.json
axios.post(url, headers);
Answered! Go to the Best Answer.
Best Answer02-08-2022 10:31
02-08-2022 10:31
Hi @Gordon-C ,
yes that is correct - the accessCode is the access token created after oauth2 flow.
Just to update you, I managed to successfully create a subscription!
The steps I took are:
1. Revoke the user's access token
2. Authenticate the user to retrieve the access token
3. Use the access token to create a subscription with an Authorization and X-Fitbit-Subscriber-Id header
02-08-2022 09:38
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
02-08-2022 09:38
Hi @esef
Is there a reason for surrounding your authorization header value with single tick marks, while the other header values use double-quotes?
Gordon
Best Answer02-08-2022 10:01
02-08-2022 10:01
Hi @Gordon-C ,
the authorization header value uses template literals (i.e backticks) to embed expressions such as the access code. I changed the backticks to double-quotes but I"m still receiving the same error message.
const config = {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + accessCode,
"X-Fitbit-Subscriber-Id": "1",
"Content-Length": "32"
}
};
Best Answer02-08-2022 10:21
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
02-08-2022 10:21
@esef ... when you say accessCode, you mean the access token that is created after oauth2 flow is complete?
02-08-2022 10:31
02-08-2022 10:31
Hi @Gordon-C ,
yes that is correct - the accessCode is the access token created after oauth2 flow.
Just to update you, I managed to successfully create a subscription!
The steps I took are:
1. Revoke the user's access token
2. Authenticate the user to retrieve the access token
3. Use the access token to create a subscription with an Authorization and X-Fitbit-Subscriber-Id header