This documentation is for WSO2 API Manager 2.6.0. View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Content Zone
locationtop

Exporting an API

  1. Make sure that WSO2 API Manager is started and that the CLI import/export tool is running. 
  2. Run the following CLI command to export an existing API as a .zip archive.
Localtab Group
Localtab
activetrue
idFormat-exportAPI
titleCommand Format
Code Block
apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -k
Code Block
apimcli export-api --name <API-name> --version <version> --provider <provider> --environment <environment> --insecure


Flags:

  • Required flags:
    • --name, -n
    • --version, -v
    • --provider, -r
    • --environment, -e
    • --insecure, -k : This allows connections to SSL sites without certificates
Localtab
idExample-exportAPI
titleExample
Code Block
apimcli export-api -n PhoneVerification -v 1.0.0 -r admin -e dev -k
Localtab
idReponse-exportAPI
titleResponse
Code Block
Succesfully exported API!
Find the exported API at /Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification_1.0.0.zip

Importing an API

Multiexcerpt
MultiExcerptNameimportAPIcreated
Note

The lifecycle status of the API is preserved when importing/exporting the API as the --preserveStatus flag is set to true by default.

You can use the archive created in the previous section to import APIs to an API Manager instance.

  1. Make sure that WSO2 API Manager is started and that the CLI import/export tool is running. 

    Note
    titleFor Secure Endpoint Enabled APIs:

    If you have enabled secure endpoints when creating the API and your username or/and password differs in the two environments, please follow the steps below before importing the API.

    1. Unzip the .zip archive created in the previous section.

    2. Go to the <API-name-version>/Meta-information directory and open the api.json file.
    For example, PhoneVerification_1.0.0/Meta-information directory and open the api.json file.

    3. Modify the endpointUTPassword with your endpoint password and save the api.json file.

    4. Compress the PhoneVerification_1.0.0 folder to a folder named myExportedAPI.

  • Run the following CLI command to import an API.

    Localtab Group
    Localtab
    activetrue
    idFormat-importAPI
    titleCommand Format
    Code Block
    apimcli import-api -f <environment>/<file> -e <environment> -k
    Code Block
    apimcli import-api --file <environment>/<file> --environment <environment> --insecure


    Flags:

    • Required flags:
      • --file, -f : The file path of the exported API. For example, if your file path is /Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification_1.0.0.zip., then you need to enter dev/PhoneVerification_1.0.0.zip as the value for this flag.
      • --environment, -e : The environment to which you what to import the API to.
      • --insecure, -k : This allows connections to SSL sites without certificates
    • Optional flags:
      • --preserveStatus : Preserves the lifecycle state of an API when importing/exporting. The default value is set to true. If this value is set to false the API will be exported in the CREATED status. 
        As the --preserveStatus is set to true by default the status of the API will be preserved when the API is exported. Therefore when the API is imported it will be imported to the new environment with the correct lifecycle state.
    Localtab
    idExample-importAPI
    titleExample
    Code Block
    apimcli import-api -f dev/PhoneVerification_1.0.0.zip -e production -u admin -p admin -k
    Localtab
    idResponseImport
    titleResponse
    Code Block
    titleSample Response
    ZipFilePath: /Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification_1.0.0.zip
    Successfully imported API 'dev/PhoneVerification_1.0.0.zip'
    Succesfully imported API!
    Tip

    You must add a parameter named --preserve-provider to the CLI command and set its value to false if the API is imported to a different domain than its exported one. This parameter sets the provider of the imported API to the user who is issuing the CLI command. Here's an example:

    Localtab Group
    Localtab
    activetrue
    idFormat-preserve
    titleCommand Format
    Code Block
    apimcli import-api -k -f <environment>/<file> -e <environment> -u <username> -p <password> --preserve-provider <preserve_provider>
    Code Block
    apimcli import-api --insecure --file <environment>/<file> --environment <environment> -u <username> -p <password> --preserve-provider=<preserve_provider>
    Note

    The username and password are optional flags. You will be prompted to enter your credentials if you do not provide these flags.

    Flags:

    • Required flags:
      • --insecure, -k : This allows connections to SSL sites without certificates
      • --file, -f
      • --environment, -e : The environment to which you what to import the API to.
      • --preserve-provider (This does not have a short flag)
    • Optional flags:
      • --username, -u
      • --password, -p
    Localtab
    idExample-preserve
    titleExample
    Code Block
    apimcli import-api -k -f dev/PhoneVerification_1.0.0.zip -e production -u admin -p admin --preserve-provider=false
    Note

    The --preserve-provider flag is used to decide whether to keep the actual Provider as the provider of the API or change the provider to the user who is importing the API to a different environment.

    As an example, If --preserve-provider is set to true, when importing an API created by user-1 in environment-1 will be preserved as the provider when and after importing that API to environment-2 by user-2. If --preserve-provider is set to false, when importing that API created by user-1 to the environment-2, the provider will be changed (not preserved) to user-2 who is importing the API.

    Info
    titleTroubleshooting

    After importing, if the APIs are not visible in the API Publisher UI, do the following to re-index the artifacts in the registry.

    1. Rename the <lastAccessTimeLocation> element in the <API-M_2.6.0_HOME>/repository/conf/registry.xml file. If you use a clustered/distributed API Manager setup, change the file in the API Publisher node. For example, change the /_system/local/repository/components/org.wso2.carbon.registry/indexing/lastaccesstime registry path to /_system/local/repository/components/org.wso2.carbon.registry/indexing/lastaccesstime_1.

    2. Shut down the API Manager 2.6.0, backup and delete the <API-M_2.6.0_HOME>/solr directory.

      For more information, see Upgrading the API Manager to 2.6.0.

