Apic Cli
APIC CLI Cheatsheet
This is intended to be a cheatsheet and quick reference for working with the APIC CLI tool. Always refer to the knowledge center if more details are needed
Table of Contents
- APIC CLI Cheatsheet
- Scripting Commands
- Login
- Working with APIs
- Creating Draft API
- Creating Draft Product and Publishing
- Replacing the Product
- Create Another New API/Product
- Download APIs and Products
- Add Third OAuth Provider
- Cloud Manager Mail Server
Scripting Commands
First run before running commands with apic
CLI for the first time.
apic --accept-license
Gather your URLs and other often referenced values and set them as variables for convenience.
api_mgmt='manager.apic-v10.ibm.com'cloud_mgmt='admin.apic-v10.ibm.com'catalog='sandbox'org='shellorg'username=<APIM_USERNAME>password=<APIM_PASSWORD>
Login
Realm
- Realm for API Manager local user registry:
provider/default-idp-2
- Realm for Cloud Manager local user registry:
admin/default-idp-1
apic client-creds:set ./eks3node-creds.json
API Manager
Manual Login with Local User
apic login --server $api_mgmt --username $username --password $password --realm provider/default-idp-2
Cloud Manager
Realm for local user registry: admin/default-idp-1
cm_username=<CMGR_USERNAME>cm_password=<CMGR_PASSWORD>apic login --server $cloud_mgmt --username $cm_username --$cm_password --realm admin/default-idp-1
SSO (OIDC Registry Types)
apic login --server $api_mgmt --sso
When prompted for Context?
, type provider
. Then open the browser and login with the OIDC user account. Paste in API key in the terminal after successful login in the browser.
Note: if you don't get the API key screen after logging in and instead APIC looks like it logs you in regularly, try a different browswer or clearly your cache.
Working with APIs
Creating Draft API
Get List of APIs in Sandbox catalog
apic apis:list-all --scope catalog --server $api_mgmt --catalog $catalog --org $org
Create a draft of an API. This will create the API in API Manager but it is not associated with any products yet.
apic draft-apis:create --server $api_mgmt --org $org example-yamls/find-branch-api-1.0.0.yaml
Creating Draft Product and Publishing
Get List of Products
apic products:list-all --server $api_mgmt --org $org --catalog $catalog --scope catalog
Create a draft of a product containing the above API
apic draft-products:create --server $api_mgmt --org $org example-yamls/branch-product-1.0.0.yaml
Publish the draft product above. The CLI product:publish
requires the $ref
to the API yaml in order
to publish the product (but not for draft)
apic products:publish --server $api_mgmt --catalog $catalog --org $org example-yamls/branch-product-1.0.0.yaml
Replacing the Product
Now a product containing the 1.0.0
of the API is published. Note that the 1.0.0 find branch API is pointing to an improper backend URL. So let's say we've created find branch 2.0.0 to update the backend URL so that it works properly, and we'll replace the product with the new version, so subscriptions will migrate automatically.
We first create draft of the new version API and create a new draft a product that references the new API.
# Create a new draft APIapic draft-apis:create --server $api_mgmt --org $org example-yamls/find-branch-api-2.0.0.yaml# Create a new draft productapic draft-products:create --server $api_mgmt --org $org example-yamls/branch-product-2.0.0.yaml
# Grab the previously published product (in this case we're interested in find-branch-product:1.0.0)product_url=$(apic products:list-all --server $api_mgmt --org $org --catalog $catalog --scope catalog | grep 'find-branch-product:1.0.0.*published' | awk '{print $4}')product_url="product_url: ${product_url}"echo $product_url
Generate product mapping file (docs here for product mapping file format).
echo ${product_url}>product-map.txtecho "plans:">>product-map.txtecho "- source: default">>product-map.txtecho " target: default">>product-map.txt
Create the new draft product, stage it, and then use it to replace the old one.
Note the product given in this command is the name of the product that will replace the old product. The product identified in the mapping file is the product being replaced.
# Stage new productapic products:publish --server $api_mgmt --catalog $catalog --org $org --stage example-yamls/branch-product-2.0.0.yaml# Replace published 1.0.0 product with staged 2.0.0 productapic products:replace --server $api_mgmt --org $org --scope catalog --catalog sandbox find-branch-product:2.0.0 product-map.txt
Create Another New API/Product
apic draft-apis:create --server $api_mgmt --org $org example-yamls/find-branch-api-3.0.0.yamlapic draft-products:create --server $api_mgmt --org $org example-yamls/branch-product-3.0.0.yamlapic products:publish --server $api_mgmt --catalog $catalog --org $org example-yamls/branch-product-3.0.0.yaml
Download APIs and Products
Download APIs and Products from the catalog. Use the flag --output
to specify where to save the files, or
show in standard output (--output -
).
Get single API
# List all APIs in the catalogapic apis:list-all --server $api_mgmt --org $org --catalog $catalog --scope catalog# Download single API from the catalog - this will create a file locally called findbranch_2.0.0.yamlapic apis:get --server $api_mgmt --org $org --catalog $catalog --scope catalog findbranch:2.0.0# Download the same API without saving to file (Add --output -) flagapic apis:get --server $api_mgmt --org $org --catalog $catalog --scope catalog findbranch:2.0.0 --output -
Download all Products and APIs
# Download ALL APIs in the catalog into a directorymkdir ./api-dumpapic apis:clone --server $api_mgmt --org $org --catalog $catalog --scope catalog --output api-dump# Download ALL Products in the catalogapic products:clone --server $api_mgmt --org $org --catalog $catalog --scope catalog --output api-dump
Add Third OAuth Provider
Modify the URLs and other properties as needed, and run the create
command.
apic oauth-providers:create --server $api_mgmt --org $org setup-yamls/third-party-oauth-okta.yaml
Cloud Manager Mail Server
List out existing mail servers
apic mail-servers:list --server $cloud_mgmt --org admin