It has been long time that I wanted to write a post on how to automate API proxy deployment by only Platform API calls.
Most of the time I do démo with UI to my prospects on API Manager topics and I have always the same question coming from them: “How are we going to add this to our CI/CD pipeline.”
So I have decided to show by only using API calls how we can import your swagger to Anypoint Exchange, Create the proxy, deploy it, add SLA tiers, apply policies, tag it then activate monitoring with only one postman collection.
The steps the collection contains are:
- Import your swagger file to Anypoint Exchange
- Create an API in API Manager from an API in Exchange
- Deploy the API proxy to Runtime Manager
- Add SLA tiers ( Free, Premium) to your API in Anypoint API Manager
- Apply the following policies to your API in Anypoint API Manager:
- Rate Limiting SLA Based policy
- JWT Validation Policy
- Tag your API
- Activate Monitoring and Visualiser on Anypoint Runtime Manager for your API
For this postman collection I have only used the APIs available on Anypoint Platform APIs.
You should run by order the API Calls as it is already ordered in postman collection. Because each API call gets the values from the response and sets the postman environment variables that will be used for the following API calls.
- You should create a connected app (Access Management → Connected Apps) with the following scopes on your choose of Business org and Environment: Runtime Manager, Exchange Contributor, API Manager, CloudHub Org Admin
- Your swagger file
- Your Business Group Name (the name of the business org to which you want to deploy)
- Your Environment Name ( the name of the environment to which your want to deploy)
- Your Environment client_id and client_secret (we need it to activate monitoring)
- Import the Postman Collection file to your Postman ( GitHub repository )
- Import the Postman environment variables to your Postman (GitHub Repository)
The following postman environment variables must be filled in:
- anypoint_host: https://anypoint.mulesoft.com
- connected_app_id: The id of the connected app you have created in the pre-requisite step 1
- connected_app_secret: The id of the connected app you have created in the pre-requisite step 1
- env_name: The name of the environment to which you want to deploy your API. ex: Sandbox, Design or Production
- org_name: The name of Anypoint Business Group to which you want to publish your API
- environment_app_id: your environment client Id that you have get from the pre-requisite step 6
- environment_app_secret: your environment client secret that you have get from the pre-requisite step 6
- domainName: The domain name you want to use as part of your API URI. It will be the identifier of you app in RM, it must be unique. (
domainname
-de-c1.cloudhub.io) - exchangeAssetId: The assetId that will be used in Anypoint Exchange
The very first two steps are the preparation requests to get access token, env_id and org_id
This steps calls the token endpoint to get an access_token to be used as bearer token for the following steps.
- gets acces_token for the connected app that I have created in Anypoint Platform.
- sets the acces_token in postman environment variable to use for the following requests
For the most of the following steps you will need environment id and organisation id. This request calls the accounts/api/profile to get information on your platform (business org, env, ...). The env_name and org_name variable let us to query the response result and extract Ids
Once we have the variable set for: access_token, org_id and env_id, then we can import the swagger to Exchange, create your api in api manager and depoy the proxy instance to CloudHub via runtime manager
This request will add your swagger to exchange. Check the body of the request to customise the parameters. The important one is the asset: you should give the full path to your swagger file as value to asset.
Creates an API in Api Manager from an existing Exchange API (check body of the request if you want to customise it). It sets apiId postman environment variable from the response.
Creates a proxy for the given apiId, domainName(must be unique, it is part of your api url), env_id and env_name
Now your API is imported to exchange, created in API Manager and deployed to Runtime Manager. The following steps are to customise your APIs: SLA Tiers (Subscription), Policies, Tag and activate monitoring on your API.
This request creates a SLA tiers for the given apiId. Check body of the request to customise it
This request creates a SLA tiers for the given apiId. Check body of the request to customise it
You can use this request to check the SLA tiers created previsouly
Applies the standard Rate limiting SLA based policy to your API. This policy wil use the SLA tiers defined in the previous steps.
Add the following tag to your api: ratelimitingSLAbased
Applies the standard JWT validation policy to your API. Check the body of the request to customise your settings.
Add the following tag to your api: jwt
You can query your API manager by tag name. This lets you to tag your API properly to set a context than query easily all APIs with the specific tags
This steps is optional. It lets you to activate monitoring and visualiser on your proxy app in runtime manager.