API のセットアップ
IBM Cloud® Schematics API を使用すると、Schematics で IBM Cloud 機能を自動化することができます。 CLI を使用するには、 CLI を使用するための準備 を参照してください。
サポートされる IBM Cloud® Schematics APIs
、APIエンドポイント、必要なAPIヘッダーとボディ情報の概要については、 Schematics APIドキュメントを参照のこと。
Schematics APIでの作業
Identity and Access Management トークンを使用して認証を行う IBM Cloud® Schematics API の使用方法について説明します。
IBM Cloud Schematics API を使用するには、 IBM Cloud 認証情報とともに生成される IBM Cloud® Identity and Access Management (IAM) トークンを提供する必要があります。 IBM Cloud での認証方法に応じて、IBM Cloud IAM トークンの作成を自動化するための次のオプションから選択できます。
認証オプション | 説明 |
---|---|
IBM Cloud ユーザー名とパスワード | このトピックの手順に従って、 IBM Cloud IAM アクセストークンの作成を完全に自動化できます。 MFA を使用して IBM Cloud で認証する場合、MFA は Web ブラウザーと手動で対話する必要があるため、 IBM Cloud IAM トークンの作成を完全に自動化することはできません。 IBM Cloud IAM トークンの作成を完全に自動化するには、代わりに IBM Cloud API キーを使用する必要があります。 |
IBM Cloud の API キー | IBM Cloud のユーザー名とパスワードを使用する代わりに、 IBM Cloud API キーを使用できます。 IBM Cloud 生成された API キーは、固有の鍵です。 IBM Cloud API キーのベースとは別のアカウントで作成されたワークスペースにアクセスするには、そのアカウントの API キーを生成する必要があります。 |
- IBM Cloud IAM アクセス・トークンを作成します。
API トークン要求の要求本文は、 IBM Cloud 認証方式によって異なります。
IBM Cloud IAM トークンは、API 出力の access_token
フィールドにあります。 次のステップでさらにヘッダー情報を取得するため、IBM Cloud IAM トークンをメモしておきます。
POST `https://iam.cloud.ibm.com/identity/token`
入力パラメーター | 値 |
---|---|
ヘッダー | :Content-Type: application/x-www-form-urlencoded :Authorization:Basic [Yng6Yng=^] Yng6Yng= は、 URL-encoded authorization for username bx and password bx に等しい。 |
IBM Cloud ユーザー名とパスワードの本文 | :grant_type: password :response_type: cloud_iam uaa :username : IBM Cloud username.:password : ご使用の IBM Cloud password.:uaa_client_id: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します。 |
IBM Cloud API キーの本文 | :grant_type: urn:ibm:params:oauth:grant-type:apikey :response_type: cloud_iam uaa :apikey : IBM Cloud API キー:uaa_client_id: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します。 |
IBM Cloud ワンタイム・パスコードの本文 | :grant_type:urn:ibm:params:oauth:grant-type:passcode :response_type: cloud_iam uaa :passcode : IBM Cloud のワンタイム・パスコード。 ibmcloud login --sso を実行し、CLI 出力の指示に従って、Web browser.:uaa_client_id: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します。 |
出力例
{
"access_token": "<iam_access_token>",
"refresh_token": "<iam_refresh_token>",
"uaa_token": "<uaa_token>",
"uaa_refresh_token": "<uaa_refresh_token>",
"token_type": "Bearer",
"expires_in": 3600,
"expiration": 1493747503
"scope": "ibm openid"
}
- 処理対象のトークンのアカウント ID を取得します。
<iam_access_token>
を、前のステップで API 出力の access_token
フィールドから取得した IAM トークンに置き換える。 API出力では、 resources.metadata.guid フィールドに IBM Cloud アカウントの ID を見つけることができます。
GET https://accounts.cloud.ibm.com/coe/v2/accounts
入力パラメーター | 値 |
---|---|
ヘッダー | :Content-Type: application/json :Authorization: bearer <iam_access_token> :Accept: application/json |
出力例
{
"next_url": null,
"total_results": 5,
"resources": [
{
"metadata": {
"guid": "<account_ID>",
"url": "/coe/v2/accounts/<account_ID>",
"created_at": "2020-09-29T02:49:41.842Z",
"updated_at": "2020-08-16T18:56:00.442Z",
"anonymousId": "1111a1aa1a1111a1aa11aa11111a1111"
},
"entity": {
"name": "<account_name>",
}
}
]
}
- IBM Cloud 資格情報と、作業するアカウント ID が含まれる、新しい IBM Cloud IAM トークンを生成します。
IBM Cloud API キーを使用する場合、API キーの作成対象となった IBM Cloud アカウント ID を使用する必要があります。 アカウント B
内の Schematics ワークスペースまたはアクションにアクセスするには、アカウント B
にログインし、アカウント B
に基づく IBM Cloud API キーを作成します。
POST https://iam.cloud.ibm.com/identity/token
入力パラメーター | 値 |
---|---|
ヘッダー | :Content-Type: application/x-www-form-urlencoded :Authorization: Basic Yng6Yng= [^] Yng6Yng= は、ユーザー名 とパスワード の エンコードされた認可に等しい。 bx bx URL |
IBM Cloud ユーザー名とパスワードの本文 | :grant_type: password :response_type: cloud_iam uaa :username : IBM Cloud ユーザー名。 :password : IBM Cloud パスワード。 :uaa_client_ID: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します specified.:bss_account : 前のステップで取得した IBM Cloud アカウント ID。 |
IBM Cloud API キーの本文 | :grant_type: urn:ibm:params:oauth:grant-type:apikey :response_type: cloud_iam uaa :apikey : IBM Cloud API key.:uaa_client_ID: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します specified.:bss_account : 前のステップで取得した IBM Cloud アカウント ID。 |
IBM Cloud ワンタイム・パスコードの本文 | :grant_type:urn:ibm:params:oauth:grant-type:passcode :response_type: cloud_iam uaa :passcode : IBM Cloud パスコード。 :uaa_client_ID: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します。 :bss_account : 前のステップで取得した IBM Cloud のアカウント ID。 |
Example output
{
"access_token": "<iam_token>",
"refresh_token": "<iam_refresh_token>",
"token_type": "Bearer",
"expires_in": 3600,
"expiration": 1493747503
}
IBM Cloud IAMトークンはAPI出力の access_token
、リフレッシュトークンは refresh_token
フィールドにあります。
- Schematics API を使用して、アカウント内のすべてのワークスペースをリストします。
すべてのワークスペースを一覧表示する構文
GET https://schematics.cloud.ibm.com/v1/workspaces/
| Input parameters | Values |
| ----- | --- |
| Header | `Authorization: bearer <iam_token>`|
{: caption="Input parameters to work with the IBM Cloud Schematics API." caption-side="top"}
特定のワークスペースに関する情報を取得するための構文:
GET https://schematics.cloud.ibm.com/v1/workspaces/{id}
入力パラメーター | 値 |
---|---|
ヘッダー | Authorization: bearer <iam_token> : IBM Cloud の IAM アクセス・トークン。 |
パス | id <workspace_ID> : ワークスペースの ID です。 ワークスペース ID を取得するには、ibmcloud schematics workspace list を実行します |
- サポートされる
APIs
のリストについては、 IBM Cloud Schematics API 資料 を参照してください。
IBM Cloud IAM アクセストークンをリフレッシュし、API で新しいトークンを取得する
IBM Cloud® Identity and Access Management (IAM) アクセス・トークンは、1 時間後に有効期限が切れます。 IBM Cloud API へのアクセスを確保するには、アクセス・トークンを定期的にリフレッシュする必要があります。 同じ手順で新しいトークンを取得できます。
開始する前に、有効な IBM Cloud IAM リフレッシュ・トークン、または新しいアクセストークンをリクエストするために使用できる IBM Cloud API キーがあることを確認してください。
- リフレッシュ・トークン: IBM Cloud API を使用したワークスペースの作成と管理のプロセスの自動化 の説明に従います。
- APIキー あなたの IBM Cloud APIキーを取得します。
- メニュー・バーから、「管理」 > **「アクセス (IAM)」**をクリックします。
- **「ユーザー」**ページをクリックして、自分を選択します。
- API キー ペインで、IBM Cloud API キーの作成をクリックします。
- API キーの**「名前」と「説明」を入力し、「作成」**をクリックします。
- **「表示」**をクリックして、生成された API キーを確認します。
- API キーをコピーして、新しい IBM Cloud IAM アクセス・トークンを取得できるようにします。
IBM Cloud IAM トークンを作成する場合、または新しいリフレッシュ・トークンを取得する場合は、以下の手順を使用します。
- リフレッシュ・トークンまたは IBM Cloud API キーを使用して、新しい IBM Cloud IAM アクセス・トークンを生成します。
POST https://iam.cloud.ibm.com/identity/token
入力パラメーター | 値 |
---|---|
ヘッダー | :Content-Type: application/x-www-form-urlencoded :Authorization: Basic Yng6Yng= Yng6Yng= は、ユーザー名 とパスワード の エンコードされた認可に等しい。 bx bx URL |
リフレッシュ・トークン使用時の本体 | :grant_type: refresh_token :response_type: cloud_iam uaa :refresh_token: IBM Cloud IAM リフレッシュ・トークン。 :uaa_client_ID: cf :uaa_client_secret: :bss_account: IBM Cloud
アカウント ID。 uaa_client_secret キーは値を指定せずに追加します。 |
IBM Cloud API キー使用時の本体 | :grant_type: urn:ibm:params:oauth:grant-type:apikey :response_type: cloud_iam uaa :apikey: IBM Cloud API キー。 :uaa_client_ID: cf :uaa_client_secret: 値を指定せずに uaa_client_secret キーを追加します。 |
API 出力の例
{
"access_token": "<iam_token>",
"refresh_token": "<iam_refresh_token>",
"uaa_token": "<uaa_token>",
"uaa_refresh_token": "<uaa_refresh_token>",
"token_type": "Bearer",
"expires_in": 3600,
"expiration": 1493747503
}
新しい IBM Cloud IAM トークンは access_token
に、リフレッシュトークンは API 出力の refresh_token
フィールドにあります。
- 前のステップで取得したトークンを使用して、 IBM Cloud Schematics API ドキュメントで作業を続行します。