API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Using the consumer API in v10 reserved instance

By RUSSELL FINN posted Fri March 04, 2022 12:23 PM

  
This is a worked example showing how a consumer can authenticate and use the consumer API on a v10 Reserved Instance

First you need a consumer, for example by signing up at the Developer Portal.

Log in to API Manager, and click on the Download Toolkit tile:
Then click the Download link in Step 2 for "Toolkit credentials"


which will download a credentials.json file that looks like this:

> cat credentials.json
{ 
  "cloud_id": "146fcd3e-6761-43cc-a11d-cc08478176c6",
  "toolkit": {
    "endpoint": "https://api.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/api",
    "client_id": "871ed1dc-6f80-41ab-8552-db1ba552b1b5",
    "client_secret": "REDACTED"
  },
  "consumer_toolkit": {
    "endpoint": "https://consumer.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/consumer-api",
    "client_id": "6cb156cc-ab6e-46ca-a7f0-62f6874309a4",
    "client_secret": "REDACTED"
  }
}

The lower block shows the consumer endpoint to use, and also the client_id and client_secret to use in the next step.

Then you get a bearer token, here we are using example values of:

provider org = myporg
catalog = sandbox

> curl -X POST https://consumer.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/consumer-api/token \
-d '{"username":"me@uk.ibm.com", "password":"REDACTED", "realm":"consumer:myporg:sandbox/sandbox-idp", "client_id":"client-id-value-from-earlier","client_secret":"client-secret-from-earlier","grant_type":"password"}' \
-H "Content-Type:application/json" \
-H "Accept:application/json" \
-H "X-IBM-Consumer-Context:myporg.sandbox"
{   
    "access_token": "LONG-REDACTED-TOKEN",
    "token_type": "Bearer",
    "expires_in": 28800
}

The value for realm key takes the format: consumer:<<provider-org>>:<<catalog>>/<<catalog>>-idp

Now you can make a call to the consumer API, for example

curl https://consumer.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/consumer-api/orgs -H "Authorization:Bearer LONG-REDACTED-TOKEN" -H "Content-Type:application/json" -H "Accept:application/json" -H "X-IBM-Consumer-Context:myporg.sandbox"
{
    "total_results": 1,
    "results": [
        {
            "type": "org",
            "api_version": "2.0.0",
            "id": "b6e74bea-b622-4344-ae4c-REDACTED",
            "name": "captain-america",
            "title": "Captain America",
            "summary": "Captain America",
            "state": "enabled",
            "owner_url": "https://consumer.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/consumer-api/user-registries/0765dbbc-b685-4897-b422-REDACTED/users/ebe701cd-ccdd-4710-a4a1-REDACTED",
            "created_at": "2022-02-14T15:39:04.000Z",
            "updated_at": "2022-02-14T15:39:04.000Z",
            "url": "https://consumer.ef29-e2b74a2d.us-east.apiconnect.cloud.ibm.com/consumer-api/orgs/b6e74bea-b622-4344-ae4c-REDACTED",
            "group_urls": []
        }
    ]
}


#APIConnect
#Integration
#v10
0 comments
38 views

Permalink