# OAuth authentication failed with status code 400

**URL:** <https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532>\
**Category:** Dynatrace API\
**Tags:** tokens, dynatrace-api\
**Created:** [May 11, 2024, 2:14pm UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532 "2024-05-11T14:14:04Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 11, 2024, 2:14pm UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/1 "2024-05-11T14:14:04Z")

</div>

Hi guys,

I have a problem using the rest api for oauth authentication.

As described in your documentation I used POST in the request to the following endpoint:

[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)

I executed the instructions providing all the parameters in the request body, but when I execute the request I get an http error code 400 (Bad Request).&nbsp;How can I solve the problem?&nbsp;The python code follows:

import requests

oauth\_client = “my\_oauthClient”  
oauth\_secret = “my\_oauthSecret”  
oauth\_scope = "storage:events:read " \  
"storage:buckets:read " \  
"account-idm-write " \  
"account-idm-read " \  
"account-env-read " \  
"account-env-write " \  
"account-uac-read " \  
"account-uac-write " \  
"iam-policies-management " \  
"iam:policies:write " \  
"iam:policies:read " \  
"iam:bindings:write " \  
"iam:bindings:read " \  
“iam:effective-permissions:read”

oauth\_resource = “my\_urn:dtaccount:xxxxxxxxxxxxxx”

sso\_url = “[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)”

data = {  
‘grant\_type’: ‘“client\_credentials”’,  
‘client\_id’: oauth\_client,  
‘client\_secret’: oauth\_secret,  
‘scope’: oauth\_scope,  
‘resource’: oauth\_resource}

form\_headers = {“Content-Type”: “application/x-www-form-urlencoded”}  
response = requests.post(sso\_url,params={},headers=form\_headers,data=data)

auth\_status = response.status\_code

assert auth\_status == 200, f"OAuth authentication for DQL failed with status code {auth\_status}"

token = response.json().get(“access\_token”)

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 4:59am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/2 "2024-05-14T04:59:49Z")

</div>

Hi&nbsp;[@Hazard](https://community.dynatrace.com/user/75658)&nbsp;,

I think the bearer is missing.

So I think the bearer must be captured as data

 ![erh_inetum_0-1715662125872.png](https://global.discourse-cdn.com/dynatrace/original/2X/d/d31a27cfb894ab17d57f5f6f50626733e167402b.png)

like you did here:

_data = {  
‘grant\_type’: ‘“client\_credentials”’,  
‘client\_id’: oauth\_client,  
‘client\_secret’: oauth\_secret,  
‘scope’: oauth\_scope,  
‘resource’: oauth\_resource}_

and pass it the value captured in the response variable:

_form\_headers = {“Content-Type”: “application/x-www-form-urlencoded”}_  
_ **response** = requests.post(sso\_url,params={},headers=form\_headers, **data=data** )_

Hope it helps.

Regards,

Elena.

---

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 14, 2024, 7:46am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/3 "2024-05-14T07:46:50Z")

</div>

Hi Elena,

Maybe I didn’t explain myself well. My problem is that I can’t get a Bearer Token. After creating the OAuth2 client, requesting the bearer token from the Dynatrace SSO system via an API call fails. This API Call fail:

[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)&nbsp;(POST)

and it gives me an http code 400 (Bad Request).

the python code in the previous post explains it well

I hope I explained myself.

Thank you

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 8:00am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/4 "2024-05-14T08:00:37Z")

</div>

Hi Hazard,

Could you try to add these scopes on “oauth\_scope”&nbsp;variable?

settings:objects:read  
settings:objects:write  
settings:schemas:read  
app-engine:apps:run

Regards,

Elena.

---

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 14, 2024, 8:12am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/5 "2024-05-14T08:12:08Z")

</div>

So do I have to recreate the Oauth client by adding these scopes, in addition to the ones already present? Should I try this?

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 8:17am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/6 "2024-05-14T08:17:17Z")

</div>

Yes, I do. I would try it. With these scopes, it works for me.

---

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 14, 2024, 8:21am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/7 "2024-05-14T08:21:24Z")

</div>

Hi elena,

So, I’ll recreate the Oauth Client by adding the following scopes and let you know ok?

settings:objects:read  
settings:objects:write  
settings:schemas:read  
app-engine:apps:run

storage:buckets:read&nbsp;  
account-idm-write&nbsp;  
account-idm-read&nbsp;  
account-env-read&nbsp;  
account-env-write&nbsp;  
account-uac-read&nbsp;  
account-uac-write&nbsp;  
iam-policies-management&nbsp;  
iam:policies:write&nbsp;  
iam:policies:read&nbsp;  
iam:bindings:write&nbsp;  
iam:bindings:read

iam:effective-permissions:read

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 8:24am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/8 "2024-05-14T08:24:06Z")

</div>

Sure.

---

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 14, 2024, 9:27am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/9 "2024-05-14T09:27:18Z")

</div>

Sorry Helena,

but it failed again…

![Hazard_0-1715678791944.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/b1eecf93bab41e0f4bf2dbda3da85b8371ffa345.png)

Follow Postman Request.

This thing is driving me crazy!

 ![Hazard_1-1715678826410.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/1/c1dc07eb20f908c479d2042de355bb349854a04d.png)

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 9:49am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/10 "2024-05-14T09:49:30Z")

</div>

Hi Hazard,

