Monday, September 12, 2016

Notify subscribers of new API Versions


Enabling Notifications

Email server configurations should be set in repository/conf/output-event-adapters.xml under email adapter.
Open the admin console and go to the registry browser
open the tenant-conf.json in path "/_system/config/apimgt/applicationdata/tenant-conf.json"
Click the edit resource and Set true for NotificationsEnabled field

Setting Notifier Properties
Notifiers properties should be set in tenant-conf.json. A notification type can have multiple notifier classes which will help to send multiple notifications. Each Notifier should have a class attribute which contains the full class path. following properties should be set for the default NewAPIVersionEmailNotifier class
Class :- full class path of the notifier class
ClaimsRetrieverImplClass :- Subscriber Email addresses are extracted from user claims. The default pack uses org.wso2.carbon.apimgt.impl.token.DefaultClaimsRetriever to read the claim values from user store.
Subject :- The email subject.
Template :- Email Body Template. this can be a String values or a valid registry path to a template file.
The following strings will be replaced with API specific values in Subject and Template.
$1 :- API name
$2 :- New API Version
$3 :- API Provider email
$4 :- API version Of the original API

sample notification configuration. Full tenant-conf.json is attached
"NotificationsEnabled":"false",
 "Notifications":[{
   "Type":"new_api_version",
   "Notifiers" :[{
     "Class":"org.wso2.carbon.apimgt.impl.notification.NewAPIVersionEmailNotifier",
     "ClaimsRetrieverImplClass":"org.wso2.carbon.apimgt.impl.token.DefaultClaimsRetriever",
     "Title": "Version $2 of $1 Released",
     "Template": " <html> <body> <h3 style=\"color:Black;\">We’re happy to announce the arrival of the next major version $2 of $1 API which is now available in Our API Store.</h3><a href=\"https://localhost:9443/store\">Click here to Visit WSO2 API Store</a></body></html>"

   }]
 }
 ]

For this release we only support notifications for new API Versions. If a user wants to send a different type of notification ,then they can have their own implementation by extending org.wso2.carbon.apimgt.impl.notification.Notifier abstract class.