Managing API Products
Use the apic products
and apic apis
commands to manage
Products and APIs that have been published to IBM® API Connect Catalogs. Use the
--scope space
option to manage Products and APIs that have been published to Spaces within
Catalogs.
Product management command summary
Example command | Description |
---|---|
apic config:set
catalog=https://platform-api.myserver.com/api/catalogs/myorg/sandbox |
Set the default Catalog. |
apic login --username some-user --password some-password --server
platform-api.myserver.com --realm provider/my-identity-provider |
Login into the management server. For full details on how to log in to your management server from the CLI, see Logging in to the management server. |
apic create:api --title Routes --product "ClimbOn"
|
Create the Product and API. |
apic products:publish climbon.yaml |
Publish the Product to the default catalog. Add --stage argument to stage the Product. |
apic products:list-all --scope catalog |
List the Products in the default catalog. |
apic products:get climbon:1.0.0 --output - |
Display the Product's properties. Omit the output argument to download to a file. |
apic apis:list-all --scope catalog |
List the APIs in the Catalog. |
apic apis:get routes:1.0.0 --output - |
Get the API properties. Omit the output argument to download to a file. |
apic products:replace climbon:1.0.0 mapfile.txt |
Replace the Product indicated on the command line with the staged or published Product designated in the mapfile. This retires the replaced Product. |
apic products:supersede climbon:1.0.0 mapfile.txt |
Supersede the Product indicated on the command line with the staged or published Product designated in the mapfile. This deprecates the superseded Product. |
apic products:delete climbon:1.0.0 |
Delete the Product from the Catalog. The Product must be either retired or deprecated. |
Using the products
and apis
commands through a full
lifecycle
This example shows a complex lifecycle where a new version of a Product and API replaces the original version at run time.
$ref
field to reference a fragment of OpenAPI code that is defined
in a separate file, the $ref
field is replaced
with the contents of the target file before the Product that contains the API is staged or published
with the apic publish command. For more information, see Using $ref to
reuse code fragments in your OpenAPI
files.- Set the default Catalog and login to the mgmnthost.com API Connect cloud
-
apic config:set catalog=https://platform-api.myserver.com/api/catalogs/climbon/sandbox apic login --username some-user --password some-password --server platform-api.myserver.com --realm my-identity-provider
For full details on how to log in to your management server from the CLI, see Logging in to the management server.
- Create and publish an initial version
-
apic create:api --title Routes --version 1.0.0 --filename routes100.yaml apic create:product --title "Climb On" --version 1.0.0 --apis routes100.yaml --filename climbon100.yaml apic products:publish climbon100.yaml
- Create a new version to fix a bug in the API, stage it to the Catalog
-
apic create:api --title Routes --version 1.0.1 --filename routes101.yaml apic create:product --title "Climb On" --version 1.0.1 --apis routes101.yaml --filename climbon101.yaml apic products:publish --stage climbon101.yaml
- Inspect the Catalog
-
apic products:list-all --scope catalog
This produces a list of all Products in the catalog. Copy the ID of theclimbon:1.0.1
Product. The ID resembles the following example.https:/server/api/catalogs/3eca6046-3c27-4ad/ab8772bf-0f65-45/products/8f854623-bda1-4f9
- Create a mapping file
- For example, if you are replacing a Product, the mapping file specifies the Product that you
want to replace, and the mapping of the Plans from the source Product to the target Product. For
example, if you are replacing
climbon:1.0.0
withclimbon:1.0.1
thenproduct_url
property specifies the URL ofclimbon:1.0.0
.This file takes the following form:product_url: https:/server/api/catalogs/{id}/products/{id} plans: - source: {source_plan_name_1} target: {target_plan_name_1} - source: {source_plan_name_2} target: {target_plan_name_2} . . .
Note:- The source and target Plan names can be the same or different.
- Every Plan in the Product you are replacing must be mapped to a Plan in the replacement Product.
- "Hot-replace" version 1.0.0 with 1.0.1
After it is replaced in this way, a Product is retired. It is no longer active.apic products:replace climbon:1.0.1 PRODUCT_PLAN_MAPPING_FILE
Note: The Product specified on the command line is the replacement Product. For example, if you are replacingclimbon:1.0.0
withclimbon:1.0.1
then the Product specified on the command line isclimbon:1.0.1
.- Supersede version 1.0.0 with 1.0.1
- Rather than hot-replacing an existing Product with a new one (usually an updated version), you
can supersede the existing Product with a new one. When you replace a Product, all external
application subscriptions to that Product are automatically moved to the new Product. When you
supersede a Product, the subscriptions are not automatically moved to the new Product, some action
must be taken to subscribe external applications to the superseding Product.The command to supersede a Product uses the same mapping file as the command to replace a Product. The name of the superseding Product is given on the command line.
Once superseded, a Product is marked deprecated, meaning that no further subscriptions to the Product are allowed, although it is still active and existing subscriptions still work.apic products:supersede climbon:1.0.1 PRODUCT_PLAN_MAPPING_FILE
Note: The Product specified on the command line is the superseding Product. For example, if you are replacingclimbon:1.0.0
withclimbon:1.0.1
then the Product specified on the command line isclimbon:1.0.1
. The mapping file specifies the URL of the Product you are superseding. - Set a migration target
- It is possible to set a migration target for the existing Product. This helps migration.Use a command like the following to set the migration target.
apic products:set-migration-target climbon:1.0.0 PRODUCT_PLAN_MAPPING_FILE
Note: The Product specified on the command line is the Product from which you want to migrate subscriptions. The mapping file specifies the target Product for the subscriptions.Once a migration target is set, external application developers will be able to migrate their application subscriptions through the Developer Portal with ease. It is also possible to execute a subscription migration using the following command.apic products:execute-migration-target climbon:1.0.0
- Delete a Product
- When the replaced or superseded Product is no longer needed, it can be deleted.
apic products:delete climbon:1.0.0
Additional Product and API operations
clone
sub-command:
Command | Description |
---|---|
apic products:clone | Download all Products and their APIs from the catalog or space. |
apic apis:clone | Download all APIs from the catalog or space. |
--confirm
parameter):apic products:clear --confirm catalog_name
where
catalog_name is the name of the Catalog.You can use a Space to partition a Catalog so multiple teams can manage Products and APIs independently in a single Catalog. A Space is conceptually like a subcatalog, except that Products and APIs in all Spaces in a given Catalog are published to the same developer portal. For more information about Spaces, see Using syndication in IBM API Connect.
--scope space
option with the apic products
and apic
apis
commands. For example, to list the Products that are contained in a Space called
flights, use the following
command:apic products --scope space --space flights --catalog production --org climbonorg --server platform-api.myserver.com
Changing the lifecycle state of a Product in a Catalog or Space
To directly change the lifecycle state of a Product that has previously been staged or published to a Catalog or Space, complete the following steps:
- Enter the following command (the terminating hyphen character means that the command takes input
from the command line):
where:apic products:update product_name:version --server mgmt_endpoint_url --org organization --scope scope --catalog catalog [--space space] -
The command returns:Reading PRODUCT_FILE arg from stdin
- Enter the following data, followed by a new
line:
where new_state is the state that you want to change the Product to, and must have one of the following values.state: new_state
- staged
- published
- deprecated
- retired
- archived
- Press
CTRL D
to terminate the input. If the command is successful, the lifecycle state change is confirmed.For example:apic products:update finance:1.0.0 --server https://myserver.com --org development --scope catalog --catalog sandbox - Reading PRODUCT_FILE arg from stdin state: published finance:1.0.0 [state: published] https://myserver.com/api/catalogs/dce12994-a6a1-487b-83b6-c73bd8498799/006827d5-9e82-427a-abe6-be5b126210f7/products/0f0af980-f505-4f36-b09c-d7b1c9c1a2f2
The command will not succeed if the lifecycle state change you are attempting is not permitted.
- staged to published
- deprecated to retired
- published to staged
- retired to published
For full details, see The Product lifecycle.
apic products:list-all --server mgmt_endpoint_url --org organization --scope scope --catalog catalog [--space space]
apic products:list-all --server https://myserver.com --org development --scope catalog --catalog sandbox
graphql-services:1.0.0 [state: staged] https://myserver.com/api/catalogs/dce12994-a6a1-487b-83b6-c73bd8498799/006827d5-9e82-427a-abe6-be5b126210f7/products/7652d568-b396-4bfa-bf71-2f18cea63737
finance:1.0.0 [state: published] https://myserver.com/api/catalogs/dce12994-a6a1-487b-83b6-c73bd8498799/006827d5-9e82-427a-abe6-be5b126210f7/products/0f0af980-f505-4f36-b09c-d7b1c9c1a2f2
apic products:get product_name:version --server mgmt_endpoint_url --org organization --scope scope --catalog catalog [--space space] --fields state --output -
apic products:get finance:1.0.0 --server https://myserver.com --org development --scope catalog --catalog sandbox --fields state --output -
state: published
Example scripts
A set of example toolkit scripts that demonstrate how to create and manage organizations, users, apps, Products and APIs are available at https://github.com/ibm-apiconnect/example-toolkit-scripts.