# Get Token Example

> Example showing how to generate authentication tokens using API Maker system APIs.

Source: https://docs.apimaker.dev/v1/examples/sys/system/getToken.html

`g.sys.system.getToken` calls the [get token system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-token-api.html) from your code, whatever the settings of that API say about HTTP callers.

### Get token using global object 'g'.

- Token of an API Maker API user: no `name`.

```ts
await g.sys.system.getToken({
    "u": "USER_NAME",
    "p": "USER_PASSWORD"
});
```

- Token of a database user (application user): the `name` of its token generator.

```ts
await g.sys.system.getToken({
    "name": "TOKEN_GENERATOR_NAME",
    "u": "USER_NAME",
    "p": "PASSWORD"
});
```

- Both at once: an array in, an array of tokens out.

```ts
const [apiUser, databaseUser] = await g.sys.system.getToken([
    { "u": "USER_NAME", "p": "USER_PASSWORD" },
    { "name": "TOKEN_GENERATOR_NAME", "u": "USER_NAME", "p": "PASSWORD" }
]);
// apiUser.token goes in x-am-authorization, databaseUser.token in x-am-user-authorization
```

## Related

- [Get token system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-token-api.html) · [All system APIs from code](https://docs.apimaker.dev/v1/examples/sys/system/system.html) · [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html)
