Try WSO2 Cloud for Free
Sign in

All docs This doc
||
Skip to end of metadata
Go to start of metadata

Any user with admin privileges can migrate the APIs from a local WSO2 API Manager (WSO2 APIM) environment to WSO2 API Cloud without having to recreate the APIs. 

In this tutorial, you set up an instance of WSO2 API Manager in your local environment, create an API in the API Manager instance and then migrate that API from the local setup to WSO2 API Cloud.

Let's get started!

  1. Go to http://wso2.com/products/api-manager/ and download WSO2 API Manager 2.1.0 by clicking the DOWNLOAD button in the upper right-hand corner.

    Tip: To migrate APIs, your local environment must have the same API Manager version that the API Cloud runs on. 

  2. Extract the ZIP file to a suitable location in your machine. Let's call this location <APIM_HOME>.
  3. To export the API that you will later create in the API Manager, you need the API Import/Export tool provided by WSO2. Download this WAR file and copy it to the <APIM_HOME>/repository/deployment/server/webapps folder. It deploys the API Import/Export tool in your API Manager server.
  4. Start the API Manager by executing one of the following commands:
    • On Windows:  <APIM_HOME>\bin\wso2server.bat --run
    • On Linux/Solaris/Mac OS: sh <APIM_HOME>/bin/wso2server.sh

  5. Sign in to the API Publisher in your local environment using the URL http://localhost:9763/publisher and credentials admin/admin.
     
  6. Create and publish an API with the following details. If you do not know how to create and publish an API, see Create and Publish an API.

    Tab NameParametersValues
    Design TabNamePhoneTest

    Context

    /phonetest


    Version1.0.0

    VisibilityPublic

    API Definition

    Click Next without entering anything and the system will prompt you to add a wildcard resource (/*). Click Yes.

    Implement Tab -> Managed APIProduction Endpointhttp://ws.cdyne.com/phoneverify/phoneverify.asmx
    Manage TabTier Availability

    Gold

    Tip: You cannot import a tier to an environment if it is not supported there, although it is supported in the source environment.

    For example, the Unlimited tier is supported in WSO2 API Manager, but not in WSO2 API Cloud. Therefore, you cannot import it to the Cloud.


    You have now set up an instance of API Manager in your local environment and created an API in it. Let's export the API to a ZIP file.

  7. Install cURL in your local machine.
  8. Using the command line (if you use a Mac/Linux) or an online Base64 encoder such as https://www.base64encode.org/, create a Base64-encoded string of the credentials of the API Manager, separated by a colon as <username>:<password>. In this example, it is admin:admin. 

    If you use Mac/Linux, use the following command.
    echo -n <username>:<password> | base64

    ex. echo -n admin:admin | base64

    Tip: Only users with admin privileges can migrate APIs between environments using the API Import/Export tool.

  9. Navigate to a suitable location using the command-line or terminal and execute the following cURL command to export your API as a ZIP file. 

    curl -H "Authorization:Basic <base64-encoded-credentials-from_previous_step>"
    -X GET "https://<APIM_HOST:Port>/api-import-export-2.1.0-v2/export-api?name=<API_Name>&version=<API-Version>
    &provider=<API_provider>" -k > <ZIP_File_Name>.zip
    
     
    According to our example, the command is:
    curl -H "Authorization:Basic <base64-encoded-credentials-from_previous_step>=" -X GET "https://localhost:9443/api-import-export-2.1.0-v2/export-api?name=PhoneTest&version=1.0.0&provider=admin" -k > myExportedAPI.zip

    You have exported an API to a ZIP file. Let's import that to your tenant in WSO2 API Cloud.

  10. Log in to WSO2 Cloud by going to http://cloud.wso2.com, clicking the Sign In link and then selecting WSO2 API Cloud.

  11. You need to construct and then copy your username which would be <email_address>@<tenant_domain>.

  12. Create a Base64-encoded string of your API Cloud's credentials, separated by a colon as <username>:<password>. 
     

  13. Execute the following command to import the API to the API Cloud:

    curl -H "Authorization:Basic <base64-encoded-credentials-from_previous_step>" -F file=@"<full_path_of_zip_file>" -k -X POST "https://gateway.api.cloud.wso2.com/api-import-export/import-api?preserveProvider=false"
     
    For example:
    curl -H "Authorization:Basic <base64-encoded-credentials-from_previous_step>" -F file=@"/Users/Admin15/Downloads/myExportedAPI.zip" -k -X POST "https://gateway.api.cloud.wso2.com/api-import-export/import-api?preserveProvider=false"

    Tip: Make sure the name and context of the API that you are importing (e.g., PhoneTest and /phonetest) do not duplicate that of an existing API in the API Cloud.

  14. Sign in to WSO2 API Cloud and note that the API that you imported now appears in the API Publisher.
     

  15. Note that the API in the Cloud is in the CREATED state although it was in the PUBLISHED state in your local API Manager instance. This is done to enable you to modify the API before publishing it.

In this tutorial, you created an API in an API Manager and exported that to WSO2 API Cloud without having to recreate the API from scratch.

  • No labels