Importing/exporting an API in a tenanted environment

Note

The environments that you create will be common to the admin and the tenants. Therefore, you do not need to create environments again when exporting and importing APIs between tenanted environments.


  • To export an API from a tenant, follow the steps in Export an API. Use the tenant-specific encoded credentials in the CLI command. Here's an example: 

    Localtab Group
    Localtab
    activetrue
    idFormat-exportAPITenant
    titleCommand Format
    Code Block
    apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -u <username> -p <password> -k
    Code Block
    apimcli export-api --name <API-name> -version <version> --provider <provider> --environment <environment> --username <username> --password <password> --insecure
    Note

    The username and password are optional flags. You will be prompted to enter your credentials if you do not provide these flags.

    Flags:

    • Required flags:
      • --name, -n
      • --version, -v
      • --provider, -r
      • --environment, -e : The environment to which you what to export the API to.
      • --insecure, -k : This allows connections to SSL sites without certificates
    • Optional flags:
      • --username, -u
      • --password, -p
    Localtab
    idExample-exportAPITenant
    titleExample
    Code Block
    apimcli export-api -n PizzaShackAPI -v 1.0.0 -r [email protected] -e dev -u [email protected] -p chris123 -k
    Localtab
    idResponseExportAPITenant
    titleResponse
    Code Block
    titleSample Response
    Succesfully exported API!
    Find the exported API at /Users/kim/.wso2apimcli/exported/apis/dev/PizzaShackAPI_1.0.0.zip
  • To import the API in another tenant, follow the steps in Importing an API. Use the encoded credentials for this tenant in the CLI command. Here's an example:

    Multiexcerpt include
    SpaceWithExcerptAM260
    MultiExcerptNameimportAPIcreated
    PageWithExcerptMigrating the APIs to a Different Environment

    Localtab Group
    Localtab
    activetrue
    idFormatImportAPI
    titleCommand Format
    Code Block
    apimcli import-api -f <environment>/<file> -e <environment> -u <username> -p <password> --preserve-provider <preserve_provider>
    Code Block
    apimcli import-api --file <environment>/<file> --environment <environment> --username <username> --password <password> --preserve-provider <preserve_provider>
    Note

    The username and password are optional flags. You will be prompted to enter your credentials if you do not provide these flags.

    Flags:

    • Required flags:
      • --file, -f
      • --environment, -e : The environment to which you what to import the API to.
      • --insecure, -k : This allows connections to SSL sites without certificates
      • --preserve-provider
    • Optional flags:
      • --username, -u
      • --password, -p
      • --preserveStatus : Preserves the lifecycle state of an API when importing/exporting. The default value is set to true. If this value is set to false the API will be exported in the CREATED status. 
        As the --preserveStatus is set to true by default the status of the API will be preserved when the API is exported. Therefore when the API is imported it will be imported to the new environment with the correct lifecycle state.
    Localtab
    idExampleImportAPI
    titleExample
    Code Block
    apimcli import-api -f dev/PizzaShackAPI_1.0.0.zip -e production -u [email protected] -p nick123 --preserve-provider=false -k
    Localtab
    idResponseImportAPITenant
    titleResponse
    Code Block
    ZipFilePath: /Users/kim/.wso2apimcli/exported/apis/dev/PizzaShackAPI_1.0.0.zip
    Successfully imported API 'dev/PizzaShackAPI_1.0.0.zip'
    Succesfully imported API!

    Note that the --preserve-provider flag value should be set to false.

List APIs

  1. Make sure that WSO2 API Manager is started and that the CLI import/export tool is running. 
  2. Run the following CLI command to list the APIs.
Localtab Group
Localtab
activetrue
idFormatListAPI
titleCommand Format
Code Block
apimcli list apis -e <environment> -u <username> -p <password> -k            
Code Block
apimcli list apis --environment <environment> --username <username> --password <password> --insecure
Code Block
apimcli list apis --environment <environment> --limit <maximum number of APIs> --insecure

Flags:

  • Required flags:
    • --environment, -e
    • --insecure, -k
  • Optional flags:
    • --username, -u
    • --password, -p

    • --limit, -l : Maximum number of APIs to returnOptional flags: 

      Note
      The username and password are optional flags. You will be prompted to enter your credentials if you do not provide these flags.
Localtab
idExample-listAPI
titleExample
Code Block
apimcli list apis -e dev -u admin -p admin -k
Code Block
apimcli list apis --environment dev --username admin --password admin --insecure
Code Block
apimcli list apis --environment dev --limit 40 --insecure
Localtab
idResponse-listAPI
titleResponse
Code Block
Environment: dev
No. of APIs: 2
+-------------------+---------+--------------+-----------+----------+--------------------------------------+
|       NAME        | VERSION |   CONTEXT    |  STATUS   | PROVIDER |                  ID                  |
+-------------------+---------+--------------+-----------+----------+--------------------------------------+
| PhoneVerification | 1.0.0   | /phoneverify | PUBLISHED | admin    | 2f25b332-4007-4c83-8249-b14b8af04848 |
| PizzaShackAPI     | 1.0.0   | /pizzashack  | PUBLISHED | admin    | 59e81b69-24d2-4fc4-9aaa-40665e119261 |
+-------------------+---------+--------------+-----------+----------+--------------------------------------+

...