# Management API Access Tokens for Production returns access denied

**URL:** <https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946>\
**Category:** Get Help\
**Tags:** api\
**Created:** [April 12, 2021, 9:08am UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946 "2021-04-12T09:08:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![modish10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/modish10/32/28717_2.png) [@modish10](https://community.auth0.com/u/modish10)\
**Post date:** [April 12, 2021, 9:08am UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946/1 "2021-04-12T09:08:29Z")

</div>

Hi i was following the below link " Get Management API Access Tokens for Production "

> **[Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production?_ga=2.194657965.1239496157.1618174943-1976856459.1618174943)**
>
> Learn how to get Access Tokens to make scheduled frequent calls to the Management API.

var client = new RestClient(“[https://YOURDOMAIN/oauth/token](https://yourdomain/oauth/token)”);  
var request = new RestRequest(Method.POST);  
request.AddHeader(“content-type”, “application/x-www-form-urlencoded”);  
request.AddParameter(“application/x-www-form-urlencoded”, “grant\_type=client\_credentials&client\_id=%24%7Baccount.clientId%7D&client\_secret=YOUR\_CLIENT\_SECRET&audience=https%3A%2F%2F%24%7Baccount.namespace%7D%2Fapi%2Fv2%2F”, ParameterType.RequestBody);  
IRestResponse response = client.Execute(request);

I tried to get the token from a console app.  
below is the error I get  
Error : {“error”:“access\_denied”,“error\_description”:“Unauthorized”}

when i try from fiddler sometimes it gives me the same error or other wise it is 410 Gone.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 12, 2021, 1:33pm UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946/3 "2021-04-12T13:33:48Z")

</div>

Hi @modish10,

Your request looks good. Just to confirm, is your application a machine-to-machine (M2M) application that has been authorized to use your tenant’s management API?

After a failed request, do you see an associated tenant log (from your Auth0 dashboard, **Monitorig \> Logs** )? The logs will sometimes provide additional information which indicate what went wrong with the request.

You could also try testing from your terminal using cURL using the commands in the guide to see if you still get an error.

---

<div class="post-metadata">

**Author:** ![modish10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/modish10/32/28717_2.png) [@modish10](https://community.auth0.com/u/modish10)\
**Post date:** [April 13, 2021, 1:08am UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946/4 "2021-04-13T01:08:19Z")

</div>

Yes M2M

From Postman its working fine.  
it doesn’t show any log.

So I changed the code as below, and it worked.

```
private static async Task<string> PostFormUrlEncoded (string url, IEnumerable<KeyValuePair<string, string>> postData){
            using(var httpClient = new HttpClient()){
                using(var content = new FormUrlEncodedContent(postData)) {
                    content.Headers.Clear();
                    content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    HttpResponseMessage response = await httpClient.PostAsync(url, content);
                    return await response.Content.ReadAsStringAsync();
                }
            }
        }

 private static void GetToken() {
            IEnumerable<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>{
                new KeyValuePair<string, string>("grant_type", "client_credentials"),
                new KeyValuePair<string, string>("client_id", "YOUR CLIENT_ID"),
                new KeyValuePair<string, string>("client_secret", "YOUR CLIENT_SECRET"),
                new KeyValuePair<string, string>("audience", "https://YOURDOMAIN/api/v2/")
            };
            var tempT = Task.Run(async () => await PostFormUrlEncoded("https://YourDomain/oauth/token", postData))
                    .Result;
}

```

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 13, 2021, 1:13pm UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946/5 "2021-04-13T13:13:50Z")

</div>

That’s great! Glad it is working for you now.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 28, 2021, 1:14pm UTC](https://community.auth0.com/t/management-api-access-tokens-for-production-returns-access-denied/60946/6 "2021-04-28T13:14:42Z")

</div>

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