Troubleshooting
Problem
Clarification is needed of how to get and use the Bearer token for calling the REST APIs in the API Connect REST API Documentation
Resolving The Problem
In order to use the API Connect REST APIs, a user needs a Bearer token for authenticating.
To get a Bearer token, you must first set up a client ID and secret. The Obtaining a Client ID and Secret page in the API Connect REST API Documentation provides more details.
Obtaining a Client ID and secret:
Log in to the API Connect server as an admin user by using the
For example
To get a Bearer token, you must first set up a client ID and secret. The Obtaining a Client ID and Secret page in the API Connect REST API Documentation provides more details.
Obtaining a Client ID and secret:
Log in to the API Connect server as an admin user by using the
apic login
command.
For example
apic login --server platform.example.com --username user --password password --realm admin/default-idp-1
After logging in Register an Application
Register an application:
Create a JSON file with your wanted credentials for the application.
For example, app1.json:
Create a JSON file with your wanted credentials for the application.
For example, app1.json:
{
"name": "app1",
"client_id": "app1id",
"client_secret": "app1secret",
"client_type": "toolkit"
}
Register the application from the toolkit:
$ apic registrations:create --server platform.example.com app1.json
app1 https://apic.ibm.com/api/cloud/registrations/51196222-788c-474f-b4c7-0b351ce509de
You now have set up an application with client_id: app1id and client_secret: app1secret
Get the bearer token:
The Obtaining and Using a Bearer Token page in the API Connect REST API Documentation provides more details.
To get the bearer token
Send a curl like:
Send a curl like:
curl -v -k -X POST -d '{"username": "user", "password": "****", "realm": "provider/default-idp-2", "client_id": "registered-app-client-id", "client_secret": "registered-app-client-secret", "grant_type": "password"}' -H 'Content-Type: application/json' -H 'Accept: application/json' https://platform.example.com/api/token
Note:
Replace registered-app-client-id and registered-app-client secret with whatever client ID and secret that you defined in the application you registered.
You get a response like this:
Replace registered-app-client-id and registered-app-client secret with whatever client ID and secret that you defined in the application you registered.
You get a response like this:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1MGVmOGQzOC1lMTUxLTQ4NjctYmIwOS0wNDA0N2UxZjM3NDciLCJuYW1lc3BhY2UiOiIzYjQ1ODU4Ni1kZGMwLTQ1NDYtOThkZi03MmUxMzMzYjA5ZWE6MTYzZD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TA1bmM5MldRX3doNCIsInNjb3BlcyI6WyJjbG91ZDp2aWV3IiwiY2xvdWQ6bWFuYWdlIiwicHJvdmlkZXItb3JnOnZpZXciLCJwcm92aWRlci1vcmc6bWFuYWdlIiwib3JnOnZpZXciLCJvcmc6bWFuYWdlIiwiZHJhZnRzOnZpZXciLCJkcmFmdHM6ZWRpdCIsImNoaWxkOnZpZXciLCJjaGlsZDpjcmVhdGUiLCJjaGlsZDptYW5hZ2UiLCJwcm9kdWN0OnZpZXciLCJwcm9kdWN0OnN0YWdlIiwicHJvZHVjdDptYW5hZ2UiLCJhcHByb3ZhbDp2aWV3IiwiYXBwcm92YWw6bWFuYWdlIiwiYXBpLWFuYWx5dGljczp2aWV3IiwiYXBpLWFuYWx5dGljczptYW5hZ2UiLCJjb25zdW1lci1vcmc6dmlldyIsImNvbnN1bWVyLW9yZzptYW5hZ2UiLCJhcHA6dmlldzphbGwiLCJhcHA6bWFuYWdlOmFsbCIsIm15OnZpZXciLCJteTptYW5hZ2UiLCJ3ZWJob29rOnZpZXciXX0.1ybezGJrJWgRZ8ec5cjyGQTKcWA3iwTbV5AubXCox60",
"token_type": "Bearer",
"expires_in": 28800
}
You can then use the bearer token in the REST API call
For example:
For example:
curl -k -v https://platform.example.com -H 'Authorization: Bearer {value of access_token}' -H 'accept: application/json
Related Information
Document Location
Worldwide
[{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSMNED","label":"IBM API Connect"},"ARM Category":[{"code":"a8m50000000Ce8rAAC","label":"API Connect-\u003EManagement and Monitoring (MM)"}],"ARM Case Number":"TS013824453","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"10.0.0;10.0.1;10.0.5;and future releases"}]
Was this topic helpful?
Document Information
Modified date:
15 August 2023
UID
ibm17025151