# C# API: test token for management API returns AggregateException

**URL:** <https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [December 9, 2025, 7:42am UTC](https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333 "2025-12-09T07:42:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wake-reliant-poise](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wake-reliant-poise/32/73047_2.png) [@wake-reliant-poise](https://community.auth0.com/u/wake-reliant-poise)\
**Post date:** [December 9, 2025, 7:42am UTC](https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333/1 "2025-12-09T07:42:43Z")

</div>

This is giving me an error (forgive my F#):

```auto
#r "nuget: FSharpPlus"
#r "nuget: Auth0.Core"
#r "nuget: Auth0.ManagementApi"

open FSharpPlus
open System.Threading.Tasks
open Auth0
open Auth0.ManagementApi
open Auth0.ManagementApi.Models

let token = "..."

let client = Auth0.ManagementApi.ManagementApiClient(token, "https://redacted.ca.auth0.com/")

let req = GetUsersRequest()

let result = client.Users.GetAllAsync(req).Result

```

System.AggregateException: One or more errors occurred. (The format of value 'Bearer   
’ is invalid.)

The token is valid JWT tested on [JWT.io](http://JWT.io) generated from the Auth0 Management API page. It also works in the docs.

Any idea what’s going on here?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [December 10, 2025, 3:21pm UTC](https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333/3 "2025-12-10T15:21:28Z")

</div>

Hi @wake-reliant-poise,

The error strongly suggests that the **token string being passed to the `ManagementApiClient` contains unexpected whitespace characters** —most commonly a newline or an extra space—either before or after the actual JWT. The `Auth0.ManagementApi` client, which uses `HttpClient` internally, is very strict about the format of the `Authorization` header.

You can try using the `.Trim()` method to remove the whitespace from the token.

Please let us know if that resolves the issue.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![wake-reliant-poise](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wake-reliant-poise/32/73047_2.png) [@wake-reliant-poise](https://community.auth0.com/u/wake-reliant-poise)\
**Post date:** [December 11, 2025, 7:40am UTC](https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333/4 "2025-12-11T07:40:43Z")

</div>

Hi Vlad,

I could have sworn I’d cleaned up the file I was loading the token from, but as it turns out, you’re right. `Trim()` solved it.

Thanks for the pointer!

---

<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:** [December 25, 2025, 7:41am UTC](https://community.auth0.com/t/c-api-test-token-for-management-api-returns-aggregateexception/195333/5 "2025-12-25T07:41:10Z")

</div>

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