Anypoint Platform APIs

 

In this Tutorial we will make you understand how to use “Anypoint platform APIs” for various housekeeping tasks. These APIs can perform most of the tasks which you can do in Anypoint platform UI. These APIs can help you automate tasks related to MuleSoft in your organization. These APIs can also be used in your Devops pipeline to automate various tasks. e.g Getting a list of client applications, getting list of users in your organizations , reset client secret of a client application etc

 

You can find more details on the platform API specification at https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/api-platform-api/ .

 

We have demonstrated a use cases using the platform APIs to filter out the users who have not logged in within last month. Here are the steps in details.

 

Getting Bearer token to login to Anypoint Platform API.

 

This is the first step in getting access to Anypoint platform APIs. Getting Bearer token varies with respect to the access set up to login the Anypoint Platform.

Federated user – For SSO enabled login to MuleSoft Anypoint platform, we need to get SAML token to get Bearer Token to login to Anypoint Platform APIs.

To get the SAML token for your Annypoint platform login, use the browser’s developer tools. We have used firefox as an example below. Before logging into Anypoint platform, open the debugger tools. This will capture the SAML token during the process of login to Anypoint platform.

Open Settings> Web Developer > Debugger

 

Login to SSO URL of your Organization’s  Anypoint Platform account. After successful login, just save the HAR “Save All As HAR” file shown in the screenshot below.

 

Open the saved *.HAR file and search with “SAMLResponse” Use the value of the SAMLResponse field in the API call below

 

Request

POST /accounts/login/receive-id HTTP/1.1
Host: anypoint.mulesoft.com
X-Requested-With: XMLHttpRequest
Content-Type: application/json
{
  "SAMLResponse": "value retrieved "
}

Response

{
  "access_token": "as3338-as-a33s-as-eff5a2sda45a3876",
  "token_type": "bearer",
  "redirectUrl": "/home/"
}

Non-Federated user – for Non-Federated users, they can simply use username and password to get the Bearer Token as below

Request

POST /accounts/login HTTP/1.1
Host: anypoint.mulesoft.com
Content-Type: application/json
{
  "username": "username",
  "password": "password"
}

Response

{
  "access_token": "as3338-as-a33s-as-eff5a2sda45a3876",
  "token_type": "bearer",
  "redirectUrl": "/home/"
}

We will now use the above generated Bearer token to demonstrate few use cases which will internally use the Platform APIs.

 

Get list of users who have not logged in the last one month

 

We will demonstrate the use case to get the list of users not logged in last one month. Use the request as below to get the list of all the users in your organization and then filter them based on response field “lastLogin

GET /apiplatform/repository/v2/organizations/{organization id}/users HTTP/1.1

Host: anypoint.mulesoft.com

Authorization: Bearer {Bearer Token generated as shown in first step}

 
Response

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments