# 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:** 1\
**Showing post:** 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”)

---

_[View the full topic](https://community.dynatrace.com/t/oauth-authentication-failed-with-status-code-400/45532)._
