always getting Invalid grant_type parameter or parameter missing but works on postman
I am trying to get my access token with a post request.
I have tried the request on postman and it works perfectly.
but when trying from my app I get the error
{error: "invalid_request", error_description: "Invalid grant_type parameter or parameter missing"}
I have copied the code from from postman and tried it in my JS but I still get the error
This is my fetch call
fetch('https://api.box.com/oauth2/token', { method: 'post', headers: { "Content-type": "application/x-www-form-urlencoded; charset=UTF-8" }, body: JSON.stringify({ grant_type: 'authorization_code', code: code, client_id: "CLIENT_ID", client_secret: "CLIENT_SECRET" }) })
Any help would be greatly appreciated.
Thank you
-
,
You'll have better luck getting a response posting this to the Box Developer Forum.
Bob
-
You're setting the wrong content-type. You set it to
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
but you're sending json so it should be
"Content-type": "application/json"
If you want to send urlencoded data instead of json then the data should look like:
grant_type=authorization_code&code=code&client_id=CLIENT_ID&client_secret=CLIENT_SECRET
Please sign in to leave a comment.
Comments
2 comments