# How to use the .NET SDK to get an access token for the management API?

**URL:** <https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219>\
**Category:** Get Help\
**Tags:** access-token, .net, management-api\
**Created:** [June 23, 2017, 1:05am UTC](https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219 "2017-06-23T01:05:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saxon](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@saxon](https://community.auth0.com/u/saxon)\
**Post date:** [June 23, 2017, 1:05am UTC](https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219/1 "2017-06-23T01:05:27Z")

</div>

Hi,  
I’m using the following code to try to get an access token for using the management API:

```
string auth0Domain = "mydomain.au.auth0.com";
var auth0AuthenticationClient = new AuthenticationApiClient(
    new Uri(String.Format("https://{0}", auth0Domain)));
var tokenRequest = new ClientCredentialsTokenRequest()
    {
        ClientId = "my client id",
        ClientSecret = "my client secret",
        Audience = String.Format("https://{0}/api/v2", auth0Domain),
    };
var tokenResponse = 
    await auth0AuthenticationClient.GetTokenAsync(tokenRequest);

```

However I get the following error:

> Client is not authorized to access  
> “https:/mydomain.au.auth0.com/api/v2”.  
> You might probably want to create a  
> “client-grant” associated to this API.  
> See:  
> [Management API Reference - Auth0 Docs](https://auth0.com/docs/api/v2#!/Client_Grants/post_client_grants)

I googled that error and found this question:

[http://community.auth0.com/questions/1626/how-to-generate-a-management-api-token-automatical](http://community.auth0.com/questions/1626/how-to-generate-a-management-api-token-automatical)

However I have already done all of those steps, ie created a non-interactive client, authorized the client for the management API, and configured some scopes.

Any ideas what else I could be missing?

Thanks,  
Saxon

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [June 23, 2017, 6:55am UTC](https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219/2 "2017-06-23T06:55:32Z")

</div>

You are requesting a token for the API with identifier (audience) `https:/mydomain.au.auth0.com/api/v2`.

The Management API identifier is `https:/mydomain.au.auth0.com/api/v2/` - notice the trailing slash. Please amend your audience to reflect this.

---

<div class="post-metadata">

**Author:** ![saxon](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@saxon](https://community.auth0.com/u/saxon)\
**Post date:** [June 23, 2017, 12:25pm UTC](https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219/3 "2017-06-23T12:25:05Z")

</div>

Awesome, thanks @prashant, that fixed it! 🙂

---

<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:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/how-to-use-the-net-sdk-to-get-an-access-token-for-the-management-api/7219/4 "2018-03-02T05:54:53Z")

</div>


