/WSO2-AM-API-Import-Export-Tool

WSO2 API Manager API import export tool

Primary LanguagePythonOtherNOASSERTION

WSO2 API Manager API Bulk Import Export Tool

This tool helps to export all the created APIs in a WSO2 API Manager deployment in to a set of source file and import it in to a different WSO2 API Manager deployment.

To export APIs, the script uses API Manager REST API and the APIs exposed by api-import-export-2.0.0 web application.

####API Export steps API Import and Export scripts need OAuth application registered in the API Manager to use Store/Publisher REST API.

Create Applicatin for API Manager REST API:

To create a OAuth application Carbon user or Carbon tenant user credentials have to be provided.

OAuth Application Creation Request.

curl -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -d @payload.json http://localhost:9763/client-registration/v0.10/register

payload.json

{
    "callbackUrl": "localhost",
    "clientName": "rest_api_publisher",
    "tokenScope": "Production",
    "owner": "admin",
    "grantType": "password refresh_token",
    "saasApp": true
}

Response

{"appOwner":null,"clientName":null,"callBackURL":"localhost","isSaasApplication":true,"jsonString":"{\"username\":\"admin\",\"redirect_uris\":\"www.google.lk\",\"client_name\":\"admin_rest_api_publisher\",\"grant_types\":\"urn:ietf:params:oauth:grant-type:saml2-bearer iwa:ntlm implicit refresh_token client_credentials authorization_code password\"}","clientId":"iMWERi0Sg60kV3C1u9Mb0_Q0o74a","clientSecret":"Zm27CVLgUnDQLY8eqlQFgbHf8Ika"}

Execute the API Export tool

API export script exports the API (download API Zip archive and unzip) to a local folder. If the local folder is a Git repository the script commit new changes and push the new changes to a remote Git repository.

Command syntax to export all the APIs:

export-api.py apiKey apiSecret userName password hostName tokenEndpointPort restApiEndpointPort gitRepoPath

./export-api.py iMWERi0Sg60kV3C1u9Mb0_Q0o74a Zm27CVLgUnDQLY8eqlQFgbHf8Ika admin admin123 localhost 8243 9443 /tmp/api-repo/

Command syntax to export single API:

export-api.py apiKey apiSecret userName password hostName tokenEndpointPort restApiEndpointPort gitRepoPath apiName apiVersion

Example:

./export-api.py iMWERi0Sg60kV3C1u9Mb0_Q0o74a Zm27CVLgUnDQLY8eqlQFgbHf8Ika admin admin123 localhost 8243 9443 /tmp/api-repo/ DEEP-Test 1.0.0

For Multi-Tenant environments Command syntax to export all the APIs:

export-api.py apiKey apiSecret userName@TenantDoamain tenantPassword hostName tokenEndpointPort restApiEndpointPort gitRepoPath

Example:

./export-api.py iMWERi0Sg60kV3C1u9Mb0_Q0o74a Zm27CVLgUnDQLY8eqlQFgbHf8Ika admin@mytenant.com mytenant123 localhost 8243 9443 /tmp/api-repo/

Command syntax to export single API:

./export-api.py iMWERi0Sg60kV3C1u9Mb0_Q0o74a Zm27CVLgUnDQLY8eqlQFgbHf8Ika admin@mytenant.com mytenant123 localhost 8243 9443 /tmp/api-repo/ DEEP-Test 1.0.0

####API Import steps Create an OAuth application in the destination API Manager deployment to import APIs. retrieve a access token to communicate with import API Manager REST API.

####Execute the API Import tool API import script updates the local Git repository to get latest changes from the remote Git repo and export all the API in the Git repo to the given API Manager deployment.

Command syntax to import all APIs:

import-api.py apiKey, apiSecret, userName, password hostName tokenEndpointPort restApiEndpointPort gitRepoPath

Example:

./import-api.py miFZAyBq46RyVhFwcdspQJc10yMa dZNwt9eC0nNQzfR3uubnqZiVnbUa admin admin localhost 8343 9543 /tmp/api-repo/

Command syntax to import single APIs:

import-api.py apiKey, apiSecret, userName, password hostName tokenEndpointPort restApiEndpointPort gitRepoPath apiName apiVersion

Example:

./import-api.py miFZAyBq46RyVhFwcdspQJc10yMa dZNwt9eC0nNQzfR3uubnqZiVnbUa admin admin localhost 8343 9543 /tmp/api-repo/ DEEP-Test 1.0.0

For Multi-Tenant environments Command syntax to import all the APIs:

import-api.py apiKey, apiSecret, userName@TenantDoamain tenantPassword hostName tokenEndpointPort restApiEndpointPort gitRepoPath

Example:

./import-api.py miFZAyBq46RyVhFwcdspQJc10yMa dZNwt9eC0nNQzfR3uubnqZiVnbUa admin@mytenant.com mytenant123 localhost 8343 9543 /tmp/api-repo/

Command syntax to import single APIs:

import-api.py apiKey, apiSecret, userName@TenantDoamain tenantPassword hostName tokenEndpointPort restApiEndpointPort gitRepoPath apiName apiVersion

Example:

./import-api.py miFZAyBq46RyVhFwcdspQJc10yMa dZNwt9eC0nNQzfR3uubnqZiVnbUa admin@mytenant.com mytenant123 localhost 8343 9543 /tmp/api-repo/ DEEP-Test 1.0.0