Currently the v10 Reserved Instance of API Connect doesn’t yet have a built in option for headless use of the CLI toolkit. The following details how to use an IBM Cloud IAM bearer token with the API Connect CLI and REST API in a headless environment such as a CI/CD pipeline.
For interactive use of the API Connect CLI, you can login using the --sso option, retreive an api key with your browser and provide that to the CLI for example:
apic-slim login --server {apic-api-endpoint} --sso
However if you want to use the CLI in a non-interactive context such as a CI/CD pipeline you need to retrieve an IBM Cloud IAM Bearer token for the toolkit to use. This can be obtained using ibmcloud iam oauth-tokens and then placed in ~/.apiconnect/token for the apic CLI to use.
The token file needs to contain:
{apic-api-endpoint}/api: |
refresh_token: ""
access_token: {access_token}
This can be done programmatically using something like this:
ibmcloud login --apikey {api-key}
ibmcloud iam oauth-tokens | sed "s/IAM token: *Bearer /{apic-api-endpoint}\/api: |\n refresh_token: \"\"\n access_token: /" > ~/.apiconnect/token
apic orgs --my --server {apic-api-endpoint}
production [state: enabled] https://api...apiconnect.cloud.ibm.com/api/orgs/9123ae60-427c-4997-8a6b-ddd75b169bfb
test-porg [state: enabled] https://api...apiconnect.cloud.ibm.com/api/orgs/b73708ea-a7b5-4d27-b562-80767e0b238e
If you're prefer to use the
API Connect REST API, you can make use of the same IAM tokens to call it as
detailed in the documentationOriginally posted on
my personal blog