---
schema_version: "1"
id: 0c8efcae2473f6f7bc9749854ef1d3d8e123c0f85d421b6983891439e1e2b549
title: API Manager API ツールを使用した Flex Gateway の設定
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/gateway/1.9/flex-conn-manage-public-api.md
canonical_url: https://docs.mulesoft.com/jp/gateway/1.9/flex-conn-manage-public-api
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8bdae21f43a167571a0324cc032da160b9b0ab1a3bb8913ed3390a25a88e4c00
description: MuleSoft Documentation Site
release: "1.9"
latest: false
---
# API Manager API ツールを使用した Flex Gateway の設定

Anypoint Platform を介して API Manager ユーザーインターフェースを使用する代わりに、 [Anypoint Platform 開発者ポータル](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/)​から API Manager API ツールを使用して、接続モードで Flex Gateway を設定できます。このツールにより、コマンドラインを使用して API Manager と通信できるようになります。このチュートリアルの手順を使用して、API インスタンスの作成、デプロイ、ポリシーの適用、および削除を行います。

API Manager API についての詳細は、 [API Manager API ドキュメント](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-manager-api/)​を参照してください。

<table><tbody><tr><td class="icon"><i class="fa icon-note" title="Note"></i></td><td class="content">Jenkins パイプラインを使用してこれらのコマンドを自動化するには、​<a href="https://docs.mulesoft.com/jp/gateway/1.9/flex-conn-jenkins-api" class="xref page">「Jenkins Pipeline を使用した接続モードでの Flex Gateway の自動化」</a>​を参照してください。</td></tr></tbody></table>

## [](#始める前に)始める前に

API Manager API を使用して Flex Gateway を設定する前に、次のタスクを完了します。

1. [Flex Gateway をダウンロードします](https://docs.mulesoft.com/jp/gateway/1.9/flex-install)​。
2. [接続モードでの Flex Gateway を登録して実行します](https://docs.mulesoft.com/jp/gateway/1.9/flex-conn-reg-run)​。
3. [接続アプリケーションを設定します](https://docs.mulesoft.com/jp/access-management/connected-apps-developers#create-a-connected-app)​。
    
    - **\[App acts on its behalf (client credentials) (アプリケーションが自身のために行動する (クライアントログイン情報))\]**​ 種別を使用し、以下のスコープを含めます。
        
        - API Manager: **\[Manage API Configuration (API 設定の管理)\]**​、​**\[Manage Policies (ポリシーの管理)\]**​、​**\[View Policies (ポリシーの参照)\]**​、​**\[Deploy API Proxies (API プロキシのデプロイ)\]**
        - Runtime Manager: **\[Read Servers (サーバーの参照)\]**
        - Exchange: **\[Exchange Viewer (Exchange 閲覧者)\]**
            
            API Manager API を使用するために​[接続アプリケーションで Flex Gateway を登録して実行](https://docs.mulesoft.com/jp/gateway/1.9/flex-conn-reg-run-app)​する必要はありませんが、適切なスコープを含めれば同じ接続アプリケーションを使用できます。
    - 設定する接続アプリケーションの ​**ID**​ と​**シークレット**​を保存します。
4. 作成または適用する Exchange アセットのグループ ID、アセット ID、およびアセットバージョン (GAV) を収集します。
    
    Exchange から GAV を収集する手順は、次のとおりです。
    
    1. Exchange に移動します。
    2. 追加または適用するアセットを見つけます。
    3. URL からグループ ID とアセット ID を収集します。
        
        たとえば、API Manager API Exchange URL ​`https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-manager-api/minor/1.0/pages/home/`​ から収集された ID は次のとおりです。
        
        - グループ ID: `f1e97bc6-315a-4490-82a7-23abe036327`
        - アセット ID: `api-manager-api`
    4. **\[Latest Stable (最新の安定バージョン)\]**​ からアセットのバージョンを収集します。
        
        たとえば、API Gateway HTTP 基本認証ポリシーテンプレートから収集されたバージョンは ​`1.3.1`​ です。
5. Anypoint Platform インスタンスから以下の情報を収集します。
    
    - Flex Gateway を実行する組織の​**組織 ID**
        
        詳細は、​[「組織 ID を見つける」](https://docs.mulesoft.com/jp/access-management/organization#find-your-organization-id)​を参照してください。
    - Flex Gateway を実行する環境の​**環境 ID**
        
        詳細は、​[「API Manager の外観」](https://docs.mulesoft.com/jp/api-manager/latest/latest-overview-concept#what-api-manager-looks-like)​を参照してください。
    - API をデプロイする Flex Gateway のランタイム​**対象 ID**
        
        **対象 ID**​ を見つけるには、​**\[Anypoint Platform\] > \[Runtime Manager\] > \[Flex Gateway\]**​ に移動します。

## [](#access-management-アクセス管理-から認証トークンを取得する)\[Access Management (アクセス管理)\] から認証トークンを取得する

API Manager API を使用してコールを行うには、認証トークンを取得する必要があります。

1. 次の情報を収集します。
    
    - `<connected-app-client-id>`​: 接続アプリケーションの ​**ID**
    - `<connected-app-client-secret>`​: 接続アプリケーションの​**シークレット**​。
2. プレースホルダーを次の内容に置き換えたら、次の要求を実行して認証トークンを取得します。
    
    ```ssh
    curl --location --request POST 'https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token' \
    --header 'Content-Type: application/json' \
    --data-raw '{
     "grant_type": "client_credentials",
     "client_id": "<connected-app-client-id>",
     "client_secret": "<connected-app-client-secret>"
    }'
    ```
3. 返された認証トークンを保存します。

## [](#api-インスタンスを作成する)API インスタンスを作成する

API Manager API を使用して API インスタンスを作成する手順は、次のとおりです。

1. 次の情報を収集します。
    
    - `<your-org-id>`​: Flex Gateway を実行する組織の​**組織 ID**
    - `<your-env-id>`​: Flex Gateway を実行する組織の​**環境 ID**
    - `<authorization-token>`​: [「\[Access Management (アクセス管理)\] から認証トークンを取得する」](#obtain-an-authorization-token-from-access-management)​ステップで収集された認証トークン
    - API GAV:
        
        - `<asset-group-id>`​: Exchange から取得したグループ ID
        - `<asset-id-from-exchange>`​: Exchange から取得した、作成する API のアセット ID
        - `<asset-version>`​: Exchange から取得した、作成する API のアセットバージョン
    - `<upstream-uri>`​: API の URI アップストリーム
    - `<your-proxy-uri>`​: プロキシ URI、API インスタンスのポートとベースパスの組み合わせ (例: `http://0.0.0.0:<port-to-populate>/<path>`​)
2. 必要に応じて、​`"endpointUri"`​ を収集するか、​`"endpointUri"`​ 項目を削除します。
    
    - `<your-consumer-endpoint>`​: API のコンシューマーエンドポイント (例: `http://consumer-endpoint.com`​)
3. サンプルコンテンツを置き換えたら、Anypoint Platform に対して POST 要求を実行します。
    
    ```ssh
    curl --location --request POST https://anypoint.mulesoft.com/apimanager/api/v1/organizations/<your-org-id>/environments/<your-env-id>/apis \
    --header 'Authorization: bearer <authorization-token>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
     "spec": {
       "groupId": "<your-org-id>",
       "assetId": "<asset-id-from-exchange>",
       "version": "<asset-version>"
     },
     "endpoint": {
       "deploymentType": "HY",
       "uri": "<upstream-uri>",
       "proxyUri": "<your-proxy-uri>",
       "isCloudHub": null
     },
     "technology": "flexGateway"
     "endpointUri": "<your-consumer-endpoint>" // OPTIONAL
    }'
    ```
4. インスタンスのデプロイ、ポリシーの適用、または削除を行うために、応答からインスタンス ID ​`"id"`​ を保存します。

## [](#api-インスタンスをデプロイする)API インスタンスをデプロイする

API Manager API を使用して API インスタンスをデプロイする手順は、次のとおりです。

1. 次の情報を収集します。
    
    - `<instance-id>`​: [「API インスタンスを作成する」](#create-an-api-instance)​からのインスタンス ID ​`"id"`
    - `<gateway-version>`​: 使用している Flex Gateway のバージョン (例: `1.4.0`​)
    - `<target-id-from-runtime-manager>`​: Runtime Manager から収集された対象 ID
2. サンプルコンテンツを置き換えたら、Anypoint Platform に対して POST 要求を実行します。
    
    ```ssh
    curl --location --request POST 'https://anypoint.mulesoft.com/proxies/xapi/v1/organizations/<your-org-id>/environments/<your-env-id>/apis/<instance-id>/deployments' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: bearer <authorization-token>' \
    --data-raw '{
     "type": "HY",
     "gatewayVersion": "<gateway-version>",
     "targetId": "<target-id-from-runtime-manager>",
     "environmentId": "<your-env-id>"
    }'
    ```

## [](#ポリシーの適用)ポリシーの適用

API Manager API を使用して、接続モードポリシーを Flex Gateway にのみ適用できます。

API Manager API を使用して API インスタンスにポリシーを適用する手順は、次のとおりです。

1. 次の情報を収集します。
    
    - ポリシー GAV:
        
        - `<policy-group-id>`​: Exchange のポリシーグループ ID
        - `<policy-asset-id>`​:Exchange のポリシーアセット ID (例: `http-basic-authentication`​)
        - `<policy-asset-version>`​: Exchange のポリシーアセットバージョン (例: `1.3.1`​)
    - `"configurationData"`​: ポリシーの必須設定パラメーター + Each policy has unique configuration data fields。​`"username"`​ 項目と ​`"password"`​ 項目は一例です。ポリシーの設定データを見つけるには、​[「内部ポリシーディレクトリ」](https://docs.mulesoft.com/jp/gateway/1.9/policies-included-directory)​を参照してください。
2. サンプルコンテンツを置き換えたら、Anypoint Platform に対して POST 要求を実行します。
    
    ```ssh
    curl --location --request POST 'https://anypoint.mulesoft.com/apimanager/api/v1/organizations/<your-org-id>/environments/<your-env-id>/apis/<instance-id>/policies' \
    --header 'Authorization: bearer <authorization-token>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
       "configurationData":{
          "username": "user",
          "password": "test"
         },
        "pointcutData":null,
        "assetId": "<policy-asset-id>",
        "assetVersion": "<policy-asset-version>",
        "groupId": "<policy-group-id>"
    }'
    ```

## [](#api-インスタンスの削除)API インスタンスの削除

API Manager API を使用して API インスタンスを削除するには、サンプルコンテンツを置き換えた後に、Anypoint Platform に対して DELETE 要求を実行します。

```ssh
curl --location --request DELETE 'https://anypoint.mulesoft.com/apimanager/api/v1/organizations/<your-org-id>/environments/<your-env-id>/apis/<instance-id>' \
--header 'Content-Type: application/json' \
--header 'Authorization: bearer <authorization-token>'
```

## [](#関連情報)関連情報

- [Jenkins Pipeline と API Manager API を使用した Flex Gateway の自動化](https://docs.mulesoft.com/jp/gateway/1.9/flex-conn-jenkins-api)
- [Anypoint 開発者 API Manager API](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-manager-api/)