# How can I get acess\_token of my API in Angular app?

**URL:** <https://community.auth0.com/t/how-can-i-get-acess-token-of-my-api-in-angular-app/85190>\
**Category:** Get Help\
**Tags:** angular\
**Created:** [June 15, 2022, 7:16pm UTC](https://community.auth0.com/t/how-can-i-get-acess-token-of-my-api-in-angular-app/85190 "2022-06-15T19:16:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonardo.lima](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leonardo.lima/32/27607_2.png) [@leonardo.lima](https://community.auth0.com/u/leonardo.lima)\
**Post date:** [June 15, 2022, 7:16pm UTC](https://community.auth0.com/t/how-can-i-get-acess-token-of-my-api-in-angular-app/85190/1 "2022-06-15T19:16:43Z")

</div>

I try to get the access token of my API and I have CORS error on the console:

> Access to XMLHttpRequest at ‘[https://altatechti.us.auth0.com/oauth/token](https://altatechti.us.auth0.com/oauth/token)’ from origin ‘[http://localhost:4200](http://localhost:4200)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I created this function

```auto
getToken() {
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
    })
    return this.httpClient.post(
      this.tokenUrl,
      '[{"client_id": "", "client_secret": "", "audience": ", "grant_type":""}]',
      { headers: headers })
  }

```

Am I doing something wrong?

---

<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:** [June 16, 2022, 8:43pm UTC](https://community.auth0.com/t/how-can-i-get-acess-token-of-my-api-in-angular-app/85190/3 "2022-06-16T20:43:28Z")

</div>

Hi @leonardo.lima,

Welcome to the Auth0 Community!

I understand that you would like to get an Access Token of your custom API in your Angular application.

After looking at your function, I did not find anything that stands out as to why you are encountering a CORS error when [Calling your API using the Client Credentials Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-client-credentials-flow).

In this case, I recommend using the code snippet provided on your Auth0 Dashboard to get an Access Token for your API. To do so, please navigate to your [Auth0 Dashboard \> Applications \> APIs \> YOUR\_API](https://manage.auth0.com/#/apis) and click on the **Test** tab.

On that page, click on **Node.JS** and select your M2M application from the drop-down list. With that, use the code snippet provided in the interface in your Angular app. This should provide a working code snippet for calling your API using the Client Credentials flow. See below for clarity:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/f/b/fb046358db65603bd5f250d15ff536f4fbfce74d.jpeg)

Here is the code snippet skeleton below as well:

```auto
var request = require("request");

var options = { method: 'POST',
  url: 'https://YOUR_DOMAIN.REGION.auth0.com/oauth/token',
  headers: { 'content-type': 'application/json' },
  body: '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET","audience":"YOUR_AUDIENCE_IDENTIFIER","grant_type":"client_credentials"}' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

```

Lastly, I have tested this request and confirm that I could successfully get an Access Token for my API.

I hope this helps!

Please let me know if you need any help with this.

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:52am UTC](https://community.auth0.com/t/how-can-i-get-acess-token-of-my-api-in-angular-app/85190/4 "2022-12-22T10:52:58Z")

</div>


