---
schema_version: "1"
id: 2e97db549f7e1a2ee7500cf68287554b2d78569d334b6e1a237678dd2a004d9e
title: Configuring Mule Gateway API Autodiscovery in a Mule 4 Application
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-gateway/mule-gateway-config-autodiscovery-mule4.md
canonical_url: https://docs.mulesoft.com/mule-gateway/mule-gateway-config-autodiscovery-mule4
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e23d957915c7e68c1861d96b6a851a9498897523274dc54632ce0966199a5d5d
description: MuleSoft Documentation Site
latest: true
---
---
product: Mule Gateway
---

# Configuring Mule Gateway API Autodiscovery in a Mule 4 Application

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

To configure API Autodiscovery in your Mule 4.x application, you must meet the following
requirements:

## Making your API Available in API Manager

The API to which you want to pair your Mule application must be available in API Manager.  
You can either:

- Publish your API in Exchange and import it from there to API Manager.  
  See [To Manage an API from Exchange](https://docs.mulesoft.com/api-manager/latest/create-instance-task-mule).

- Import it directly from your machine.  
  See [To Import an API Instance](https://docs.mulesoft.com/api-manager/latest/api-instance-landing-page) for more details.

API Manager generates an "API ID" identifier for every imported API:

![An HTTP API instance with API Instance ID highlighted](/mulesoft/current/en-us/mule-gateway/_images/api-id.png)

This API ID is required by the Autodiscovery element to identify the API to which you want to pair
your application.

## Configuring API Manager

This step is necessary to instruct API Manager to use your deployed Mule application as the API
proxy itself.

1.  For Managing type, select Basic Endpoint.

2.  Add the Implementation URI that points to the deployed Mule application.

3.  Select the checkmark `Check this box if you are managing this API in Mule 4 or above`.

## Configuring Anypoint Platform Organization Credentials in Mule Runtime

To use Autodiscovery in a Mule application, Mule runtime engine must start with Anypoint Platform
credentials already configured. Learn how to configure your organization credentials based on your
deployment target in
[Configuring Organization Credentials in Mule Runtime 4](https://docs.mulesoft.com/mule-gateway/mule-gateway-org-credentials-mule4).

## Configuring the Autodiscovery Element in Your Mule Application

Within the code of your Mule application, you must configure the `api-gateway:Autodiscovery`
element. The Autodiscovery element points to the specific API in API Manager to which you want to
pair.

> [!TIP] If you configured a proxy endpoint for your API, your autogenerated proxy will already be
> correctly configured with the Autodiscovery element.

XML element

```xml
<api-gateway:autodiscovery
  apiId="${apiId}" (1)
  flowRef="myFlow" /> (2)
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Configure the <code>apiId</code> with the API ID that API Manager assigned to your API.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Set the <code>flowRef</code> element to point to the flow that you want to pair to the API in API Manager. The referenced flow must use an <a href="https://docs.mulesoft.com/http-connector/1.10/http-listener-ref">HTTP Listener</a> component. Other connectors that use HTTP as an underlying transport aren’t supported for policy enforcement.</td></tr></tbody></table>

You can either replace `${apiId}` with your specific value, or you can create a `config.properties`
file where you define it in a key-value fashion: `apiId=[your-specific-value]` and reference it as
`${apiId}` in this configuration.

You can also configure this using Anypoint Studio’s UI:

1.  In your existing flow, select the Global Elements tab in your Mule Configuration File editor.

2.  Click the Create button, and look for the API Autodiscovery global element.

    ![A form for configuring global elements, with API Autodiscovery selected in a dropdown labeled Component configurations](/mulesoft/current/en-us/mule-gateway/_images/auto-discovery-studio-7.png)

3.  Set the API ID and Flow Reference.

    ![A form displaying auto-discovery settings for an API](/mulesoft/current/en-us/mule-gateway/_images/auto-discovery-api-config.png)

    You can also choose to use the `${apiId}` value and reference it from a `config.properties`
    file.

After the element is defined in the application, and the runtime is configured with your Anypoint
Platform credentials, Mule Runtime will automatically track and keep up to date with the API
configuration. defined in API Manager.

## Autodiscovery Configuration

In Mule 4, the API is identified by the API Id and a reference to a Flow where the HTTP listener is
defined using the `<api-gateway:autodiscovery (…​)/>.` element.

## See Also

- [Reviewing Mule Gateway API Autodiscovery concepts](https://docs.mulesoft.com/mule-gateway/mule-gateway-autodiscovery-overview)
