Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: https://wso2.org/jira/browse/DOCUMENTATION-6513

...

After successfully deploying the import/export tool, you can export an existing API as a .zip archive. Issue the following cURL command using the command line:


 

Code Block
curl -H "Authorization:Basic <base64-encoded-credentials-separated-by-a-colon>" 
-X GET "https://<APIM_HOST:Port>/api-import-export-<product-version>-<tool-version>/export-api?name=<API-name>&version=<API-version>
&provider=<API-provider>" -k > <exportedApiName>.zip

Tip

To obtain <base64-encoded-credentials-separated-by-a-colon> use a base64 encoder (e.g., https://www.base64encode.org/) to encode your client ID and client secret using the following format: <clientId>:<clientSecret> Thereafter, enter the encoded value for this parameter.


Here's an example:

Code Block
curl -H "Authorization:Basic AbCdEfG" -X GET 
"https://<host>:9443/api-import-export-<product-version>-<tool-version>/export-api?name=PizzaShackAPI&version=1.0&provider=admin" 
-k > myExportedAPI.zip

...

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

    Code Block
    curl -H "Authorization:Basic AbCdEfG" -X GET "https://<host>:port/api-import-export-2.0.0-v0/export-api?name=sample&version=1.0.0&provider=user@domain.com" -k > exportedApiName.zip
  • To import the API in another tenant, follow the steps in Importing an API. Use the encoded credentials for this tenant in the cURL command. Here's an example:

    Code Block
    curl -H "Authorization:Basic AbCdEfG" -F file=@"/home/user/Desktop/exportedApiName.zip" -k -X POST "https://<host>:port/api-import-export-2.0.0-v0/import-api?preserveProvider=false"

    Note that the preserveProvider parameter value should be set to false.

 


Understanding the API import/export tool

...

The structure of the ZIP file is explained below:


 

Sub directory/FileDescription

Meta Information

  • api.json: contains all the basic information required for an API to be imported to another environment

  • swagger.json: contains the API swagger definition

Documents

  • docs.json: contains the summary of all the documents available for the API

  • Add the uploaded files for API documentation also

ImageThumbnail image of the API
WSDLWSDL file of the API
SequencesThe sequences available for the API

 


Given below is the RESTful API for the export functionality. It is secured using Basic Authentication.

 


ParameterDescription

URI

https://<host name>:9443/api-import-export-<product-version>-<tool-version>/export-api

Query parameters

name=<api_name>&version=<api_version>&provider=<provider_name>

HTTP method

GET

Examples

curl -H "Authorization:Basic YWRtaW46YWRtaW4=" -X GET "https://<host>:9443/api-import-export-<product-version>-<tool-version>/export-api?
              name=test&version=1.0.0&provider=admin"

It gives a data stream as the output. To download it as a zipped archive, use the following command:

curl -H "Authorization:Basic YWRtaW46YWRtaW4=" -X GET "https://<host>:9443/api-import-export-<product-version>-<tool-version>/export-api?name=test
              &version=1.0.0&provider=admin"  -k > exportedApi.zip

To verify the output status of the API call:

curl -v -H "Authorization:Basic YWRtaW46YWRtaW4=" -X GET "https://<host>:9443/api-import-export-<product-version>-<tool-version>/export-api?name=test&version=1.0.0&provider=admin"  -k > exportedApi.zip

The import functionality

The import functionality uploads the exported ZIP file of the API to the target environment. It creates a new API with all the registry and database resources exported from the source environment. Note the following:

  • The lifecycle status of an imported API will always be CREATED even when the original API in the source environment has a different state. This is to enable the importer to modify the API before publishing it.
  • Tiers and sequences are provider-specific. If an exported tier is not already available in the imported environment, that tier is not added to the new environment. However, if an exported sequence is not available in the imported environment, it is added.
  • The importer can decide whether to keep the original provider’s name or replace it. Set the preserveProvider parameter to true to keep it. If you set it to false, the original provider is replaced by the user who is sending the cURL command. 
  • Cross-tenant imports are not allowed by preserving the original provider. For example, if an API is exported from tenant A and imported to tenant B, the valve of the preserveProvider parameter must always be false.
     
Given below is the RESTful API for the import functionality.
ParameterDescription

URI

https://<host>:9443/api-import-export-<product-version>-<tool-version>/import-api

Query parameters

preserveProvider=<true|false>

HTTP method

POST

Example

Imports the API with the original provider preserved: curl -H "Authorization:Basic YWRtaW46YWRtaW4=" -F file=@"full/path/to/the/zip/file" -k -X POST "https://<host>:9443/api-import-export-<product-version>-<tool-version>/import-api"

Imports the API with the provider set to the current user: curl -H "Authorization:Basic YWRtaW46YWRtaW4=" -F file=@"full/path/to/the/zip/file" -k -X POST "https://<host>:9443/api-import-export-<product-version>-<tool-version>/import-api?preserveProvider=false"