API Manager – Auto-Discovery
API auto-discovery is a mechanism that manages an API from API Manager by pairing the deployed application to an API created on the platform.
In this use case we will deploy the application through Anypoint Studio
First update the AnyPoint Studio with Anypoint Platform credentials –same credential will be used to deploy your code in CloudHub.
Add the credential – Goto Window – Preferences – Anypoint Studio – Authentication
Now update organization Client id and secret in AnyPoint Studio
We need to get the credentials from AnyPoint platform – in case you can’t see the option then check with Administrator.
Click on organization name and then copy Client id and Secret
Update the same in AnyPoint Studio and validate it.
Now we need to create the API Manager configuration for the application.
In API Manager – create the API Manager configuration for the mule application – API name will be synced with Exchange assets.
Once saved you can see the API ID under Autodiscovery – please note it down. Also, see the status right now is Unregistered.
Now in mule application we must add the AutoDiscovery configuration – add the Global Elements -> AutoDiscovery -> APP ID which we had noted down in earlier step
Now deploy the application through AnyPoint Studio only – as this will ensure the client id and secret will be pushed from Anypoint Studio to Cloudhub.
Or if we want to deploy the mulesoft application manually or through Maven then please add below properties in your deployment
Under properties tab
anypoint.platform.analytics_base_uri=https://analytics-ingest.anypoint.mulesoft.com/ anypoint.platform.client_id=2ccab1a7dcd94b69b7b1aa93c40af931 anypoint.platform.client_secret=C30fE68A87464438B534eFC47e4da0fB anypoint.platform.base_uri=https://anypoint.mulesoft.com/
Once deployed we can see the application in Mule runtime and logs confirming that its successfully got registered with API manager.
Also, we can access the endpoint now –
Now if we check API manager again then it’s status must change to Active as application is now registered.
Now attach the client policy in API manager for this application
Select credential origin
Now if we hit the same endpoint then we must get authentication error –
Now let’s create client application credential for accessing the application – from Exchange request for the access.
If no SLA tier is defined, then it will take to Client App page
Just note down the client id and secret
Now if we pass this client id and secret then we can access the application.