Content server REST API - filter files by date

Options

Hi ,
Please can you suggest the way to list only files which are modified after specified date in the Content Server REST API .

I tried Filters concept as given in below link.
https://developer.opentext.com/webaccess/#url=/awd/resources/articles/868/opentext+restful+api+standard&tab=501
which is working for String/Numeric type field but its not working on the date fields.

The below is the example REST query I tried to fetch the data using modified date filter :
http://///api/v1/nodes//nodes?fields=data&where_modify_date='2014-09-19'

As the result for the above service call, I am getting every thing, and there is no filtering happening.

Please suggest is there any other work around for this.

Regards,
Thiru.

Tagged:

Comments

  • There is currently no way to list files which were modified after an arbitrary date, without using facets. Here is how to use facets to accomplish that through REST API.

    • "GET /nodes/{id}/facets" will give you a list of available facets
      for that location. Look under 'properties' and locate the object
      which has data_source: "sys_ModifyDate" - the name of the object is
      the facet ID.
    • Look under 'available_values' and find the object which
      corresponds to the facet ID, you will see available values there.
      Under the 'value' field is the facet value ID.
    • Thus, if facet ID of "sys_ModifyDate" was 3551, and you wanted to
      list by a facet value ID "re05", you would put the URL together like
      so:

    GET nodes/{id}/nodes?where_facet=3551:re05

    If you wanted to use two or more facet values for a given facet ID, you separate by a | character

    GET nodes/{id}/nodes?where_facet=3551:re05|re09

    If you wanted to use more than one facet ID, specify another where_facet= parameter

    GET nodes/{id}/nodes?where_facet=3551:re05&where_facet=1234:567


    Facet value ID for year: yr{year}
    (example for 2004): where_facet=3551:yr2004

    Facet value ID for month: mt{year}{month}
    (example for march 2004): where_facet=3551:mt200403

    Facet value ID for day: dy{year}{month}{day}
    (example for march 26 2004): where_facet=3551:dy20040326

    Thus, if you wanted to list items in the enterprise workspace with a modified date of March 26, 2004 (assuming your facet ID for modified date is 3551):

    GET /nodes/2000/nodes?where_facet=3551:dy20040326

    And if you wanted to list items with a modified date of March 25, 2004, or March 26 2004:

    GET /nodes/2000/nodes?where_facet=3551:dy20040325|dy20040326

    ** NOTE: The default items returned is a max of 25 items. Use ?limit={number of items to return} to increase the upper limit.

    In addition to the facet functionality above, you can also sort by the modified date using ?desc_modify_date (for descending sort) or ?asc_modify_date (ascending sort).

  • Someone from the REST API team may correct me, but I'm afraid that the REST API supports only three filtering properties: where_name, where_type and where_facet. It is not obvious from the documentation. The where_facet can filter by the modification time, but faceted browsing is not exactly a general filtering and it is too impractical for a general usage and infeasible for using with arbitrary date/time values.

    You would have to list all children (by paging) and filter them on the client side. For example, like this:

    <script
        src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script>
      var cgiUrl      = '//vmfp-ll100.eng-muc.opentext.net/livelink/llisapi.dll',
          credentials = {
            userName: '...', password: '...'
          },
          // Points to the children of the Enterprise Volume
          apiPath     = '/api/v1/volumes/141/nodes',
          dateRange   = {
            start: new Date('2014-06-26T00:00:00'),
            end: new Date('2014-06-27T00:00:00')
          };
    
      // Get the filtered documents and dump their names on the console
      filterDocsByModifyDate(cgiUrl + apiPath, credentials, dateRange)
          .then(function (documents) {
            console.log(documents.map(function (item) {
              return item.name;
            }));
          });
    
      // Return a filtered list of documents using a node listing URL
      function filterDocsByModifyDate(url, credentials, dateRange) {
        return doFilterDocsByModifyDate(url, credentials, dateRange, 1, []);
      }
    
      function doFilterDocsByModifyDate(url, credentials, dateRange, pageNum,
          filteredDocs) {
        return getDocsOrderedByModifyDate(url, credentials, pageNum)
            .then(function (response) {
              var unfilteredDocs = response.data,
                  firstDoc, lastDoc, newFilteredDocs;
              if (unfilteredDocs.length) {
                firstDoc = unfilteredDocs[0];
                // Stop if the first document is above the date range; the
                // documents were requested to be sorted by the modified date
                // and following pages would contain only newer documents
                if (new Date(firstDoc.modify_date) < dateRange.end) {
                  lastDoc = unfilteredDocs[unfilteredDocs.length - 1];
                  // Skip this page if the last document is still below the
                  // specified date range; the next page may contain newer ones
                  if (new Date(lastDoc.modify_date) > dateRange.start) {
                    newFilteredDocs = $.grep(unfilteredDocs, function (doc) {
                      var date = new Date(doc.modify_date);
                      return date >= dateRange.start && date < dateRange.end;
                    });
                    filteredDocs = filteredDocs.concat(newFilteredDocs);
                  }
                  // Ask for the next page if we are not on the last one and
                  // process it by this method recursively
                  if (response.page < response.page_total) {
                    return doFilterDocsByModifyDate(url, credentials, dateRange,
                        pageNum + 1, filteredDocs);
                  }
                }
              }
              return filteredDocs;
            });
      }
    
      // Return a specific page of documents from the node listing URL, ordered
      // ascending by the last modification time
      function getDocsOrderedByModifyDate(url, credentials, pageNum) {
        var parameters = {
          page: pageNum,
          limit: 25,
          where_type: 144,
          sort: 'asc_modify_date'
        };
        return $.ajax({
          url: url + '?' + $.param(parameters),
          headers: {
            Authorization: 'Basic ' + btoa(unescape(encodeURIComponent(
                credentials.userName + ':' + credentials.password)))
          }
        })
            .then(null, function (xhr) {
              var message = xhr.status > 0 ? xhr.responseJSON.error + ' (' +
                                xhr.statusText + ')' : 'Other connection  error';
              console.log(message);
            });
      }
    </script>
    
  • I have updated my original post with facet stuff.