Hi,
To get access to REST APIs of the Consumer-API ( Consumer-APIs ) a Bearer Token must be generated to get access.
This is similar to the general process for generating a Bearer Token for the other REST APIs available with API Connect v10 ( APIC v10 REST APIs ) which I detailed in a previous blogpost ( here ) but there are notable differences.
Here is how to generate a Bearer Token for calling Consumer-APIs in APIC v10 using a consumer user from the Catalog / Developer Portal:
./apic-slim login
Enter your API Connect credentials
Server? $cloud-url [this is the URL of the Cloud Manager]
Realm? admin/default-idp-1 [see getting started blogpost to check if this the correct realm for your deployment]
Username? USERNAME [your Cloud / Admin level username]
Password? PASSWORD
Logged into $cloud-url successfully
app4consumerAPI.json
{ "name": "app4consumerAPI", "title": "app4consumerAPI", "state": "enabled", "client_type": "consumer_toolkit", "client_id": "specify-a-CLIENT-ID", "client_secret": "specify-a-CLIENT-SECRET" }
./apic-slim registrations:create -s $cloud-url app4consumerAPI.json
app4consumerAPI [state: enabled] $cloud-url
curl -v -k -X POST -d '{"username": "USERNAME", "password": "PASSWORD", "realm": "admin/default-idp-1", "client_id": "CLIENT-ID-for-user-specified", "client_secret": "CLIENT-SECRET-for-user-specified", "grant_type": "password"}' -H 'Content-Type: application/json' -H 'Accept: application/json' $cloud-url/api/token
curl -v -k -X 'POST' -d '{ "name": "app4consumerapi", "title": "app4consumerapi", "state": "enabled", "client_type": "consumer_toolkit", "client_id": "specify-a-CLIENT-ID", "client_secret": "specify-a-CLIENT-SECRET" }' -H 'Accept: application/yaml' -H "Authorization: Bearer $b" -H "Content-Type: application/json" "$cloud-url/api/cloud/registrations"
-
Now get the bearer token (this is in 2 steps: creating a $PAYLOAD variable, which is then pushed into API token call, where {catalog}-idp relates to the name of the identity provider of the Catalog & USERNAME2 / PASSWORD2 are from a consumer user in the Catalog / Developer Portal):
export PAYLOAD='{"username": "USERNAME2", "password": "PASSWORD2", "realm": "consumer:{org}:{catalog}/{catalog}-idp", "client_id": "CLIENT-ID", "client_secret": "CLIENT-SECRET", "grant_type": "password"}'
echo $PAYLOAD | curl -k -X POST -d @- -H "X-IBM-Consumer-Context: {org}.{catalog}" -H 'Content-Type: application/json' -H 'Accept: application/json' $consumer-url/consumer-api/token
I hope you find this blog on the Consumer-API useful.
-------------------------------------------------
Nick Cawood
API Connect Consultant
IBM Hybrid Cloud Integration Expert Labs
IBM UK Ltd
https://www.linkedin.com/in/nickcawood/
-------------------------------------------------
#APIConnect