Using the Platform APIs- Digital Transformation with IBM API Connect
When you are working with any of the web user interfaces (Cloud Admin or API Manager), they are actually utilizing APIs to perform all the tasks you initiate. Those APIs are the Platform APIs. The Platform API interface is constructed when API Connect is initially installed.
When you are creating and managing APIs within API Connect, there will be situations where you have repetitive tasks performed by various roles. These tasks can be added to your DevOps pipeline if you so desire. In this chapter, you will learn what you need to do to execute one of these tasks. For more information on the available APIs, you can visit the following website and peruse the offerings:
https://apic-api.apiconnect.ibmcloud.com/v10/.
The best way to learn about the platform APIs is to learn by example. You’ll learn that next.
Platform API execution
For all the interactions with the API Manager interface, you will require the logon credentials. Since we are invoking APIs, you will need to acquire the necessary Client ID and the secret to invoke your app. Here are the steps to do this:
- You will need to log in to the server. The apic login is required to establish a connection to the API Connect server with the proper credentials to make updates to API Connect:
apic login –username admin –server cloud-admin-
ui.apicisoa.com –realm admin/default-idp-1
Enter your API Connect credentials
Password?
Once you are logged in to cloud-admin successfully, you need to create a consumer application so you can make API calls to the Platform API interface. You do that by registering the app.
2. You must create an application and also get set a client ID and secret. Registering a new application will require you to create a JSON file that provides the details of the application. That includes setting your own client ID and secret. You need to create an input file to pass with the API call. This input file should be created in JSON format. In this example, you can name the file app1.json. Refer to the following code:
{
“name”: “app1book”,
“client_id”: “app1bookid”,
“client_secret”: “app1booksecret”,
“client_type”: “toolkit”
}
Once the file is created, you will run the registration:create command, passing in the server you are interfacing with and the name of the JSON file you just created.
3. You first need to ensure you are authorized to issue these commands to API Connect. Therefore, you must register with API Connect the credentials that you created in step 2. Issue the apic registration:create command as follows:
apic registrations:create –server [your cloud
adminserver] app1.json
A successful response will list out the newly created application name and internal identifier of the application registration. Refer to the following code:
app1book [state: enabled]
https://[your cloudadmin
server/api/cloud/registrations/e40dbb1a-de6a-48c1-
ba9a-a094b1cc3cb9
You don’t have to save the internal identifier. It’s for internal reference only.
You will use client_id and client_secret from step 2 in the next step. You should save the client ID and secret for future use.
4. Now that you have registered your application, the next thing that is required is a bearer token. This token can be used for multiple platform API calls until the token expires (28,800 seconds). The OAuth token is acquired by calling the URL https://[apimserver]/api/token and passing in the relevant information to obtain a bearer token. The data within brackets should be replaced with the proper information for your environment. Using the curl command, you will make a call to the server requesting a token, as follows:
curl -v -k -X POST -d ‘{“username”: “[username]”,
“password”: “[****]”, “realm”: “provider/default-idp-
2″, “client_id”: “[app1bookid]”, “client_secret”:
“[app1booksecret]”, “grant_type”: “password”}’
-H ‘Content-Type: application/json’
-H ‘Accept: application/json’
If successful, you will receive a bearer token that must be included with any Platform API call. A successful message is similar to the following:
{
“access_token”:
“eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjMyNjQ0O
UE4RUFFMEQ5Mjk2RTM4MkYwREQ4RUFGRDVDODc2QTI0QUIifQ.
[…]
-WW_KSdie6Cy6UnEveNWASVDuBg6a6tIXqCTopnPv_5dB-
qk6IFYivAtaZW2rYtDkf6VdMu58cbu6DDBy7UMA7YbsFSdXTwjwvlA
fbY9GDAL4XhqzlLkI5vkm3NdVz0REv_FJxNd5iV1b1TM4nVXO63rEB
Ltc-_hUNBxHfPJwuIHBNo6Qh9d2np3CG1KqSE3Ue5cSoMQIwTXU
AwwPn8oGa2k2lhNeCBxE2kbqYDTHEcBwQZUAV_Q”,
“token_type”: “Bearer”,
“expires_in”: 28800
}
Now that you have a token, you can proceed to call the platform APIs. The steps you just learned will need to be done regardless of which Platform API you wish to call. Next, you’ll learn how to use the publishing Platform API.