Photo by Prateek Katyal on Unsplash

Notification on New API Creation in WSO2 APIM

ajanthan
WSO2 Solution Architecture Team Blog
4 min readJan 22, 2020

--

In an effective API ecosystem, it is very important to inform the consumers about the changes in the APIs. The growth of an API ecosystem heavily depends on how the information flows from API providers to API consumers. Most of the bonding between API provider and the consumer happen through Developer Portal. But the developer portal only gives a snapshot view of the whole ecosystem at a time. The developers are unaware of the ongoing changes in the system if they don’t check the developer portal regularly. In that case, the ongoing important changes should be communicated via different channels to keep the consumer in the loop. The information should be somehow pushed into channels used by developers regularly. Chat channels and email are used by most of the organizations to keep the developer community updated with the latest information. In the case of the API ecosystem, we have to use these existing channels to propagate the information regarding ongoing changes as notifications.

WSO2 API Manager, one of the open-source, complete API lifecycle management solution, has the ability to send notifications to all the consumers when a new version of API is available. Primarily email is used as a notification channel but it is not limited to just email, with a little bit of additional work other channels like Slack can be added but in the developer world email is the primary medium to communicate none time-sensitive information.

Sometimes it also useful to send a notification to the developer group whenever there is a new API available in the API ecosystem. It is another channel of API discovery. Unfortunately in WSO2 API Manager, it is not supported. But it is not the end of the story. WSO2 API Manager has an extension mechanism to extend the product capability as needed. The idea here is to use the extension mechanism and achieve this missing functionality. The purpose of this article is to guide through how it can be implemented using the extensions available in WSO2 API Manager.

WSO2 API Manager has an extensible API Lifecycle management component. The default lifecycle can be modified by writing an API Lifecycle extension. A Java class can be written by extending the “org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor” class. This extension gives the ability to write your own logic in the middle of the API lifecycle transition. It is also possible to pinpoint the exact state transition and execute the custom logic there. Here we are going to utilize this capability to detect every API creations and send an email to all the developers(i.e subscribers).

The complete extension can be found in the following Github repository.

If you want to try this by yourself, first download and start the WSO2 API Manager as mentioned in the official documentation(follow the instructions in “Before you begin…” section only). Then clone above Github repository and follow the instructions in the readme to build the extension project and configure it with API Manager instance that you have just started.

Before trying the functionality there are few things need to be done. In this example, Gmail is used as an email service provider. By default, Gmail doesn’t allow sending mails through 3 rd party applications or less secure applications. In order for this example to work, the Google account security setting should be changed as follows. Visit Google account security settings page and disable 2-factor authentication and enable “less secure app access”.

Disable 2-factor authentication in Google account
Enable less secure app access in Google account

The extension is executed whenever there is a new API created. It starts a new thread and sends notifications to all the users in the subscriber role in the WSO2 API Manager setup. Thus, it is important to have at least one user in the subscriber role with an email attribute with a valid email address. Add a new user with subscriber role and edit User Profile and update the email attribute as follows.

Edit added user via User Profile
Add the Email attribute

Finally, it is time to try the functionality. If the above instructions are followed correctly when a new API is created there should be an email notification sent to all the subscribers.

As in the Quickstart guide step 1 create and publish an API. There should be an email to the email address of a user who is in a subscriber role.

Email Alert
Content of the email

In this post, we have looked at the importance of notifications in the API ecosystem and how a WSO2 API Lifecycle extension can be used to extend the WSO2 API Manager to implement notification on each new API creation.

--

--