# Cannot Delete or Get a user "Not Found"

**URL:** <https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113>\
**Category:** Get Help\
**Tags:** users-list, user, users, delete-user\
**Created:** [April 14, 2021, 9:57pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113 "2021-04-14T21:57:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NNKamel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nnkamel/32/28662_2.png) [@NNKamel](https://community.auth0.com/u/NNKamel)\
**Post date:** [April 14, 2021, 9:57pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/1 "2021-04-14T21:57:48Z")

</div>

Hi, I am facing a problem with getting and deleting users. I am trying to do so using the API [https://DOMAIN.auth0.com/users/userid](https://DOMAIN.auth0.com/users/userid) using my custom API (which is not my Management API)

However I have been able to use the [https://DOMAIN.com/userinfo](https://DOMAIN.com/userinfo) API to get the current user info, using my Custom API.

And if I change my request to: [https://DOMAIN.auth0.com/api/v2/users](https://DOMAIN.auth0.com/api/v2/users)  
I get:  
{“statusCode”:401,“error”:“Unauthorized”,“message”:“Bad audience: https://custom\_api\_identifier/ [https://DOMAIN.auth0.com/userinfo](https://DOMAIN.auth0.com/userinfo)”}

My whole dev stack is SPA using angular in the front end, and .Net webapi as a backend. And I can’t use the Auth0 Management API because I need to use permissions and roles and these are not customizable there. So I need the Custom API but I don’t know how to get all users or get one user by its id or delete a user using the custom API audience

---

<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 15, 2021, 11:39am UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/3 "2021-04-15T11:39:52Z")

</div>

Hi @NNKamel,

When you need to make requests to a Management API endpoint (such as `https://your-domain/api/v2/users`), the API must be authorized to use the Management API. To do this, you’d create a machine-to-machine (M2M) application that represents your API and authorize the M2M app to use the `read:users` scope of the Management API.

1. Create M2M app:  

2. Authorize it to use the Management API:  

3. Within your custom API, get an Access Token:

```auto
curl --request POST \
  --url https://YOUR-DOMAIN/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"YOUR_M2M_APP_CLIENT_ID","client_secret":"YOUR_M2M_APP_CLIENT_SECRET","audience":"https://YOUR-DOMAIN/api/v2/","grant_type":"client_credentials"}'

```

1. Use the Access Token from step 3 to call the Management API:

```auto
curl --request GET \
  --url https://YOUR-DOMAIN/api/v2/users \
  --header 'authorization: Bearer ACCESS_TOKEN'

```

---

<div class="post-metadata">

**Author:** ![NNKamel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nnkamel/32/28662_2.png) [@NNKamel](https://community.auth0.com/u/NNKamel)\
**Post date:** [April 23, 2021, 4:58pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/4 "2021-04-23T16:58:30Z")

</div>

So I just followed what you said and that worked for getting users, and thank you very much. But however when trying to set user roles, I get  
`{"statusCode":400,"error":"Bad Request","message":"Schema violation"}`  
which I don’t know why. Do you know the correct way to fix this request in C# code?

```
        dynamic body = new
        {
            roles = new List<string> { "Admin" }
        };
        var client = new RestClient($"https://DOMAIN.com/api/v2/users/{dictionary["sub"]}/roles");
        var restRequest = new RestRequest(Method.POST);
        restRequest.AddHeader("Authorization", mtok);
        restRequest.AddHeader("content-type", "application/json");
        restRequest.AddParameter("application/json", JsonConvert.SerializeObject(body), ParameterType.RequestBody);
        IRestResponse response = await client.ExecuteAsync(restRequest);

```

So mtok is my machine token that you just instructed me how to get it in step 3. And my userid is the “dictionary[“sub”]”, And I have an Admin role.

---

<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 23, 2021, 5:15pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/5 "2021-04-23T17:15:20Z")

</div>

Great to hear that is working for you!

It looks like you are using the string “Admin” inside the `roles` list. Instead of using the role name, you’ll want to use the role ID (the role ID looks like `rol_abc123`). You can find the role ID by using the [GET](https://auth0.com/docs/api/management/v2?_ga=2.246162692.1847387816.1618225160-1595415333.1607347674#!/Roles/get_roles)[/api/v2/roles](https://auth0.com/docs/api/management/v2?_ga=2.246162692.1847387816.1618225160-1595415333.1607347674#!/Roles/get_roles) endpoint, or you can just go to **User Management** \> **Roles** in your dashboard. Click on a role and copy the role ID from the URL:

```auto
https://manage.auth0.com/dashboard/us/YOUR-TENANT/roles/YOUR-ROLE-ID/settings

```

---

<div class="post-metadata">

**Author:** ![NNKamel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nnkamel/32/28662_2.png) [@NNKamel](https://community.auth0.com/u/NNKamel)\
**Post date:** [April 23, 2021, 6:01pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/6 "2021-04-23T18:01:10Z")

</div>

Thank you very much. Worked as expected

---

<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:** [May 8, 2021, 6:02pm UTC](https://community.auth0.com/t/cannot-delete-or-get-a-user-not-found/61113/7 "2021-05-08T18:02:02Z")

</div>

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