June 9, 2020 By Kazuki Nobutani 3 min read

IBM API Connect offers a series of APIs that allow users to have better control over the API Connect instances on IBM Cloud.

These APIs must be accessed using a token-based authentication called JSON Web Token (JWT) for improved security. 

Prerequisites

Goal

In this post, I am going to show you how to obtain the JWT token using a curl command, and then I’ll call an API to get a list of products in a catalog from the developer portal as a demo. 

On top of the JWT token, this particular API requires the following header and a parameter when you call it via CURL. Steps 2 and 3 will cover how to obtain necessary elements:

  • Header: X-IBM-APIManagement-Context:<providerOrg>.<Catalog> 
  • Parameter: originURL, which is the URL of your API Connect developer portal

Please note that required headers and parameters vary depending on the API. 

Step 1. Obtain the JWT token

Run the following command to obtain the JWT token:

curl -k -i -X POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "Accept: application/json" \
https://login.service.<REGION>.apiconnect.ibmcloud.com/apikey?apikey=<APIKEY>

Replace <APIKEY> with the API key you have and change <REGION> to the region where your instance is deployed:

  • Sydney = au
  • Dallas = us
  • Washington = us-east
  • London = eu
  • Frankfurt = eu-de 

CURL command example:

curl -k -i -X POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "Accept: application/json" \
https://login.service.us.apiconnect.ibmcloud.com/apikey?apikey=0123456789F1C4dbHedPjBEsOiKnOovbbZabcdefg

Response example: 

The response contains the JWT token. You need this token when you call APIs, so copy and paste it somewhere secure:

{"jwt":"eyJhbGciOiJFUzM4NCIsInR5cC.....4Tcsbokc4"}

Step 2. Find the catalog name

Each catalog in your API Connect has its display name and a short name. We are going to use the short name when we call APIs, and here is how to find it:

  1. Open API Connect from the IBM Cloud Dashboard:
  2. Open a catalog published to the developer portal.
  3. Go to the Settings > Overview tab and look for the Name:

Step 3. Find the provider organization

Provider organization is a name assigned to your API Connect instance. When you call APIs, you can use either the provider organization name or ID. We used the following API to look up the configuration details of a portal based on its originURL:

curl -k -i -X GET https://apimanager.<REGION>.apiconnect.cloud.ibm.com/v1/portal/config?originURL=<DEV PORTAL>

Replace <REGION> with the region where your instance is deployed and change <DEV PORTAL> to your developer portal home URL:

  • Sydney = au-syd
  • Dallas = us-south
  • Washington = us-east
  • London = eu-gb
  • Frankfurt = eu-de

CURL command example:

curl -k -i -X GET https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/config?originURL=https://sandbox-ORG-SPACE.developer.us.apiconnect.ibmcloud.com/

Response example:

{"expired":false,"applicationLifecycleEnabled":false,"orgID":"PROVIDER ORG ID","orgName":"PROVIDER ORG NAME" ... "apim","realm":null,"writable":true,"isCaseSensitive":false},"paymentGateways":[]}

Step 4. Invoke Manager API

It’s time to get the product list. As per the document, we are calling this API endpoint using CURL:

curl -k -i -H "X-IBM-APIManagement-Context: <providerOrgNAME/ID>.<Catalog>" \
-X GET https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/products \
-H 'Authorization: Bearer <JWT token>'

Replace <JWT token> with the JWT token obtained in Step 1. Change <providerOrgNAME/ID> and <Catalog> to the provider organization name or ID and the catalog short name obtained in Steps 2 and 3. Then, replace <REGION> with the region where your instance is deployed.

  • Sydney = au-syd
  • Dallas = us-south
  • Washington = us-east
  • London = eu-gb
  • Frankfurt = eu-de

CURL command example:

curl -k -i -H "X-IBM-APIManagement-Context: 123459970cf25013613be87e.sandbox" \
-X GET https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/products \
-H 'Authorization: Bearer eyJhbG...csbokc4'

Response example:

[{"id":"PRODUCT ID 1","info":{"name":"PRODUCT NAME 1","title":"PRODUCT TITLE 1","version":"1.0.0"},"url":"https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/products/PRODUCT ID 1","status":"published"},

{"id":"PRODUCT ID 2","info":{"name":"PRODUCT NAME 2","title":"PRODUCT TITLE 2","version":"1.0.0"},"url":"https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/products/PRODUCT ID 2","status":"published"},

{"id":"PRODUCT ID 3","info":{"name":"PRODUCT NAME 3","title":"PRODUCT TITLE 3","version":"1.0.0"},"url":"https://apimanager.us-south.apiconnect.cloud.ibm.com/v1/portal/products/PRODUCT ID 3","status":"published"},]

What’s next?

IBM API Connect offers a number of different APIs and now you are ready to explore the options. Please refer to the IBM Knowledge Center for IBM API Connect for the available API list.

For any questions or concerns, please contact IBM Cloud Support.

More from Cloud

Data center consolidation: Strategy and best practices

7 min read - The modern pace of data creation is staggering. The average organization produces data constantly—perhaps even continuously—and soon it’s investing in servers to provide ample storage for that information. In time, and probably sooner than expected, the organization accrues more data and outgrows that server, so it invests in multiple servers. Or that company could tie into a data center, which is built to accommodate even larger warehouses of information. But the creation of new data never slows for long. And…

Hybrid cloud examples, applications and use cases

7 min read - To keep pace with the dynamic environment of digitally-driven business, organizations continue to embrace hybrid cloud, which combines and unifies public cloud, private cloud and on-premises infrastructure, while providing orchestration, management and application portability across all three. According to the IBM Transformation Index: State of Cloud, a 2022 survey commissioned by IBM and conducted by an independent research firm, more than 77% of business and IT professionals say they have adopted a hybrid cloud approach. By creating an agile, flexible and…

Tokens and login sessions in IBM Cloud

9 min read - IBM Cloud authentication and authorization relies on the industry-standard protocol OAuth 2.0. You can read more about OAuth 2.0 in RFC 6749—The OAuth 2.0 Authorization Framework. Like most adopters of OAuth 2.0, IBM has also extended some of OAuth 2.0 functionality to meet the requirements of IBM Cloud and its customers. Access and refresh tokens As specified in RFC 6749, applications are getting an access token to represent the identity that has been authenticated and its permissions. Additionally, in IBM…

How to move from IBM Cloud Functions to IBM Code Engine

5 min read - When migrating off IBM Cloud Functions, IBM Cloud Code Engine is one of the possible deployment targets. Code Engine offers apps, jobs and (recently function) that you can (or need) to pick from. In this post, we provide some discussion points and share tips and tricks on how to work with Code Engine functions. IBM Cloud Code Engine is a fully managed, serverless platform to (not only) run your containerized workloads. It has evolved a lot since March 2021, when…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters