Constructors

Methods

  • Builds query string from provided query object.

    Parameters

    • query: any

      Object containing filters and sort order for querying managed objects. Supported filters are:

      • __and - Specifies conditions, e.g. {__and: [{__has: 'c8y_IsDevice'}, {'count': {__gt: 0}}]}.
      • __or - Specifies alternative conditions, e.g. {__or: [{__bygroupid: 10300}, {__bygroupid: 10400}]}.
      • __eq - Specified fragment must be equal to given value, e.g. {'status': 'AVAILABLE'} (no nested object required).
      • __lt - Specified fragment must be less then given value, e.g. {'count': {__lt: 10}}.
      • __gt - Specified fragment must be greater then given value, e.g. {'count': {__gt: 0}}.
      • __in - Specified fragment must be equal to one of values in the list, e.g. {'status': {__in: ['AVAILABLE', 'UNAVAILABLE']}}.
      • __not - Negates condition, e.g. {__not: {'status': 'AVAILABLE'}}.
      • __bygroupid - True if filtered managed object is assigned to given group, e.g. {__bygroupid: 10300}.
      • __has - Specified fragment must have a value defined, e.g. {__has: 'c8y_IsDevice'}.
      • __useFilterQueryString - Gets rid of the $filter=()… $orderby=… parts of a query and keeps only what's between the most exterior parentheses of the $filter. EXAMPLE: takes a query of the form $filter=(name eq 'RaspPi*') $orderby=name asc and turns it into name eq 'RaspPi*' This is necessary for searching for smart groups, which are identified by their own query that needs to be passed through.

      Note: if you want to specify the order, you need to wrap your filters within __filter property and then add __orderby with the array of field paths and sort directions (1 for ascending, -1 for descending), for example:

      • { __filter: { ... }, __orderby: [{ 'creationTime': -1 }, { 'name': 1 }] }

    Returns string

    Returns a query string ready to be sent in request params to backend.

    Example

      const query = {
    __filter: {
    'name': 'My Device*',
    'c8y_Availability.status': {
    __in: ['AVAILABLE', 'UNAVAILABLE']
    },
    'creationTime': {
    __lt: '2015-11-30T13:28:123Z'
    },
    'c8y_ActiveAlarmsStatus.critical': {
    __gt: 0
    },
    __or: [
    {__not: {__has: 'c8y_ActiveAlarmsStatus.major'}},
    {
    __or: [
    {__bygroupid: 10300},
    {__bygroupid: 10400}
    ]
    }
    ]
    },
    __orderby: [
    {'name': 1},
    {'creationTime': -1},
    {'c8y_ActiveAlarmsStatus.critical': -1}
    ]
    };

    const params = {
    query: queriesUtil.buildQuery(query)
    };