---
title: "#63 Dynatrace APIでアカウント管理を行うには？ - bearer token の発行-"
description: Dynatrace APIでアカウント管理を行うためのbearer tokenの発行手順を解説します。OAuth2クライアントの作成からbearer tokenの取得まで、必要なステップを説明します。
---

[DynatraceTips ](https://www.iim.co.jp/dynatips)

# [#63 Dynatrace APIでアカウント管理を行うには？ - bearer token の発行-](https://www.iim.co.jp/dynatips/063)

 作成者: [城水（IIMサポートチーム）](https://www.iim.co.jp/dynatips/author/城水iimサポートチーム)｜Mar 2, 2025 10:01:00 PM

#58でご紹介したように、Dynatrace API は大きく3つのカテゴリに分けられます。

##### 皆さまこんにちは、IIMサポートチームです。  

##### このブログではDynatraceのTips等、 気軽に読めて皆さまのお役に立てるようなコンテンツを配信してます。

##### ＊文中、*斜体*になっている単語はDynatrace画面上/ドキュメント内で使用される用語となります 　例）*Service*、*Host *など

##### ＊青色の色掛部分は操作対象のボタンを表しています

##### 今回は Dynatrace APIでアカウント管理を行うには？ - bearer token の発行- がテーマです。

[#58](https://www.iim.co.jp/dynatips/058)でご紹介したように、Dynatrace API は大きく3つのカテゴリに分けられます。

そのうち、アカウント管理用のAPI（[*Account management API*](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/account-management-api) ）を実行する場合は、bearer token の発行が必要になります。

本日は、*bearer token *の発行についての手順をお伝えいたします。

## *bearer token* の取得の流れ

*bearer token *の取得には、次の2ステップを実施する必要があります。

1. *OAuth2 clients *を作成

- アカウント管理のAPIを使用する場合、プロバイダー構成には、*OAuth Client*の資格情報が必要です。

2. *bearer token*を要求

- APIで*bearer token *を呼び出して使用します。

 

### 1. OAuth2 clientsを作成

①アカウント画面表示後、[Identity & access management] ＞ [OAuth clients] をクリックします。

 

② [Create clients] をクリックします。

 

 

③以下の情報を入力、選択します。

- Service user email：APIを実行するユーザ
  
    - アカウント編集権限を持つユーザを入力します。
      
      ※権限がない場合、以下のメッセージが表示されます。

 

④ [Permissions] ＞ [Account] で下記権限を選択

- View users and groups（account-idm-read）
- Manage users and groups（account-idm-write）

 

※ユーザー追加、グループ編集に必要な権限は上記のみですが、実行するAPIに応じて、必要な権限を付与して下さい。

[https://docs.dynatrace.com/docs/shortlink/account-api-authentication#token-scopes](https://docs.dynatrace.com/docs/shortlink/account-api-authentication#token-scopes)

⑤画面下部の [Create client] をクリックします。

 

⑥表示される以下の情報をコピーします。

- Client ID
- Client secret
- Dynatrace account URN

 

※注意: Client secretはこの画面でのみ表示されます（後から確認することはできません）。

　必要に応じて、必ず情報をコピーして保管してください。

 

⑦ [Finish] を選択します。

 

### 2. bearer tokenを要求

※注意: *bearer token *の有効時間は5分（5分を過ぎた場合、再リクエストが必要）となります。

 

*OAuth2 client*を作成した後、API callを介して* Dynatrace SSO *システムに*bearer token *を要求します。  
下記の <Client ID>、<Client_secret>、<Dynatrace account UID> を、先ほどコピーした内容に置き換え、リクエストを行います。

 

`set ClientID=<Client ID>`  
`set Clientsecret=<Client_secret>`  
`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=%ClientID%&client_secret=%Clientsecret%&scope=account-idm-read%20account-idm-write&resource=<Dynatrace account UID>" https://sso.dynatrace.com/sso/oauth2/token`

 

APIの戻り値の例（赤字箇所が *bearer token *に該当します）

`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=%ClientID%&client_secret=%Clientsecret%&scope=account-idm-read%20account-idm-write&resource=urn:dtaccount:xxxxx" https://sso.dynatrace.com/sso/oauth2/token`

`{"scope":"account-idm-read account-idm-write","token_type":"Bearer","expires_in":300,"access_token":“< bearer token >","resource":"urn:dtaccount:xxxxx"}`

 

以上が*bearer token *の作成手順です。

アカウント管理APIを実行する際は、必ず*bearer token *が必要になりますので、ぜひ本手順を参考にしてみてください！

##### 関連リンク：  

[User management API- Dynatrace Docs](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/account-management-api/user-management-api)

[OAuth clients - Dynatrace Docs](https://docs.dynatrace.com/docs/manage/identity-access-management/access-tokens-and-oauth-clients/oauth-clients)

##### [Dynatraceサポートページ：API｜アイ・アイ・エム](https://www.iim.co.jp/products/dynatrace/user/api)

##### <https://www.iim.co.jp/dynatips/022>[#58 Dynatrace APIの活用例](https://www.iim.co.jp/dynatips/058)

##### #63 Dynatrace APIでアカウント管理を行うには？ - bearer token の発行-  については、以上となります。  お読みいただきありがとうございました！ 

##### ※記事執筆時 Dynatrace SaaS Version：1.307

 

 

 

 

 

 

[完全な記事を表示](https://www.iim.co.jp/dynatips/063)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "城水（IIMサポートチーム）"
  },
  "dateModified" : "2025-03-02T22:01:00.909Z",
  "datePublished" : "2025-03-02T22:01:00Z",
  "headline" : "#63 Dynatrace APIでアカウント管理を行うには？ - bearer token の発行-",
  "image" : {
    "@type" : "ImageObject",
    "height" : 1080,
    "url" : "https://19823358.fs1.hubspotusercontent-na1.net/hubfs/19823358/%2363_Dynatrace%20Tips%20%E3%82%AD%E3%83%BC%E3%83%93%E3%82%B8%E3%83%A5%E3%82%A2%E3%83%AB.png",
    "width" : 1920
  },
  "mainEntityOfPage" : "https://www.iim.co.jp/dynatips/063",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "DynatraceTips"
  }
}
```