# How create access token to use administration rest api

**URL:** <https://forum.keycloak.org/t/how-create-access-token-to-use-administration-rest-api/18585>\
**Category:** Miscellanaeous\
**Created:** [November 24, 2022, 2:30pm UTC](https://forum.keycloak.org/t/how-create-access-token-to-use-administration-rest-api/18585 "2022-11-24T14:30:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nestle2377](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/nestle2377/32/3163_2.png) [@nestle2377](https://forum.keycloak.org/u/nestle2377)\
**Post date:** [November 24, 2022, 2:30pm UTC](https://forum.keycloak.org/t/how-create-access-token-to-use-administration-rest-api/18585/1 "2022-11-24T14:30:45Z")

</div>

Hi to all, I’ve to call some keycloak Administration Rest API.

to call the api I need a valid bearer token;  
at now I use a call similar to this:

```auto
curl -X POST \
  https://<HOST>/auth/realms/master/protocol/openid-connect/token \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'cache-control: no-cache' \
  -d 'grant_type=password&username=<USERNAME>l&password=<PASSWORD>&client_id=admin-cli'

```

I retrieve the token and I spend it on my api rest.  
It works but I’m wondering if there is a more elegant and safe way to retrieve the access token without share with the application, that will use the api, the admin username and password.

I’ve try to use a client-id/secret, I retrieve the token but when I use it to access to api i’m not authorized…

thanks!
