0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

API Connect on AWSでREST APIを利用してみる

Last updated at Posted at 2025-09-10

API ConnectのREST API

API Connectは機能をREST APIとして呼び出すことが可能です。管理を自動する際に役立ちます。

環境

実行環境として、API Connect on AWSのトライアル環境を利用しています。トライアル環境の申込はこちらです。

資格情報の取得

REST APIの利用についてはこちらにガイドがあります。

credentials.jsonのダウンロード

こちらの記事の"Developers Toolkit(CLI)のダウンロード"の章を参考に、"ツールキット資格情報"をダウンロードします。Developers Toolkitは必要な場合はダウンロードください。
ダウンロードしたcredentials.jsonは以下のような資格情報が含まれます。

credentials.json
{
  "cloud_id": "e8fcdec3-bfb9-44bd-bf90-03d8639c4916",
  "toolkit": {
    "endpoint": "https://example-platform-api.ibm.com/api",
    "client_id": "7ad7b6c5-fa07-4222-808d-8de7266dcd1a",
    "client_secret": "b7127e44-4811-48be-be9d-6591302de04a"
  },
  "consumer_toolkit": {
    "endpoint": "https://example-consumser-api.ibm.com/consumer-api",
    "client_id": "3b10e0db-1cd4-4aa8-af02-51a83e334f1c",
    "client_secret": "a5a672b7-e3b2-4d2b-984b-4059ea82ae65"
  },
  "governance": {
    "endpoint": "https://example-governance.ibm.com/governance",
    "client_id": "ba48537c-7a6e-4232-92b6-ae67ad764933",
    "client_secret": "790d8a6d-e323-46bd-a05c-3d212e93d794"
  },
  "discovery": {
    "endpoint": "https://example-discovery.ibm.com/discovery",
    "client_id": "d872a2f4-bc6e-4e91-b187-bbb5b99d4605",
    "client_secret": "c0b5ddf9-58e6-4246-88de-243ce217731a"
  }
}

4つの資格情報が含まれています。今回は、プロバイダー組織スコープのAPI呼び出しをすることとして、toolkitの資格情報を利用します。

APIキーの作成

こちらの記事の"API ManagerへCLIからログイン"の章を参考に、APIキーを作成します。

Bearer Tokenの取得

credentialss.json内から、toolkit の client_id, client_secret、APIキーをコピーします。リクエスト先は、toolkitのendpointの値+/tokenになります。

curl -v -k -X POST -d '{"api_key": "取得したAPIキー", "client_id": "クライアントID", "client_secret": "クライアントシークレット", "grant_type": "api_key"}' -H 'Content-Type: application/json' -H 'Accept: application/json' https://platform-api.us-east-a.apiconnect.automation.ibm.com/api/token

{
    "access_token": "eyJhbGciOi 略",
    "token_type": "Bearer",
    "expires_in": 28800,
    "refresh_token": "d52c75ee-9752-41b5-af58-e283814eee1e",
    "refresh_expires_in": 31536000
* Connection #0 to host platform-api.us-east-a.apiconnect.automation.ibm.com left intact
}

これで、Bearer Tokenを取得できました。

REST API呼び出し

プロバイダー組織の資格情報でBearer Tokenを取得できたので、プロバイダー組織で実行できるREST APIを実行します。
プロバイダー組織の取得を行います。

% curl -k -X GET --url 'https://platform-api.us-east-a.apiconnect.automation.ibm.com/api/orgs' -H 'Authorization: Bearer eyJhbGciOi 略 '

{
    "total_results": 1,
    "results": [
        {
            "type": "org",
            "org_type": "provider",
            "api_version": "2.0.0",
            "id": "xxxxxxxxxxxx",
            "name": "api-connect-xxxxx",
            "title": "api-connect-xxxx",
            "state": "enabled",
            "owner_url": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/api/user-registries/xxxxxxx",
            "tier_url": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/api/cloud/tiers/xxxxxxxxx",
            "metadata": {
                "active": "true",
                "region": "us-east-1",
                "tenantId": "xxxxxxxxx",
                "accountId": "xxxxxxxxx",
                "productPlan": "apiconnect_trial",
                "tenant_name": "api-connect-xxxxx",
                "accountLevel": "Trial",
                "productTitle": "API Connect",
                "expiration_date": "2025-10-03T01:11:24.000Z",
                "sabaSubscriptionId": "xxxxxxxxxxxxx",
                "tenant_owner_email": "xxxxx@xxxxx.com",
                "hyperscalerProductId": "xxxxxxxxxxxx",
                "enterpriseAccountFlag": "false",
                "enabled_provider_organization": "true"
            },
            "created_at": "2025-09-03T01:12:54.000Z",
            "updated_at": "2025-09-03T01:12:54.000Z",
            "url": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/api/orgs/xxxxxxxxxxxxxxxx"
        }
    ]
}

カタログ組織を対象とする分析データを取得します。

 % curl -k -X GET --url 'https://platform-api.us-east-a.apiconnect.automation.ibm.com/analytics/89b1d81c-de00-453d-8ba3-478f5de4d258/orgs/api-connect-p4-0/events' -H 'Authorization: Bearer eyJhbGciOi 略 '

{
    "total": 120,
    "search_time": 62,
    "offset": 0,
    "limit": 50,
    "next": {
        "href": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/analytics/xxxxxxxxxxxxx/orgs/api-connect-xxxxx/events?offset=50&limit=50"
    },
    "first": {
        "href": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/analytics/xxxxxxxxxxxxx/orgs/api-connect-xxxxx/events?offset=0&limit=50"
    },
    "last": {
        "href": "https://platform-api.us-east-a.apiconnect.automation.ibm.com/analytics/xxxxxxxxxxxxx/orgs/api-connect-xxxxx/events?offset=70&limit=50"
    },
    "events": [
        {
            "@timestamp": "2025-09-08T06:02:12.899821408Z",
            "@version": "1",
            "api_id": "xxxxxxxxxx",
            "api_name": "branches",
            "api_ref": "branches:1.0.0",
            "api_resource_id": "branches:1.0.0:GET:/details",
            "api_type": "REST"

        ---- 略 ----

まとめ

API Connect on AWS のトライアル環境で、REST APIの呼び出しを行いました。


さらに詳しい情報をお探しの方へ

IBMの最新情報、イベント情報、さらに役立つ資料は、以下のIBM Communityでも発信・格納されています。 

最新のトレンドや有益な情報をチェックするために、ぜひご覧ください!

  WebSphere関連の最新情報やディスカッション、イベント情報、技術資料を公開中!

 

  ELMに関する最新のイベント情報、ナレッジ共有、便利なドキュメントをチェック!

 

  Integrationに関する最新のイベント情報、ナレッジ共有、便利なドキュメントをチェック!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?