Using Mule CloudHub APIs
Learn about how to access Mule ESB functions programmatically by deploying applications in the CloudHub API environment.
Join the DZone community and get the full member experience.
Join For FreeCloudHub APIs provide a way to access Mule ESB functions programmatically. CloudHub provides many APIs to use in external applications. In this article, some of the important APIs will be discussed.
Where To Get The APIs
All the APIs exposed by Anypoint Platform can be found here. The URL of the Cloudhub APIs can be accessed here. Also, the Mule documentation contains some important information on how to use the Cloudhub APIs. It can be found here .
Deploy Using Cloudhub API
Here in this section, the important and necessary steps to deploy a Mule application using all those APIs in the above section will be discussed.
Login API
First, you will need to get the access token. Here is how to get it:
API Endpoint |
https://anypoint.mulesoft.com/accounts/login |
Method |
POST |
Input |
|
Output |
|
Get Anypoint Platform Account Information
After getting the token, let's get the information about our Anypoint Platform account.
API Endpoint | https://anypoint.mulesoft.com/accounts/api/me |
Method | GET |
Content-Type |
application/json |
Header | Authorization → token we retrieved at Login step |
Output |
|
In the output, the value of our concern is the Organization ID.
Get the Environment ID
The Environment (Development, Production, Quality) ID can be obtained in two ways:
Using CLI tools.
Using the API.
Using CLI tools
Please check this link to install and configure Anypoint CLI. After installing, please log into Anypoint Platform.
After login, execute the following command: account environment list
It will show the environments and their respective IDs.
Using the API
API Endpoint | https://anypoint.mulesoft.com/accounts/api/organizations/{ORGANIZATION_ID}/environments |
Header | Authorization → token we retrieved at Login step |
URI Param | ORGANIZATION_ID → It can be found in the step where we retrieved the Anypoint Platform account information. |
Method | GET |
Content-Type | application/json |
Output |
|
Deploy to the Environment
API Endpoint | https://anypoint.mulesoft.com/cloudhub/api/v2/applications |
Authentication | Basic Authentication → Anypoint Platform Login and Password |
Header | X-ANYPNT-ENV-ID → The environment ID we have retrieved in the previous step |
Method | POST |
Content-Type | multipart/form-data Required parameters are, file → Browse to the zip archive to be deployed appInfoJson →
|
Output |
|
At this step, the application is uploaded to CloudHub but is not yet deployed. To deploy, please use the following API.
Start the Application
API Endpoint | https://anypoint.mulesoft.com/cloudhub/api/applications/{APP_NAME}/status |
Authentication | Basic Authentication → Anypoint Platform Login and Password |
Header | X-ANYPNT-ENV-ID → Environment ID we have extracted |
URI param | APP_NAME → Name of the app to be started |
Method | POST |
Content-Type | application/json |
Input |
|
Output | {} |
Conclusion
In this article, I have discussed some of the important APIs exposed by Cloudhub. For a detailed explanation of all the APIs exposed by CloudHub, please have a look at the developer portal exposed by Anypoint Platform. Interestingly, the mule-maven-plugin is created using all these APIs.
N.B.: All the above APIs have been tested with Postman only.
Opinions expressed by DZone contributors are their own.
Comments