Get Access Token Bad Request Exception for OAuth With Authorization Code Grant

I can get the code but when get access token by code, it throws error 400. I have follow the steps of /api/rest/authorization/use-authorization-code.html

I also use the python sample code to run and get the same error.

Below is the postman test.

post to https://login.mypurecloud.com.au/oauth/token

header:
Authorization:Basic xxxxxxxxxx ()
content-type:application/x-www-form-urlencoded

Body:
grant_type:authorization_code
code:zjfvnI2cVptStGnh3fQ0ASOPqSkiYdJ5iPuS1_WXhDA
redirect_uri:http://teleapps.net:8000/dashboard/

Error 400
{
"error": "invalid_request"
}
Inin-Correlation-Id →81d5f74e-b193-4fe5-bf8e-7e2d80804a62

The body isn't right. Be sure to use the proper format for form encoded data in a POST request. See https://developer.mypurecloud.com/api/rest/authorization/use-authorization-code.html for an example HTTP request.

Connection →keep-alive
Content-Length →28
Content-Type →application/json
Date →Tue, 05 Jun 2018 09:43:36 GMT
Inin-Correlation-Id →0cc9cf2d-599e-4ff0-af0f-9e08629ede89
Strict-Transport-Security →max-age=7776000

Connection →keep-alive
Content-Length →28
Content-Type →application/json
Date →Tue, 05 Jun 2018 09:43:36 GMT
Inin-Correlation-Id →0cc9cf2d-599e-4ff0-af0f-9e08629ede89
Strict-Transport-Security →max-age=7776000

Connection →keep-alive
Content-Length →28
Content-Type →application/json
Date →Tue, 05 Jun 2018 09:47:03 GMT
Inin-Correlation-Id →863d1e59-1805-4f53-bf81-9d5bb6cfe213
Strict-Transport-Security →max-age=7776000

Both body content have correct auth code. However, No luck. Please help

What kind of response are you getting?

Try using the x-www-form-urlencoded body type since the body is supposed to be form encoded.

image

Connection →Close
Content-Length →28
Content-Type →application/json
Date →Tue, 05 Jun 2018 13:25:22 GMT
Inin-Correlation-Id →ba9b0a89-946e-4f5a-9f92-b86f099ab942
Strict-Transport-Security →max-age=7776000

error 400 bad request

Please help, any solution?

You're still not sending a valid request. Please refer to the example request in the Grant - Authorization Code documentation. You must send the request exactly as documented. This includes sending a properly form-encoded body. Your examples have all been visibly different from the example in the documentation thus far.

Also, you could try configuring the auth code grant using Postman's Authorization OAuth2 configuration. There's nothing wrong with doing it manually, but Postman has tools to help with this.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.