This is my configuration on Postman and returns the bearer:

 ![erh_inetum_0-1715679942712.png](https://global.discourse-cdn.com/dynatrace/original/3X/3/9/39dd348af84589e6855e22f1ec7c0a90db65fc11.png)

 ![erh_inetum_1-1715679998108.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/8/78d7fe56152af94ba66380654b75d56e9e7e714b.png)

The only difference that I see it’s the “grant type” key. You could try to remove it and test if it works.

---

<div class="post-metadata">

**Author:** ![Hazard](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hazard](https://community.dynatrace.com/u/Hazard)\
**Post date:** [May 14, 2024, 10:00am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/11 "2024-05-14T10:00:03Z")

</div>

Hi Helena,

I removed the “grant\_type” key but I still get the same result. It doesn’t provide me with the bearer…

 ![Hazard_0-1715680789115.png](https://global.discourse-cdn.com/dynatrace/original/3X/2/7/27591b7f562156d5bf9d9b8ea9bf0512dd555a0a.png)

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [May 14, 2024, 1:59pm UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/12 "2024-05-14T13:59:19Z")

</div>

Hi again Hazard,

Adding “grant\_type” it also works:

 ![erh_inetum_0-1715694368023.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/2/e2e7374b2cf5656f220f467157b2a660956f422c.png)

In the answer of the POST you can see the used scopes.

Please, be sure that the value of “scope” key contains the same scopes you have defined for the client\_id on Identity & Access Managment \> OAuth clients. And also be sure the client\_id is the desired client\_id you want to use.

If it doesn´t work, I’m afraid I haven´t more ideas.

Regards,

Elena

---

<div class="post-metadata">

**Author:** ![DaveOps](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@DaveOps](https://community.dynatrace.com/u/DaveOps)\
**Post date:** [August 13, 2024, 8:43am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/13 "2024-08-13T08:43:08Z")

</div>

I have the same issue:

curl --request POST ‘[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)’ \  
--header ‘Content-Type: application/x-www-form-urlencoded’ \  
--data-urlencode ‘grant\_type=client\_credentials’ \  
--data-urlencode ‘client\_id=xx’ \  
--data-urlencode ‘client\_secret=xx’ \  
--data-urlencode ‘resource=urn:dtaccount:xx’ \  
--data-urlencode ‘scope=app-engine:apps:install app-engine:apps:run’

{“errorCode”:400,“message”:“Bad Request”,“issueId”:“WUQIHC74YTS7NMJO”,“error”:“invalid\_request”,“error\_description”:“”}%

---

<div class="post-metadata">

**Author:** ![DaveOps](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@DaveOps](https://community.dynatrace.com/u/DaveOps)\
**Post date:** [August 13, 2024, 8:56am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/14 "2024-08-13T08:56:07Z")

</div>

When I leave out the scope and resource field a bearer is returned:

```javascript
curl --location --request POST 'https://sso.dynatrace.com/sso/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=yy' \
--data-urlencode 'client_secret=zz'

{"scope":"app-engine:apps:install","token_type":"Bearer","expires_in":300,"access_token":"ey....

```

---

<div class="post-metadata">

**Author:** ![DaveOps](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@DaveOps](https://community.dynatrace.com/u/DaveOps)\
**Post date:** [August 13, 2024, 9:01am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/15 "2024-08-13T09:01:51Z")

</div>

What I am missing is all the scopes that are needed for my use case to install a custom build react app via the deployment pipeline.

app-engine:apps:install  
app-engine:apps:run  
app-engine:apps:delete

What could be the reason?

---

<div class="post-metadata">

**Author:** ![avdveen](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@avdveen](https://community.dynatrace.com/u/avdveen)\
**Post date:** [April 12, 2025, 11:03am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/16 "2025-04-12T11:03:32Z")

</div>

Hi&nbsp;[@Hazard](https://community.dynatrace.com/user/75658)&nbsp;remove the quotes around _client\_credentials_ for the _grant\_type_&nbsp;query parameter.

You had it like this:

![andre_vdveen_0-1744455762757.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/fe71ed1c6251303aeabe39bc387c0a68c356de77.png)

But it should be without the “” around client\_credentials, like this:

![andre_vdveen_1-1744455799598.png](https://global.discourse-cdn.com/dynatrace/original/3X/d/8/d8fa89e6115ee609326eaf83344e6d24370786a6.png)

I confirmed it in Postman, with “” it breaks.

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 4, 2025, 4:10pm UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/17 "2025-06-04T16:10:40Z")

</div>

Maybe you have already solved, but this is for the records

You need to specify exactly the list of scopes that you already exactly defined during the OAuth2 client creation not new ones, you list them by space separated. If you need all of them simply omit the scope parameters then you get them all.

Example on windows

curl -X POST “[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)” ^  
-H “Content-Type: application/x-www-form-urlencoded” ^  
-d “grant\_type=client\_credentials” ^  
-d “scope=environment-api:entities:read” ^  
-d “client\_id=YOUR\_ID” ^  
-d “client\_secret=YOUR\_CLIENT°SECRET” ^  
-d “resource=YOUR\_URN”

You should get this response

curl -X POST “[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)” -H “Content-Type: application/x-www-form-urlencoded” -d “grant\_type=client\_credentials” -d "client\_id=“YOUR\_CLIENT\_ID” -d "client\_secret=“YOUR\_CLIENT°SECRET” -d “resource=YOUR\_URN”{“scope”:“storage:entities:read environment-api:entities:read”,“token\_type”:“Bearer”,“expires\_in”:300,“access\_token”:“YOUR\_BEARER\_TOKEN”,“resource”:“YOUR\_URN”}Hope this helps

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 16, 2025, 8:27am UTC](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532/18 "2025-06-16T08:27:50Z")

</div>

Leave the scope list out, yo will get all what you define before. This should work.
