Friday, July 3, 2015

[WSO2 AM] Add "getRecentlyAddedAPIs" operation for Store API - WSO2 API Manager.

The WSO2 API Manager doesn't expose the "getRecentlyAddedAPIs" operation through the Store API (https://docs.wso2.com/display/AM190/Store+APIs). But you can do the following workaround to expose that operation.

1. Open the file <am_home>/repository/deployment/server/jaggeryapps/store/site/blocks/api/recently-added/ajax/list.jag and change it as bellow.

<%
include("/jagg/jagg.jag");
(function () {
    response.contentType = "application/json; charset=UTF-8";
    var mod, obj, tenant, result, limit,

            msg = require("/site/conf/ui-messages.jag"),
            action = request.getParameter("action");
    if (action == "getRecentlyAddedAPIs") {
        tenant = request.getParameter("tenant");
        limit = request.getParameter("limit");
        mod = jagg.module("api");
        result = mod.getRecentlyAddedAPIs(limit,tenant);
        if (result.error) {
            obj = {
                error:result.error,
                message:msg.error.authError(action)
            };
        } else {
            obj = {
                error:false,
                apis:result.apis
            }
        }
        print(obj);
    } else {
        print({
            error:true,
            message:msg.error.invalidAction(action)
        });
    }
}());
%>

2. Now you can invoke the getRecentlyAddedAPIs operation as bellow.

curl -b cookies 'http://localhost:9763/store/site/blocks/api/recently-added/ajax/list.jag?action=getRecentlyAddedAPIs&limit=10&tenant=carbon.super'

limit - Number of recently added APIs
tenant - Tenant domain.