ARM REST Services
Application Management Examples
Authenticating and Sending Requests
For this API Notebook to work, first execute the code block below. As this example interacts with two different APIs, two different agents must be instanced.
Each of these two agents handles the calls to an API. runtimeManagerClient handles calls to the Runtime Manager API, accessManagementClient handles calls to the Access Management API, which you need for authenticating to the Anypoint Platform before you can make any other calls.
Note: The step of creating these two agents is only necessary when using this interactive example, it is not needed outside this user interface.
Specify your username and password in the cells below and execute the code block. This populates the variables that are needed by the login commands that follow.
Note: You can authenticate using OAuth by presenting a client ID and client secret. See the Access Management API reference.
Log in by sending a POST to the Access Management API, to /login, with a JSON object containing the username and password you provided above. This returns a token. The second line of code constructs a full authorization header with the required structure.
After you get your access token, you can use it to call the Anypoint Access Management API. To send requests to the Runtime Manager API, you need to have both the Organization ID and an Environment ID. Both of these can be obtained from the Access Management API as shown below.
The code block below obtains the Organization ID from the Access Management API:
The code block below obtains the Environment ID from the Access Management API:
Note: This example picks the first listed environment, through the [0] index. You can change this in the code below to pick a different environment. You can check what environments are available and their order by executing only the first of these two lines of code, which returns the whole collection.
Now that you have all of the required tokens and IDs, you can carry out requests to the Runtime Manager API. You must add the authorization token, the organization ID, and the environment ID as headers in each request.
The request below retrieves all alerts in an organization's environment:
The request below creates a new alert that notifies users "jeff.x" and "wai.y" when any server in the environment goes down:
Note: This example includes a fourth header that sets the type of the body as JSON.