API Portal Automation : API Publishing

webMethods API Portal tutorial

API-driven automation helps to replace human involvement in a complex and monotonous, repetitive tasks. It involves replacing human intervention with calls to an API. In other words, rather than have a person execute that task, we tell a system to do it instead.

In this tutorial we will explore the possibilities of automating API publishing related activities within webMethods API Portal. As part of this tutorial we will be mainly using Curl commands to invoke the APIs. If you are unfamiliar with Curl you can check the basic tutorial here https://curl.haxx.se/docs/httpscripting.html first.

Creating an API

We can publish API to API Portal in two ways. You could use the swagger/raml/wsdl files available locally on your machine to publish it to API Portal. Or you can import the definitions from a remote URL.

  • Create API from local file

We can use below Curl command to publish an API definition into API Portal.

 
curl -X POST -u system:manager --url 'http://developers.fazio.com/abs/apirepository/v1/apis?async=false&type=swagger' --form 'api-package=@calculator.json' | jq . 
 

 

Note:

  1. -u parameter dictates the user to be used for the publishing. Please make sure the provided user have the role of API Administrator/API Provider

  2. The publishing API(abs/apirepository/v1/apis) takes type as one of the query parameter. Valid values are swagger/raml/wsdl

  3. The form parameter ('api-package') should point to the accessible location of the swagger/raml file. For example if the file is located in /tmp/source then we should provide the value as '@/tmp/source/calculator.json'

  • Create API from remote URL

We can use below Curl command to publish an API definition from a remote URL into API Portal.

 

 
curl -X POST -u system:manager --url 'http://developers.fazio.com/abs/apirepository/v1/apis?async=false&type=swagger' --form 'url=https://petstore.swagger.io/v2/swagger.json' | jq .
 

 

 
  • Response

If the creation is succesful, above invocation will provide a response something similar to below text.

 

 
[
  {
    "status": "SUCCEEDED",
    "message": "Creation of API is successful",
    "link": "/abs/apirepository/apis/d77f9ec1-6823-11e9-23f9-0050568c636d",
    "itemLink": "c.restObject.API-Portal.13-ewWgjEekj-QBQVoxjbQ.-1",
    "name": "Calculator API"
  }
]
 


We can use below API Portal API to list the published API definitions.

Listing APIs

 
curl -X GET -u system:manager --url 'http://developers.fazio.com/abs/apirepository/apis' | jq .
 
  • Response
 
[
  {
    "id": "ad6971f1-6897-11e9-23f9-0050568c636d",
    "name": "Swagger Petstore",
    "description": "This is a sample server Petstore server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the authori",
    "apiType": "restObject",
    "version": "1.0.0",
    "externalAPI": false
  },
  {
    "id": "1a490d51-6823-11e9-23f9-0050568c636d",
    "name": "Calculator API",
    "description": "Tiny Calculator API for developers",
    "apiType": "restObject",
    "version": "v1",
    "externalAPI": false
  }
]

 
 

The response includes the GUID of the published API , name, and short description.

Updating an API definition

We can republish API similar to the ways we created them. The endpoint for updating the API would include the GUID of the API being updated abs/apirepository/v1/apis/<<GUID>>

Example:

 
curl -X POST -u system:manager --url 'http://deverlopers.fazio.com/abs/apirepository/v1/apis/ad6971f1-6897-11e9-23f9-0050568c636d?async=false&type=swagger' --form 'url=https://petstore.swagger.io/v2/swagger.json' | jq . 
 

 

Associating the API to a community

Often times customers would like to associate specific APIs to specific communities. Inorder to associate an API to a community we must know the community identifier to which we are going to associate this API.

To list the communities

We can use below Curl command to list the communities registered in API Portal.

 
curl -XGET -u system:manager --url 'http://daeapiportal04rh.eur.ad.sag:18101/abs/apirepository/communities' | jq . 
 

Response

 

 
[
  {
    "id": "3bdf8005-5685-3ef5-b132-de4681963fb6",
    "name": "Public Community",
    "description": "Public Community"
  },
  {
    "id": "2ea679cc-bd83-31ff-8424-abeb47cfada1",
    "name": "Private Community",
    "description": "Private Community"
  }
]
 

response includes the GUID of the community, name and its short description.

Now to associate an API to a Community, we have to know the GUID of the API and GUID of the community. We can use below Curl command to associate an API to community.

 
curl -XPOST -u system:manager -H "Content-Type: application/json" --url 'http://developers.fazio.com/abs/apirepository/communities/2ea679cc-bd83-31ff-8424-abeb47cfada1/apis' --data '[{"id": "1a490d51-6823-11e9-23f9-0050568c636d"}]'
 

Now we have included 'Calculator API' into 'Private Community'

Deleting/Unpublishing API

Sometimes we need to cleanup some of the obsolete items. We can use below API to remove an unwanted API definition from API Portal.

 
curl -X DELETE -u system:manager --url 'http://developers.fazio.com/abs/apirepository/apis/d77f9ec1-6823-11e9-23f9-0050568c636d' | jq . 
 

API consumes GUID of the published API definition as its path parameter.  GUID of the API can be retried from the list API we seen in the past.