Query

This section provides information about querying by filtering values of fields. Only the entities that match the query are returned by the ALM Octane REST API during a GET operation on collections.

For details on cross-filtering, see Cross-filter.

Query statement

To filter, use a query statement, which is comprised of at least one query phrase.

The query statement is appended to the end of GET method.

Example: GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/{entity}?query="query statement"

  • The query statement is contained within double quotes: "query statement"

  • The query statement has the following syntax:

    " <query phrase>[[<logical operator><query phrase>]] "

    This means that when a query statement contains more than one query phrase, separate each query phrase with an And (;) or an Or (||) logical operator.

    Note: When filtering field metadata, certain limitations exist. For example, the Or (||) logical operator is not supported. For details, see Filtering field metadata using the URI.

Query phrase

  • The query phrase of a query statement has the following syntax:

    ( [negate keyword] ( "<field name> <comparison operator> <value>" ) )

    Note: Pay attention to the opening and closing parentheses in the syntax for the query phrase.

  • The query phrase can be enclosed in parenthesis.

Operators

Supported operators by data type

The values provided in the query should be consistent with the data types declared by the fields.

Data Type

EQ

LT

GT

LE

GE

IN

BTW

Integer

Boolean

DateTime

String

Memo

Reference

Operator terms

Operator type

Operator

Functionality

Example

Comparison operators Comparison operators separate between field names and their values:
 

EQ

Equal to

id EQ 1001

 

LT

Less than

id LT 1001

 

GT

Greater than

id GT 1001

 

LE

Less than or equal to

id LE 1001

 

GE

Greater than or equal to

id GE 1001

 

IN

Exists in a list of values, separated by commas.

The relationship between the items in the list of values is an OR relationship. This means that as long as one of the values match, the operation succeeds.

The list of values can also include:

  • The current user ( [current_user] ). This is the currently logged in user that is calling the REST API.

  • The current release ( [current_release]). This is the release set as the default in the ALM Octane Settings area.

id IN [current_user], 1001, 1002, 1003

 

BTW

Exists in a range of values, specified by two numbers separated by three dots ( ...) with a space before the three dots. This is an inclusive range. This is the same as saying greater than or equal to a number and less than or equal to another number.

id BTW 12 ...16 ( )

Logical operators Logical operators are used to separate between query phrases or query statements.
 

;

And

 
 

||

Or

 
  !

Not

The negation operator ! is optional. This operator reverses the meaning of the subsequent operand.

 

Operator precedence

The parenthesis has the highest precedence among all other operators, and controls the order in which the conditions are evaluated.

Parenthetical expressions can be nested.

Operator

Rank (low number = higher rank)

Example

()

1

The following statements are equivalent: 

  • "(!name EQ ^test^);flag EQ true"

  • "!name EQ ^test^;flag EQ true"

!

2

; 3
|| 4

Back to top

Value terms

This table describes the value terms, their format, and their implementation.

Type Description Examples

Numeric

Numeric values are placed after the comparison operator.

/<some_entities>?query=”<some_numeric_field_name> GE 35”

id GT 1

Boolean

Valid values: true or false.

/<some_entities>?query="<some_boolean_field_name> EQ true"

has_attachments EQ true
String / Memo

Must be wrapped in carets: ^string^

Escaping of special characters in strings is supported. See Special characters.

If a string contains a single quote, double quote, or a circumflex, escape it with a backslash. For example, pass d'Artagnan as 'd\'Artagnan'. Pass n^m as n\^m. Pass four "score" and seven years as four \"score\" and seven years.

Wildcards are supported. See Wildcards.

Literals are not trimmed. For example, if you send string literal ^ A ^, the server will get a value three characters long that will not match "A".

Features: 

name EQ ^Using cart^

Phases:

logical_name EQ ^phase.test*^

String-based When filtering, DateTime values behave like strings. See DateTime.  
Reference

Filtering on a reference value means the ability to filter on field values of the referenced entity.

Reference values have the following syntax:

{<query phrase>[[<logical operator><query phrase>]]}

The Reference field can reference a single entity or many entities, meaning, a multi-reference field. In case of multi-reference fields, the equality operator works as a containment operator.

The defect entity has a reference field to a release entity that is called detected_in_release. We want to filter all defects that were detected in the release named release1:

/defects?query=”detected_in_release EQ {name EQ ^release1^}”

We want to filter all defects that have no reference to any release in the detected_in_release field:

/defects?query=”detected_in_release EQ {null}”

(Note that null is wrapped in curly braces.)

"No Value"

Specifies that the field has no value. Represented as null. This implies that whenever user nullifies a string field from existing value (via PUT), client can send null or empty string ("") and server will store in DB null – this implies that empty string is a non-valid value for a non-nullable field.

"No Value" is relevant for all values except boolean and string values. For specifying "No Value" for strings, see below.

Whenever a value does not exist (for example, in the case where a defect closing date was not defined, since the defect is not closed yet), special keyword null should be defined. This null keyword can be used also in filtering to specify the notion of "no value".

The only manipulation of a string / memo field values from the server side can occur only due to output sanitization functionality.

The REST API doesn’t trims string/memo fields.

An empty string is not a valid value for a non-nullable field. For a nullable string field, null does not match an empty string.
 
DateTime

Must be wrapped in carets: ^datetime^

Expected date and time format is ISO-8601.

  • The date must contain complete date and time information, meaning "date only" is not supported.

  • Expected formats are:

    • 2018-06-10T10:13:15Z

    • 2018-03-12T16:42:11%2B01:00 (encoded 2018-03-12T16:42:11+01:00

    • 2018-03-12T16:42:11-01:00

  • The date and time is UTC.

  • For create, update and filtering purposes, the API consumer must use the UTC and ISO-8601 formats.

/<some_entities>?query=”<some_date_field_name> LT ^2015-02-25T16:42:11Z^

When filtering, DateTime values behave like strings.

 

Back to top

Special characters

Escaping of special character in string values is supported. If the string you are searching for contains one of the following characters, and you would like to filter by that character, use the escape character. This table shows some common examples:

Character

Escaped Character (URI Encoded)

Comments

"

\"      ( %5C%22 )

 

^

\^      ( %5C%5E )

 

\

\\      ( %5C%5C )

 

'

\q      ( %5Cq   )

 

<

\l      ( %5Cl   )

 

>

\g      ( %5Cg   )

 

*

N/A

Filtering by this character is not supported

{

\{      ( %5C%7B )

 

(

\(      ( %5C( )

 

)

\)      ( %5C) )

 

[

\[      ( %5Cb )

 

?

\?      ( %5C%3F )

 

Back to top

Wildcards

The supported wildcard is the * asterisk. Any character matches the asterisk.

To filter for a string that ... Specify wildcard... Matches...
Ends with ending *ending the_ending ; theending; ending
Starts with starting starting* starting_here ; startinghere, starting

Example: The first example shows a direct match of the string existence. The second example returns any value that starts with test.

  • /<some_entities>?query="<some_string_field_name> EQ ^existence^"

  • /<some_entities>?query="<some_string_field_name> EQ ^test*^"

Back to top

Examples

Back to top

See also: