---
schema_version: "1"
id: d8a68ea33238f92f58cab943cb481bd5d590ec699c7bd0c3e12046eb8c95c9a0
title: Configuring Flex Gateway with the API Manager API Tool
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/flex-conn-manage-public-api.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/flex-conn-manage-public-api
source_site: docs.mulesoft.com
content_type: documentation
content_hash: cd14b72c44581708204ac4dffff576d54925f7901f4f802604558e239383a95a
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
---

# Configuring Flex Gateway with the API Manager API Tool

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

You can configure Flex Gateway in Connected Mode using the API Manager API tool from the
[Anypoint Platform Developer Portal](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/)
instead of using the API Manager user interface through Anypoint Platform. This tool enables you to
use the command line to communicate with API Manager. Use the steps in this tutorial to create,
deploy, apply a policy to, and delete an API instance.

For more information about the API Manager API, see the
[API Manager API documentation](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-manager-api/).

> [!NOTE] To automate these commands using a Jenkins pipeline, see
> [Automate Flex Gateway in Connected Mode Using a Jenkins Pipeline](https://docs.mulesoft.com/gateway/1.12/flex-conn-jenkins-api).

## Before You Begin

Before you can configure Flex Gateway using the API Manager API, complete the following tasks:

1.  [Download Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-install).

2.  [Register and Run Flex Gateway in Connected Mode](https://docs.mulesoft.com/gateway/1.12/flex-conn-reg-run).

3.  [Configure a Connected App](https://docs.mulesoft.com/access-management/connected-apps-developers#create-a-connected-app):

    - Use the **App acts on its behalf (client credentials)** type and include the following scopes:

      - API Manager: **Manage APIs Configuration**, **Manage Policies**, **View Policies**, and
        **Deploy API Proxies**

      - Runtime Manager: **Read Servers**

      - Exchange: **Exchange Viewer**

        You do not have to
        [Register and Run Flex Gateway with a Connected App](https://docs.mulesoft.com/gateway/1.12/flex-conn-reg-run-app) to use the API
        Manager API, but you can use the same Connected App if you include the proper scopes.

    - Save the **Id** and **Secret** of the Connected app you configure.

4.  Collect the group ID, asset ID, and asset version (GAV) of the Exchange asset you want to create
    or apply.

    To collect your GAV from Exchange:

    1.  Go to Exchange.

    2.  Find the asset to add or apply.

    3.  Collect the group ID and asset ID from the URL.

        For example, the IDs collected from the 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/`,
        are:

        - Group ID: `f1e97bc6-315a-4490-82a7-23abe036327`

        - Asset ID: `api-manager-api`

    4.  Collect the asset version from **Latest Stable**.

        For example, the version collected from the API Gateway HTTP basic authentication policy
        template is `1.3.1`.

5.  Collect the following information from your Anypoint Platform instance:

    - **Organization ID** for the organization where you want to run Flex Gateway

      For more information, see
      [Find Your Organization ID](https://docs.mulesoft.com/access-management/managing-business-groups#find-your-organization-id).

    - **Environment ID** for the environment where you want to run Flex Gateway

      For more information, see
      [What API Manager Looks Like](https://docs.mulesoft.com/api-manager/latest/latest-overview-concept#what-api-manager-looks-like).

    - Runtime **Target ID** for the Flex Gateway you want to deploy the API to

      To find the **Target ID**, go to **Anypoint Platform > Runtime Manager > Flex Gateway**.

## Obtain an Authorization token from Access Management

You must obtain an authorization token to make calls using the API Manager API:

1.  Collect the following information:

    - `<connected-app-client-id>`: **Id** of your connected app

    - `<connected-app-client-secret>`: **Secret** of your connected app

2.  Execute the following request to obtain your Authorization Token after replacing the
    placeholders with the following:

    ```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.  Save the returned authorization token.

## Create an API Instance

To create an API instance using the API Manager API:

1.  Collect the following information:

    - `<your-org-id>`: **Organization ID** for the organization where you want to run Flex Gateway

    - `<your-env-id>`: **Environment ID** for the organization where you want to run Flex Gateway

    - `<authorization-token>`: Authorization token collected in the
      [Obtain an Authorization token from Access Management](#obtain-an-authorization-token-from-access-management)
      step

    - API GAV:

      - `<asset-group-id>`: Group ID, obtained from Exchange

      - `<asset-id-from-exchange>`: Asset ID, obtained from Exchange, of the API you want to create

      - `<asset-version>`: Asset version, obtained from Exchange, of the API you want to create

    - `<upstream-uri>`: URI upstream of your API

    - `<your-proxy-uri>`: Proxy URI, a combination of your port and base path for your API instance,
      for example, `http://0.0.0.0:<port-to-populate>/<path>`

2.  Optionally, collect your `"endpointUri"` or remove the `"endpointUri"` field:

    - `<your-consumer-endpoint>`: Consumer endpoint of your API, for example,
      `http://consumer-endpoint.com`

3.  Make a POST request to Anypoint Platform after replacing the sample content:

    ```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.  Save the Instance ID, `"id"`, from the response to deploy, apply a policy, or delete the
    instance.

## Deploy an API Instance

To deploy an API instance using the API Manager API:

1.  Collect the following information:

    - `<instance-id>`: Instance ID, `"id"`, from [Create an API Instance](#create-an-api-instance)

    - `<gateway-version>`: Version of Flex Gateway you are using, for example `1.4.0`

    - `<target-id-from-runtime-manager>`: Target ID collected from runtime manager

2.  Make a POST request to Anypoint Platform after replacing the sample content:

    ```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>"
    }'
    ```

## Apply a Policy

Using the API Manager API, you can only apply Connected Mode policies to a Flex Gateway.

To apply a policy to an API instance using the API Manager API:

1.  Collect the following information:

    - Policy GAV:

      - `<policy-group-id>`: Policy group ID from Exchange

      - `<policy-asset-id>`: Policy asset ID from Exchange, for example `http-basic-authentication`

      - `<policy-asset-version>`: Policy asset version from Exchange, for example `1.3.1`

    - `"configurationData"`: Required configuration parameters for the policy + Each policy has
      unique configuration data fields. The `"username"` and `"password"` fields are an example. To
      find the configuration data for your policy, see
      [Included Policies Directory](https://docs.mulesoft.com/gateway/1.12/policies-included-directory).

2.  Make a POST request to Anypoint Platform after replacing the sample content:

    ```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>"
    }'
    ```

## Delete an API Instance

To delete an API instance using the API Manager API, make a DELETE request to Anypoint Platform
after replacing the sample content:

```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>'
```

## See Also

- [Automating Flex Gateway with a Jenkins Pipeline using the API Manager API](https://docs.mulesoft.com/gateway/1.12/flex-conn-jenkins-api)

- [Anypoint Developer API Manager API](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-manager-api/)
