Javascript for Anypoint API Management

Usage no npm install needed!

<script type="module">
  import anypointUtils from '';



npm downloads Build Status

This npm package provides utility methods that can be used within your CI/CD environment and MuleSoft API release management strategy. MuleSoft provides REST API resources for managing your Mule products and hostings on Cloudhub or On-Premise.


$ npm install anypoint-utils --save

Example Code (with use of corp proxy)

// tmp.js

const AnypointUtils = require('./main');
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });

const s = new AnypointUtils('user', 'password', '');

async function main() {
  const authtoken = await s.getToken();`token: ${authtoken}`);

  const orgId = await AnypointUtils.getOrganizationId(authtoken);`orgId: ${orgId}`);

  const stuff = await AnypointUtils.createApiManagerInstance(authtoken, 'emp-xapi', '1.0.0', orgId, 'Sandbox2');`This id is used for API auto-discovery. Id:${stuff}`);


Note: if proxy not used, send 'null'


These are the current functions that have been coded so far. A listing is given here with comments for your reference.


This function takes an active bearer token and returns an organization id in the same form/syntax of the token.


This function returns the environment id that is set as default by the user that supplied the credentials for the bearer token (authenticated).


This function returns a JSON array of environments that are associated to the authenticated user.


This function returns a JSON array of client applications that are associated to the authenticated user.


This function returns a JSON array of APIs (needs closer review).


This function returns a JSON array of "instanced" APIs that are associated to the authenticated user.


This function returns the organization id and business group ids from Exchange that are associated to the authenticated user.

getExchangeAssetById(token, groupId, assetId)

This function returns an Exchange asset by giving the group id and the asset id (name).


This function returns all Exchange assets visible to the authenticated user. This function is not very useful. Needs a filter.

createClientApplication(token, clientName)

This function creates a new client application. This client application is a representational object of either an API or an external API consumer. The client application will be requesting access to registered (running) APIs. These API's should already be in Exchange as managed assets.

deleteApplication(token, appId)

This function will delete a client application (remember it's a representational object only) using a bearer token (authorization) and the client application's application id or primary key.

getApplicationIdByName(token, applicationName)

This function gets the application id for client application name given, along with the bearer token (authorization) of course.

getApiIdByName(token, apiName)

This function gets the API id for the API name or artifact id given.

getApi(token, apiId)

This function returns a JSON object representing the API for the API id given.

getVersionId(token, apiId, productVersion)

This function returns a version id for the API id and productVersion (e.g. v1) given.

createApiManagerInstance(token, assetId, version, groupId)

This function creates an unregistered API instance in API Manager. The function returns an API id for use with runtime API auto-discovery.

createContractWithAsset(token, clientAppName, primeArtifactName)

This function creates a contract between a client application and a registered API to be consumed. Refactoring is needed because this calls another function that really does the work.

isClientApplicationByName(token, clientApplicationName)

This function returns true if the named client application exists that's related to the authenticated user sending the bearer token (authorization) also.

promoteApiCreatingNewInstance(token, organizationId, environmentId, originalApiId)

This function essentially promotes an existing (registered) API into a new environment, specified by the environment id, and using the original API id. A new API id for runtime auto-discovery is returned by the function.

getEnvironmentIdByName(token, environmentName)

This function returns the id for the environment name given.


As of version 1.0.18 there are still many additions needed to this, however they will be added as work requires them. The createContractWithAssetfunction requires refactoring. Updates will be noted with future releases of this package.