# 500 on /oauth/token machine-to-machine

**URL:** <https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768>\
**Category:** Get Help\
**Tags:** api, management-api, login\
**Created:** [September 16, 2022, 10:09am UTC](https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768 "2022-09-16T10:09:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![t.leduc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/t.leduc/32/39995_2.png) [@t.leduc](https://community.auth0.com/u/t.leduc)\
**Post date:** [September 16, 2022, 10:09am UTC](https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768/1 "2022-09-16T10:09:46Z")

</div>

Hi  
I want to use manage API to delete user with the endpoint  
DELETE /api/v2/users/{id}

I already have machine-to-machine app with all APIs `Authorized` and delete:users checked in permissions

So I follow this doc to get access token :

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

but the API returns me HTTP 500 with this body :

```json
{
	"error": "server_error",
	"error_description": "Script generated an unhandled asynchronous exception."
}

```

I try with Insomnia and my project and i’ve got the same result

My code :

```plaintext
RestBuilder rest = new RestBuilder()
        RestResponse response = rest.post("https://tenant-url/oauth/token") {
            contentType("application/json")
            json({
                grant_type = "client_credentials"
                client_id = "my client id"
                client_secret = "my client secret"
                audience = "https://tenant-url/api/v2/"
            })
        }

```

I see nothing wrong on status page so why I’ve got a 500 error ?

---

<div class="post-metadata">

**Author:** ![t.leduc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/t.leduc/32/39995_2.png) [@t.leduc](https://community.auth0.com/u/t.leduc)\
**Post date:** [September 19, 2022, 6:59am UTC](https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768/3 "2022-09-19T06:59:32Z")

</div>

I had a default hook set in my configuration  
Once removed, the error disappeared

The error message is not clear 😠

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 21, 2022, 5:16pm UTC](https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768/4 "2022-09-21T17:16:03Z")

</div>

Hi @t.leduc,

Thanks for reaching out to the Auth0 Community!

I understand that you encountered an undescriptive error when getting the Management API access token.

> [@t.leduc](#):
>
> I had a default hook set in my configuration  
> Once removed, the error disappeared

I’m glad you resolved the issue after discovering that a Client Credentials Exchange Hook was responsible for the error!

In the future, I recommend using our Auth0 [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) to troubleshoot all the custom-code on your account.

If you have any other issues or questions, please feel free to reach out.

Thank you.

---

<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:** [October 5, 2022, 5:16pm UTC](https://community.auth0.com/t/500-on-oauth-token-machine-to-machine/90768/7 "2022-10-05T17:16:06Z")

</div>

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