1. What is API Autodiscovery?
API Autodiscovery is a mechanism that allows your Mule application (running on CloudHub, Runtime Fabric, or standalone) to automatically link itself with an API instance in API Manager using an Auto-Discovery ID.
This allows API policies to become active without modifying your code.
2. Why Do We Need Autodiscovery?
Without autodiscovery:
API policies will never apply
No analytics will be collected
No alerts or SLAs
No client ID/secret validation
No security enforcement
With autodiscovery:
API Manager policies sync automatically
Security and governance happen without redeploying
API traffic analytics are captured
Versioning becomes easy
Centralized control
3. How API Autodiscovery Works (Internal Flow)
You create an API Instance in API Manager.
MuleSoft assigns an API Autodiscovery ID.
You add this ID in
global.xmlusing the API Autodiscovery element.When your Mule app starts, the runtime:
Reads the autodiscovery ID
Contacts the API Manager
Authenticates using
client_idandclient_secretRetrieves applied policies
Policies are enforced inside your Mule app automatically.
This entire link happens at runtime.
4. Prerequisites
Before starting:
Anypoint Platform account
Access to API Manager
One deployed API on CloudHub or Runtime Fabric
Client ID & Secret (from connected app)
Mule Runtime 4.x
Anypoint Studio / ACB
5. Step-by-Step Working Demo
Below is a complete demo of enabling Autodiscovery in a simple Hello World API.
Step 1 — Create an API in Design Center
Go to Design Center → Create New API
Add a simple RAML:
#%RAML 1.0
title: Hello API /getMessage:
get:
responses:
200:
body:
application/json:
example:
message: "Hello from MuleSoft!"Publish the API to Exchange.
Step 2 — Create an API Instance in API Manager
Go to API Manager → Manage API → Add API
Choose:
API type: “Manage API from Exchange”
Select the RAML
On the next step:
Choose Endpoint With Proxy or Basic Endpoint
Copy the Autodiscovery API ID
Example : 12345678
We will use this in Mule.
Step 3 — Build Mule Application
Example Mule Flow (hello-api.xml):
<flow name="getMessageFlow"> <http:listener config-ref="listener" path="/getMessage" /> <set-payload value='{"message":"Hello from MuleSoft!"}'/> </flow>Step 4 — Add API Autodiscovery in global-config.xml
<api-gateway:autodiscovery apiId="12345678" flowRef="getMessageFlow" />Important Notes:
apiIdmust match API ManagerflowRefmust point to your entry flowNo spaces, no typos
Step 5 — Add the API Platform Client Credentials in properties
Add to mule-artifact.json or application properties:
anypoint.platform.client_id=YOUR_CLIENT_ID anypoint.platform.client_secret=YOUR_CLIENT_SECRETThese credentials authenticate your application with API Manager.
Step 6 — Deploy the App
Deploy to:
✔ CloudHub
✔ Standalone
✔ Runtime Fabric
Once deployed → go to API Manager.
You will see:
Status: Active
Green Connected Icon ✔
It means your API has been successfully discovered.
6. Apply a Policy to Test Autodiscovery
Let’s apply Client ID Enforcement:
Go to API Manager → Policies
Add policy → Client ID Enforcement
Save & Apply
Now test the API without credentials:
GET /getMessageYou will get:
401 Unauthorized Client ID and Client Secret are requiredSend correct headers:
client_id: xxxx client_secret: yyyyNow it returns:
{ "message": "Hello from MuleSoft!" }🎉 Autodiscovery is working perfectly!
7. Common Errors & Fixes
❗ Error 1: “Autodiscovery: API not found”
Reason: Wrong API ID
Fix: Copy API ID again from API Manager.
Error 2: “Client credentials missing”
Fix: Add these to properties:
anypoint.platform.client_id
anypoint.platform.client_secretError 3: “Not registered with platform”
Fix: Application must be deployed (local run won’t work).
Error 4: Using proxy but enabling basic endpoint
Fix: In API Manager → choose Basic Endpoint for Autodiscovery.
8. Best Practices
Always store client credentials in secure properties
Use Basic Endpoint for normal Mule apps
For proxy-based APIs, use Proxy Endpoint
Apply policies only through API Manager—not in Mule code
FAQs
1. What is API Autodiscovery in MuleSoft?
API Autodiscovery is a feature that automatically links a deployed Mule application to an API instance in API Manager so that policies can be applied without changing the code.
2. Why is API Autodiscovery needed?
It enables centralized governance, monitoring, analytics, SLA enforcement, and security policies (like Client ID Enforcement or Rate Limiting) directly from API Manager.
3. Does Autodiscovery work when running the application locally?
No.
Autodiscovery works only when the application is deployed to CloudHub, Runtime Fabric, or Standalone Mule Runtime with proper credentials.
4. Where can I find the API Autodiscovery ID?
In API Manager → Select your API Instance → Autodiscovery Section.
It looks like : 12345678
5. Can I apply policies without Autodiscovery?
No. Without autodiscovery, API Manager cannot detect your Mule app, and policies will not be enforced.




