09-11-2022 03:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-11-2022 03:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hey guys!
I'm using Laravel for authenticate with Fitbit
I tried to make a request for auth but when i want to Exchange the Authorization Code for the Access and Refresh Tokens, returns this error:
{
"errors":[
{"errorType":"invalid_request","message":"Missing 'grant_type' parameter value. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}
],"success":false
}
It is possible to show the logic or other materials if requested.
Anyone can help?
09-12-2022 09:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-12-2022 09:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @ShahabS
I'm not familiar with Laravel, but you should still make certain your code uses the correct syntax for authentication. When your application calls /oauth2/token, make certain you have the grant_type parameter specified and the value set to "authorization_code".
See https://dev.fitbit.com/build/reference/web-api/authorization/oauth2-token/
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

09-15-2022 05:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-15-2022 05:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm using this code for this request:
$code = $request->input('code');
$url = 'https://api.fitbit.com/oauth2/token';
$auth_key = base64_encode(env('FITBIT_CLIENT_ID') . ':' . env('FITBIT_CLIENT_SECRET'));
return Http::withHeaders([
'Authorization' => 'Basic ' . $auth_key,
'Content-Type' => 'application/x-www-form-urlencoded'
])
->post($url, [
'code' => $code,
'client_id' => env('FITBIT_CLIENT_ID'),
'code_verifier' => '01234567890123456789012345678901234567890123456789',
'grant_type' => 'authorization_code',
]);

09-17-2022 07:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-17-2022 07:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Is the comma after 'authorization_code' a syntax error?
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
09-19-2022 09:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-19-2022 09:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
No, i'm using PHPStorm and there is no syntax error.

09-19-2022 12:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



09-19-2022 12:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
At a high-level, the code look good to me. But, I'm not familiar with PHP code to know if what you're doing is correct. I've tried researching PHP examples and can't find exactly what I need. I did see where the comma on the last key=>value pair in the array is ok. I'm going to pose these questions to you to see if you can verify the information.
1. Are you including the Content-length header in your request? This is a requirement for POST requests and I don't see it listed here. We're missing the information in the documentation, but the other POST requests state
content-length | required | According to RFC 7230, section 3.3.2, this HTTP request requires the Content-Length header field containing the anticipated size of the payload body. |
Http::withHeaders([
'Authorization' => 'Basic ' . $auth_key,
'Content-Type' => 'application/x-www-form-urlencoded'
])
2. Are these parameters described as query or body parameters? They should be body parameters as described in the documentation. See https://dev.fitbit.com/build/reference/web-api/authorization/oauth2-token/#Request.
[
'code' => $code,
'client_id' => env('FITBIT_CLIENT_ID'),
'code_verifier' => '01234567890123456789012345678901234567890123456789',
'grant_type' => 'authorization_code',
]
3. Try switching the order of the parameter values so grant_type=authorization_code is first. What happens?
4. Lastly, what is your application type designation in your registered application setting at https://dev.fitbit.com/apps?
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

10-10-2022 11:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-10-2022 11:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Did you find a solution for this?

10-10-2022 11:39 - edited 10-10-2022 11:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-10-2022 11:39 - edited 10-10-2022 11:40
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am facing the same issue. I am using React and my request went out with the right configurations too. And I still get the same error.
As you can see from the screenshot, I have provided grant_type as authorization_code, but the error still says "Missing 'grant_type' parameter value"

10-11-2022 07:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-11-2022 07:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @sony8
Again, I'm not familiar with React code. At a glance, your code looks correct. Would you please provide me the answers to the same questions I asked above?
- Are you using the content-length header?
- Are these parameters body parameters?
- Try switching the order of the parameter list so grant_type is first. What happens?
- Lastly, what is your application type designation in your registered application setting at https://dev.fitbit.com/apps?
Gordon
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

10-16-2022 23:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2022 23:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Are you using the content-length header?
- No. Should I be using it? If so, what values should I give?
- The only header values I am using are:
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${fitbitConfig.basicToken}`,
- Are these parameters body parameters?
- Yes
- Try switching the order of the parameter list so grant_type is first. What happens?
- No difference even when I change the order
- Lastly, what is your application type designation in your registered application setting at https://dev.fitbit.com/apps?
- Server

10-17-2022 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-17-2022 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you for answering my questions. I believe you are suppose to use the content-length header since it is a POST endpoint. However, the information is missing from the documentation for that endpoint. I can fix that. The definition of content-length is
content-length | required | According to RFC 7230, section 3.3.2, this HTTP request requires the Content-Length header field containing the anticipated size of the payload body. |
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

