Logging in to a service using the Common REST API
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:
{
"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
- 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.
- To set up an HTTP request, in the Header, set the Content-Type to application/json.
- Issue the login or logon request.
- If using the /login request, do one of the following:
- In the Body, set the following keys.
- If using the /login request, do one of the following:
- 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:
For example: https://craHost:8080/cra/serviceGateway/services/MV1/logon?username=MYUSERID&password=MyPass
The API returns 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: