How To Access Anypoint Platform Services Using REST APIs

Aman Srivastava
Another Integration Blog
3 min readSep 29, 2022

The Anypoint Platform is very important while implementing MuleSoft Projects. Whether we are working on a simple POC or a complex project, we all need the services of the Anypoint Platform.

Anypoint Platform

Anypoint Platform services offer a complete solution for API-led connectivity that enables us to build a network of applications, data, and devices, both on-premises and in the cloud.

REST API

As we know, Representational State Transfer (REST) is an architectural style that defines a set of constraints that we use for creating web services. APIs play a very crucial role in achieving API-led connectivity.

Below I will describe how to use Anypoint Platform using REST APIs. In some cases, you may need to access the Anypoint Platform to debug or solve issues that act as a blocker while implementing the project.

To perform any action on the Anypoint Platform using a REST API, you first need to generate an access token for authorization. If multi-factor authentication is active for your account, the method described below to get an access token using a username and password will not work. In that case, you have to create a connected app first and then you can generate the token.

To generate the access token for a REST API, use the following curl:

curl — location — request POST ‘https://anypoint.mulesoft.com/accounts/login' \

— header ‘Content-Type: application/json’ \

— data-raw ‘{

“username”: “<Anypoint Platform username>”,

“password”: “<Anypoint Platform password>”

}’

In response, you will get an access_token and token_type.

For all the APIs that we are going to use, we have to pass this bearer token in the headers to get authenticated.

To get the organization ID and other details related to your Anypoint account, we can use this curl:

curl — location — request GET ‘https://anypoint.mulesoft.com/accounts/api/me' \

— header ‘Authorization: <Bearer Token>’

We will get a response that includes the organization ID and all other details of the Anypoint account.

To get a detailed list of all assets that are on the Exchange, we can use this curl:

curl --location --request GET 'https://anypoint.mulesoft.com/exchange/api/v1/assets?organizationId=<Anypoint Platform Organization Id>' \

--header 'Authorization: <Bearer Token>\

--header 'Content-Type: application/json'

Sometimes, while trying to upload something on the Exchange through the Maven command, we get a 409 conflict error. On the Exchange, none of the assets or connectors have the same name or asset ID. In this case, we first have to retrieve all the connectors that have been on the Exchange using the API above, then we have to delete the asset ID that is causing the conflict error. We can do this using the curl below:

curl — location — request DELETE ‘https://anypoint.mulesoft.com/exchange/api/v1/organizations/<Your Group ID>/assets/<Your Group ID>/<assetId>/<version>' \
— header ‘Authorization: <Bearer Token>’ \
— header ‘Content-Type: application/json’ \
— header ‘X-Delete-Type: hard-delete’

To get all environments with their client ID and their type in one place, we can call this curl:

curl — location — request GET ‘https://anypoint.mulesoft.com/accounts/api/organizations/<Organization ID>/environments' \
— header ‘Authorization: <Bearer Token>’

We should get a response with all details as shown below.

I appreciate the time you put into reading this, and I hope this article helps you with your MuleSoft journey!

--

--