[Yandex Cloud documentation](../../../index.md) > [Yandex Identity and Access Management](../../index.md) > [Step-by-step guides](../index.md) > Authentication > IAM tokens > Getting an IAM token for a Yandex account

{% note info %}

These methods of getting an [IAM token](../../concepts/authorization/iam-token.md) are intended for requests by a [Yandex user account](../../concepts/users/accounts.md#passport) and are not recommended for automated solutions. If you want to automate your work with the Yandex Cloud API and get IAM tokens in software, see [Getting an IAM token for a service account](create-for-sa.md).

{% endnote %}

# Getting an IAM token for a Yandex account

You can get an IAM token for your Yandex account [using the CLI](#via-cli). You need to install the [YC CLI](../../../cli/index.md) to do it.

{% note info %}

The IAM token [lifetime](../../concepts/authorization/iam-token.md#lifetime) does not exceed 12 hours; however, we recommend requesting a token more often, e.g., every hour.

To have the IAM token reissued automatically, the `export IAM_TOKEN=$(yc iam create-token)` script can be used.

{% endnote %}


## Getting an IAM token using the YC CLI {#via-cli}

{% list tabs group=instructions %}

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  1. [Authenticate in the CLI as a user](../../../cli/operations/authentication/user.md).
  1. Get an IAM token:

      ```bash
      yc iam create-token
      ```

      Result:

      ```text
      t1.9euelZrLop7Uz8up********
      ```

      The value you get is an IAM token. You can copy it, save it to a file, or write it into a variable:

      ```bash
      export IAM_TOKEN=`<IAM_token>`
      ```

{% endlist %}

Specify the received IAM token when accessing Yandex Cloud resources via the API. Provide the IAM token in the `Authorization` header in the following format:

```yaml
Authorization: Bearer <IAM_token>
```

If you have saved your IAM token to a variable, use the latter:

```yaml
Authorization: Bearer ${IAM_TOKEN}
```


## Example of using an IAM token obtained through the CLI {#use-cli}

Sending a request to get a list of clouds using an IAM token:

{% list tabs group=programming_language %}
   
- Bash {#bash}

  1. Get an IAM token and write it to the variable:

     ```bash
     export IAM_TOKEN=`yc iam create-token`
     ```

  1. Send a request to get a list of clouds:

     ```bash
     curl \
       --request GET \
       --header "Authorization: Bearer ${IAM_TOKEN}" \
       https://resource-manager.api.cloud.yandex.net/resource-manager/v1/clouds
     ```

  1. Result:
   
     ```bash
     {
     "clouds": [
       {
       "id": "b1gia87mbaom********",
       "createdAt": "2019-08-19T06:15:54Z",
       "name": "my-cloud-1",
       "organizationId": "my-organization"
       },
       {
       "id": "b1gue7m154kt********",
       "createdAt": "2022-08-29T13:27:03Z",
       "name": "my-cloud-2",
       "organizationId": "my-organization"
       }
     ]
     }
     ```

- PowerShell {#powershell}

  1. Get an IAM token and write it to the variable:

     ```powershell
     $IAM_TOKEN=yc iam create-token
     ```

  1. Send a request to get a list of clouds:

     ```powershell
     curl.exe ` 
       --request GET ` 
       --header "Authorization: Bearer $IAM_TOKEN" ` 
       https://resource-manager.api.cloud.yandex.net/resource-manager/v1/clouds 
     ```

  1. Result:

     ```powershell
     {
     "clouds": [
       {
       "id": "b1gia87mbaom********",
       "createdAt": "2019-08-19T06:15:54Z",
       "name": "my-cloud-1",
       "organizationId": "my-organization"
       },
       {
       "id": "b1gue7m154kt********",
       "createdAt": "2022-08-29T13:27:03Z",
       "name": "my-cloud-2",
       "organizationId": "my-organization"
       }
     ]
     }
     ``` 
   
{% endlist %}


#### Useful links {#see-also}

* [Using an IAM token in a Helm chart](../../../container-registry/operations/helm-chart/helm-chart-push.md)
* [Revoking an IAM token](revoke-iam-token.md)