Layer7 API Management

  • 1.  Update sysfilter from Request Event

    Posted Mar 04, 2019 03:08 PM

    Can I update req.urlParameters.sysfilter before the request is sent to resource, eg. to add a date filter to a database first resource via Request Event?

    I created the below Request Event but it does not seem to "apply" the filter

     

     

     

    if (req.verb === 'GET' && req.resourceName === 'bookings' ) {
    var today = new Date();
    var tomorrow = new Date();
    tomorrow.setDate(today.getDate()-1);
    var date = tomorrow.getDate();
    var month = tomorrow.getMonth();
    var year = tomorrow.getFullYear();
    var yearMonthDay = pad(year) + "-" + pad(month) + "-" + pad(date) + "T00:00:00";
    //var params = JSON.parse(req.urlParameters);
    var hasData = JSON.stringify(req.urlParameters.sysfilter, null, 2)
    log.debug("THE DATE: " + yearMonthDay + " -- ");

    if(req.urlParameters.sysfilter){
    //if(params.sysfilter.match(/BookingDate/).length === 0) {
    if(hasData.indexOf("BookingDate") > -1){
    //log.debug("HAS BOOKINGDATE");
    var sFilter = req.urlParameters.sysfilter + ',greaterequal(BookingDate:timestamp(' + yearMonthDay + '))';
    req.urlParameters.sysfilter = sFilter;
    }

    }
    else
    {
    req.urlParameters.sysfilter = 'greaterequal(BookingDate:timestamp(' + yearMonthDay + '))';
    }

    log.debug("sysFilter: " + req.urlParameters.sysfilter);


    }

    function pad(n) {
    return n<10 ? '0'+n : n;
    }



  • 2.  Re: Update sysfilter from Request Event

    Broadcom Employee
    Posted Mar 04, 2019 04:36 PM

    Good afternoon,

     

    Please confirm the product you are looking for assistance with. This does not look like it belongs to API Management.

     

    Sincerely,

     

    Stephen Hughes

    Broadcom Support



  • 3.  Re: Update sysfilter from Request Event

    Posted Mar 05, 2019 12:15 AM

    Live API Creator 4.1



  • 4.  Re: Update sysfilter from Request Event

    Posted Mar 05, 2019 12:36 PM

    Hi Ewan, 

     

    The req.urlParameters a read-only property is a map of all the parameters, and their value, as specified in the URL. See: Event Handlers - CA Live API Creator - 4.1 - CA Technologies Documentation 

     

    You can specify filters in the Resource definition itself. Would that work? 

     

    Wai-Yin