Oracle API Platform Cloud Service – Bulk API creation utility

Introduction

This blog provides a utility for bulk creation & deployment of APIs in Oracle API Platform cloud service. It is useful to the first time users who have significant number of back-end services that needs to be published as simple API. Instead of creating individual API from API Portal this utility reads a template (CSV file) and creates defined APIs in portal. Sometime it helps to have a template where all planned APIs are listed. this helps for internal review/approval (naming convention, description, verify back-end service URL etc) before publishing the API.

Prerequisites

– Python 2.7 or 3.x to execute utility code
– User with privilege to create API in Oracle API Platform

Execution Steps

Steps-1 : Create API template

  1.  – Download BulkAPICreation.zip and extract content in a directory named “BulkAPICreation”.
  2.  – Open file “APIList.csv” with text editor or MS-Excel to add detail of the APIs that needs to be created in API Portal. In CSV file 1st row is header that should not be modified. Row#2 onwards you need to provide API detail. There are 2 sample APIs given in attachment with values shown below.

APITemplateExcel

For each API there are 6 fields we are configuring in CSV file:

  1. (1) API_NAME: Provide name of the API that you want to configure. Each API should have a unique name.
  2. (2) API_VERSION: Version of the API that we want to configure.
  3. (3) API_DESCRIPTION: Provide detail description of the  API.
  4. (4) API_URI: Provide Endpoint URL for API. It gets appended to the Gateway URL.  Each API should have a unique URI.
  5. (5) SERVICE_URL: Back-end service URL that gets invoked when a request comes to API.
  6. (6) GATEWAY_ID: API Gateway ID. provide gateway ID only if you want to deploy API to the gateway. Otherwise provide value NONE. Check value of GATEWAY_ID in above screenshot. For API ‘API21Sample’ value is 100. Because we want to deploy API to the gateway that has ID 100. while for API ‘API22Sample’ value is ‘NONE’. because we just want to create the API but don’t want to deploy it.

Steps-2 : Modify connection URL & Credentials

  1.  – Open file Config.py in editor. This files has variable declarations.
  2.  – You need to change value of 3 variables highlighted in Red in below source code. These variables are: Username, password, URL(Host & port) of API management service.

## CSV File

api_file_name=”APIList.csv”

## Common variable declaration
headers = {‘Content-length’ : ‘0’, ‘Content-type’ : ‘application/json’}
user=‘weblogic’
password=‘welcome1’
apip_url = ‘http://apimgmt:7201/apiplatform’

## API portal variables

createAPI_REST = apip_url+’/management/v1/apis’
api_create_json_str = ”'{
“name”:”%s”,
“vanityName”: “%s”,
“version”: “%s”,
“details”: {
“description”:”%s”,
},
“implementation”:
{
“policies”:[
{ “id”:”1″, “type”:”o:ApiRequest”, “version”:”1.0″, “draft”:false, “config”: {“protocols”: [“HTTP”],”url”: “%s”}},
{ “id”:”2″, “type”:”o:ServiceRequest”, “version”:”1.0″, “draft”:false, “config”: {“headerConfig”: {“action”: “PASS-THROUGH”,”headersToAddOrUpdate”: [], “headersToDrop”: []},”useProxy”: false,”url”: “%s”}},
{ “id”:”3″, “type”:”o:ServiceResponse”, “version”:”1.0″, “config”:{}},
{ “id”:”4″, “type”:”o:ApiResponse”, “version”:”1.0″, “config”:{}}
],
“executions”:{ “request”:[“1″,”2”], “response”:[“3″,”4”] }
}
}”’

## API Gateway variables

deployAPI_REST=apip_url+’/management/v1/apis/%s/deployments’
gw_deploy_json_str = ”'{“gatewayId”:”%s”,”action”:”DEPLOY”,”description”:””,”runtimeState”:”ACTIVE”}”’

 

Steps-3 : Execute Script

  1. – Execute python script LoadAPIs.py in command command prompt / terminal.
  2.      $python LoadAPIs.py
  1. – Here is the output of sample API deployment. It shows execution log with create & deploy status of each API defined in CSV.

Output

Steps-4 : Verify APIs in Portal

  1. – Login to API portal and check deployed APIs. We can see 2 APIs created in portal as shown below.

APIList

  1. – Click on ‘API21Sample’ to see detail. As you can see API configured with endpoint URI and back-end service.

API21

  1. – Click on deployments tab. We had provided gateway ID 100 to deploy API on gateway. In following screenshot it shows API was deployed successfully.

API21_GW

  1. – Similarly click on ‘API22Sample’ to see detail.

API22

  1. – Click on the deployments tab. you can see API is not deployed to any gateway because we had provided ‘NONE’ for GATEWAY_ID.

API22_GW

The script uses OOB REST APIs provided by API Platform for API creation & deployment. There are many features like publishing API, applying multiple policies to the API which are kept out of scope to keep utility simple and easy to use. Users with REST and Python skill can modify the source code as per their requirement.

Scripts used in the blog are available to download at – BulkAPICreation

Disclaimer: Scripts provided for free to use “AS-IS” but without any official support from Oracle. Bugs, feedback and enhancement requests are welcome but need to be performed using the comments section of this blog and the A-Team reserves the right of help in the best-effort capacity.

References:

Oracle API Platform documentation – https://docs.oracle.com/en/cloud/paas/api-platform-cloud/

REST API for the Management Service – https://docs.oracle.com/en/cloud/paas/api-platform-cloud/apfrm/index.html

Add Your Comment