# Requesting management api token from backend returns data field with weird encoding

**URL:** <https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756>\
**Category:** Get Help\
**Tags:** anomaly, management-api\
**Created:** [December 19, 2022, 8:23pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756 "2022-12-19T20:23:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwpihlgren](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jwpihlgren/32/42060_2.png) [@jwpihlgren](https://community.auth0.com/u/jwpihlgren)\
**Post date:** [December 19, 2022, 8:23pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/1 "2022-12-19T20:23:51Z")

</div>

Hi, I’m using a locally hosted server to request a management api token so that my backend can read a user’s metadata.

The request succeeds with status 200 OK and using curl I even get a readable response. But when I look at the console.loged data field from the response when the server makes the call, the reponse looks something like the below.

![image](https://global.discourse-cdn.com/auth0/original/3X/5/f/5f19600eb1077d30304b971764f7fcfe2b32e72b.png)

Any ideas as to why the data field seems to be in some sort of byte representation?

Thanks in advance

Flabberghasted

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [December 19, 2022, 9:50pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/2 "2022-12-19T21:50:48Z")

</div>

Hi there @jwpihlgren welcome to the community!

> [@jwpihlgren](#):
>
> The request succeeds with status 200 OK and using curl I even get a readable response. But when I look at the console.loged data field from the response when the server makes the call, the reponse looks something like the below.

Interesting! I’m not positive, but do you mind sharing the server code you’re using the request the token?

Keep us posted!

---

<div class="post-metadata">

**Author:** ![jwpihlgren](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jwpihlgren/32/42060_2.png) [@jwpihlgren](https://community.auth0.com/u/jwpihlgren)\
**Post date:** [December 20, 2022, 5:46am UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/4 "2022-12-20T05:46:50Z")

</div>

Thanks for the quick reply @ty.frith!

I call a wrapper around axios like so:

```auto
async function getManagementAPIAccessToken(): Promise<any> {
    const url = `${process.env.AUTH0_DOMAIN}oauth/token`
    const options = {
        headers: {
            'content-type': 'application/json'
        }
    }
    const data = {
        client_id: process.env.AUTH0_CLIENT_ID,
        client_secret: process.env.AUTH0_CLIENT_SECRET,
        audience: process.env.AUTH0_MANAGEMENT_API_AUDIENCE,
        grant_type: process.env.AUTH0_GRANT_TYPE
    }

    const response = await HttpService.post(url, data, options)

    return response
}

```

And the wrapper looks like this:

```auto
async function post(url: string, data: any, config?: any ): Promise<any> {
    let result = {}
    try {
        const request = await axios.post(url, data, config)
        result = request.data
    }
    catch(error) {
        result["error"] = (error as any).response.data
    }
    return result
    
}

```

From my package.json:

```auto
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.6",
    "@types/node": "^18.11.10",
    "@typescript-eslint/eslint-plugin": "^5.13.0",
    "@typescript-eslint/parser": "^5.13.0",
    "eslint": "^8.10.0",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.3"
  },
  "dependencies": {
    "@types/mongoose": "^5.11.97",
    "@types/ws": "^8.5.3",
    "axios": "^1.2.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.17.1",
    "express-oauth2-jwt-bearer": "^1.1.0",
    "express-validator": "^6.14.0",
    "fast-xml-parser": "^4.0.8",
    "heartbeats": "^5.0.1",
    "mongoose": "^6.7.5",
    "nodemon": "^2.0.7",
    "ws": "^8.7.0"
  }

```

Thank your for your attention to this matter.

---

<div class="post-metadata">

**Author:** ![jwpihlgren](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jwpihlgren/32/42060_2.png) [@jwpihlgren](https://community.auth0.com/u/jwpihlgren)\
**Post date:** [December 20, 2022, 5:48am UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/5 "2022-12-20T05:48:38Z")

</div>

I obviously should have stated that I’m using nodejs with typescript.

---

<div class="post-metadata">

**Author:** ![jwpihlgren](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jwpihlgren/32/42060_2.png) [@jwpihlgren](https://community.auth0.com/u/jwpihlgren)\
**Post date:** [December 20, 2022, 9:17pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/6 "2022-12-20T21:17:49Z")

</div>

I switched from axios to fetch and I get a proper response now.

For my intents and purposes this is solved. I would believe that the fault lies with the axios library rather than you but I would be willing to provide further information upon request.

Thank you for your attention to this matter!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [December 20, 2022, 9:32pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/7 "2022-12-20T21:32:53Z")

</div>

> [@jwpihlgren](#):
>
> I switched from axios to fetch and I get a proper response now.

Hmm that’s interesting - Thanks for following up here and glad to know that solved it for 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:** [January 3, 2023, 9:33pm UTC](https://community.auth0.com/t/requesting-management-api-token-from-backend-returns-data-field-with-weird-encoding/96756/8 "2023-01-03T21:33:25Z")

</div>

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