# REST API -OAuth Authentication Failed with status code 400

**URL:** <https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541>\
**Category:** Developer Q&A Forum\
**Created:** [May 13, 2024, 9:39am UTC](https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541 "2024-05-13T09:39:12Z")\
**Posts on this page:** 4\
**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 13, 2024, 9:39am UTC](https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541/1 "2024-05-13T09:39:12Z")

</div>

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)”

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

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

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

---

<div class="post-metadata">

**Author:** ![SarahFaustmann](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@SarahFaustmann](https://community.dynatrace.com/u/SarahFaustmann)\
**Post date:** [May 15, 2024, 6:30am UTC](https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541/2 "2024-05-15T06:30:45Z")

</div>

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

Thanks for your question. Just to make sure, because you didn’t explicitly mention: Have you also [created the appropriate permissions](https://docs.dynatrace.com/docs/dynatrace-api/basics/dynatrace-api-authentication/account-api-authentication#create-an-oauth2-client)&nbsp;along with the client? And have you [URL-encoded all values](https://docs.dynatrace.com/docs/shortlink/account-api-authentication#request-a-token) in your request body? You can also use [curl](https://curl.se/) to try and see if the issue is with your Python code or if it’s something else. Let us know if this helps!

Best,  
Sarah

---

<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 15, 2024, 6:36am UTC](https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541/3 "2024-05-15T06:36:34Z")

</div>

Hi Sarah,

The problem has been solved. The Firewall prevented the execution of the POST request over SSO.

Thanks for collaboration

---

<div class="post-metadata">

**Author:** ![SarahFaustmann](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@SarahFaustmann](https://community.dynatrace.com/u/SarahFaustmann)\
**Post date:** [May 15, 2024, 7:05am UTC](https://community.dynatrace.com/t/rest-api-oauth-authentication-failed-with-status-code-400/45541/4 "2024-05-15T07:05:30Z")

</div>

Great, thanks for letting us know!&nbsp;🙂
