MuleSoft

Deploy A Mule Application On Cloud Hub Using REST APIs

Overview: –

  • The MuleSoft Platform API provides a set of RESTful APIs that allow you to programmatically manage your Anypoint Platform resources, such as applications, APIs, users, and other components.
  • These APIs enable automation, integration, and efficient management of key resources, including applications, APIs, users, and environments. By using these APIs, developers can streamline tasks such as deploying applications, managing API lifecycles, configuring environments, and administering user roles, enhancing the overall functionality and efficiency.

What Are MuleSoft Platform APIs?: –

  • MuleSoft Platform APIs are a collection of RESTful web services that allow developers to manage their Anypoint Platform resources efficiently.
  • The APIs provide endpoints for managing different resources within the Anypoint Platform, including:
    • Create, update, delete, and deploy Mule applications on CloudHub.
    • Manage APIs, including creating new APIs, applying policies, and monitoring API performance.
    • Manage user accounts, roles, and permissions within the Anypoint Platform.
  • MuleSoft provides detailed documentation for each API endpoint, making it easier for developers to understand how to use them effectively.

Click here Anypoint Exchange (mulesoft.com)

  • To access the APIs, developers must authenticate using OAuth 2.0, which involves obtaining an access token that grants permission to perform actions on specified resources.

Prerequisites: –

  • Before we dive into the deployment process, ensure you have the following:
    • Anypoint Platform account
    • Mule application as a deployable JAR file.
    • Postman or any REST client for testing API calls. (here I’m using Postman)

Steps to deploy the Mule application: –

  • To access Platform APIs, you must obtain a token from either the login endpoint or the OAuth authorization process. After obtaining a token, you can access the API by supplying the token in the authorization header.
  • To authenticate using a username and password, you must invoke the /login API. This API receives a username and password via a JSON request. In return, you receive an access token that you can use to access APIs. The Content-Type header must be set to application/json.

Step 1: Open Postman, configure as shown below, and hit the API

POST https://anypoint.mulesoft.com/accounts/login

Content-Type: application/json

Body:

    {

“username”:”ANYPOINT_PLATFORM_USERNAME”,

“password”:”ANYPOINT_PLATFORM_PASSWORD”

     }

Note: – If you are getting any response like an invalid csrf token then remove _csrf file from the cookies

Step 2: Copy the generated taken and in the postman click on Authorization and select Auth type as “Bearer Token” and paste the generated token.

Note: – This token must be included in every request to access the Platform APIs. Make sure to pass it with every request moving forward. If the token expires then generate a new token.

  • We need an environment ID to deploy our application in a particular environment to obtain that we need an organization ID. We can get organization using /profile API. 

Step 1: Paste the given endpoint in Postman, provide the Authorization token, and hit request.

GET https://anypoint.mulesoft.com/accounts/api/profile

Now you can check that we got organizationId in the response and copy that.

Step 2: Now, we can get all the environments using organizationId. Replace the placeholder with your organization id for the below endpoint and hit the request.

GET https://anypoint.mulesoft.com/accounts/api/organizations/${OrgIDss}/environments

Now, We’ll get all the environment details present in your organization and check for the environment Name where you are going to deploy your application and copy Id. (Here I’m deploying the application to the Sandbox environment)

  • Now we can deploy our application to the select environment using environment Id

Step 3: Provide the endpoint below and configure headers and body as below

POST https://anypoint.mulesoft.com/cloudhub/api/v2/applications

Headers: –

       X-ANYPNT-ENV-ID : ${EnvironmentID}

Content-Type: multipart/form-data

Body: -we are sending a multipart form-data request with three key-value pairs

       file : ${attach Mule jar file}

       appInfoJson:{

“domain”: “mule-blog-demo”,

“muleVersion”: {

“version”: “4.7.0”

},

“region”: “us-east-1”,

“monitoringEnabled”: true,

“monitoringAutoRestart”: true,

“workers”: {

“amount”: 1,

“type”: {

“name”: “Micro”,

“weight”: 0.1,

“cpu”: “0.1 vCore”,

“memory”: “500 MB memory”

}

},

“loggingNgEnabled”: true,

“persistentQueues”: false,

“objectStoreV1”: false

}

       autoStart: true

To send content-type as multipart/from data through postman then select form data and to upload jar file select file from drop for the key then upload file.

Configure all the properties in appInfoJson data and autoStart is use to start the application once it is deployed.

Once you hit the request, you’ll get a response like this:

Log into the Anypoint Platform, then go to Runtime Manager to confirm that the application has been deployed and is running.



Author

Teja Dannina

Leave a comment

Your email address will not be published. Required fields are marked *