Logging in to a service using the Common REST API


To retrieve data from a service using Common REST API , you must log in to the service.

Before you begin

Log in to the service from which you want to retrieve data, or follow these steps to obtain a list of services that are registered to work with the API. If you already know the name of the service to which you want to log in, you can skip this procedure.

Execute the following POST command:
https://<hostName>:<portNumber>/cra/serviceGateway/services

In curl, the URL resembles the following example:
curl http://localhost:8080/cra/serviceGateway/services

The Services request returns a JSON file listing the registered services. In the following example, the ellipsis at the end indicates that the returned JSON might include additional entries of this structure:

Services JSON
[
   {
       "HOSTIP": "172.11.11.123",
       "STATUS": "ACTIVE",
       "PORT": "22101",
       "WEBSERVICEName": "MVERESTAPI_SYSX_22101",
       "TLS": "N",
       "TYPE": "MV",
       "HOSTCN": "SYSX"
   },
   {
       "HOSTIP": "172.11.11.123",
       "STATUS": "ACTIVE",
       "PORT": "4411",
      "WEBSERVICEName": "MVERESTAPI_SYSX_4411",
       "TLS": "Y",
       "TYPE": "MV",
       "HOSTCN": "SYSX"
   },
   ...
]

To log in to a BMC AMI Ops service

  1. Use one of  the following URLs to log in to a service using the API:
    https://<hostName>:<portNumber>/cra/serviceGateway/services/<serviceName>/loginhttps://<hostName>:<portNumber>/cra/serviceGateway/services/<serviceName>/logon
    The placeholders in the URL are defined as follows:
    • <hostName> is the name of the mainframe host where the CRA server is running.
    • <portNumber> is the port number of the CRA server.
    • <serviceName> is the name of the registered service. For example, in the example JSON code shown above, the name of the first registered service is MVERESTAPI_SYSX_22101.
  2. To set up an HTTP request, in the Header, set the Content-Type to application/json.
  3. Issue the login or logon request. 

    • If using the /login request, do one of the following:
      • In the Body, set the following keys.



        • username=<userName>
        • password=<password>
      • If using client certificate, set Body as { }.
    • If using the /logon request, use an SSL certificate to connect to your BMC AMI Ops Host server or in the Request Parameter set the following keys:
username=<userName>&password=<password>

For example: https://craHost:8080/cra/serviceGateway/services/MV1/logon?username=MYUSERID&password=MyPass

Important

Replace <userName> and <password> with your credentials for logging into the BMC AMI Ops service. This user must have permission to access the data. 

The API returns a JWT user token:

Example of a JWT User Token
{
"userToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

Until you log out or the token expires, you must pass this token in all subsequent requests from the selected service.
For example:

Example of a User Token with a Request
curl -H 'Accept: application/json' -H "Authorization: Bearer 38651614-99ca-4ec8-90ce-334475abc0f4" https://<hostName>:<portNumber>/cra/serviceGateway/services/products/<productName>/views

Important

If you do not log out, the user token expires after the period of inactivity that the timeout value defines. The default timeout value is 15 minutes. For more information, see Managing-Common-REST-API-session-tokens-and-user-tokens .

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*