Available: | Crowd 2.2 and later. |
The Crowd Query Language (CQL) allows developers using the Crowd REST API to perform user and group searches in a more intuitive and simpler form.
The Crowd REST API since version 2.1 has allowed applications to POST to the Search resource with the search restriction in XML or JSON. The XML and JSON form is similar to the Java search restriction classes that Crowd uses.
In order to search for all users with an email of bob@example.net
, you would previously POST
to http://myhost.com:8095/rest/usermanagement/1/search?entity-type=user, with the following XML content:
1 2<?xml version="1.0" encoding="UTF-8"?> <property-search-restriction> <property> <name>email</name> <type>STRING</type> </property> <match-mode>EXACTLY_MATCHES</match-mode> <value>bob@example.net</value> </property-search-restriction>
From Crowd 2.2 onwards, there is a much simpler way to perform user and group searches. You can now perform a GET
request to the search resource with the restrictions expressed in CQL as a query parameter.
1 2GET http://myhost.com:8095/rest/usermanagement/1/search?entity-type=ENTITY_TYPE&restriction=RESTRICTION
where ENTITY_TYPE
is: user or group
and RESTRICTION
is the URL encoded search restriction expressed in CQL.
The above XML content now becomes:
1 2email=bob@example.net
i.e.
1 2GET http://myhost.com:8095/rest/usermanagement/1/search?entity-type=user&restriction=email%3Dbob%40example.net
Used to combine multiple restrictions, allowing you to refine your search. The AND statement is satisfied if all of the conditions are true.
Note that you can use #parentheses to control the order in which statements are executed.
Find all users with a first name of bob and an email of bob@example.net:
1 2firstName = "bob" and email = "bob@example.net"
Find all inactive groups with a name starting with "admin":
1 2name = "admin*" and active = false
Used to combine multiple restrictions, allowing you to expand your search. The OR statement is satisfied if any of the conditions are true.
Note that you can use #parentheses to control the order in which statements are executed.
Find all users with either a last name of Smith or Jones:
1 2lastName = Smith or lastName = Jones
Find all users created after December 2010 or a first name starting with Jo:
1 2createdDate > 2010-12 or firstName = Jo*
Crowd distinguishes between entity primary properties and entity secondary properties. The set of primary properties for each entity type is listed below with their type:
name
(String), email
(String), firstName
(String), lastName
(String), displayName
(String), active
(Boolean), externalId
(String), createdDate
(Date), updatedDate
(Date).name
(String), description
(String), active
(Boolean), local
(Boolean), createdDate
(Date), updatedDate
(Date).Custom attributes are secondary properties of type String and can be referred by their attribute key.
The "=
" operator is used to search for exact and partial matches of the specified value.
To find entities where the value of a specified field exactly matches multiple values, use multiple "=
" statements with the #AND operator. Partial matches are performed with the wildcard, "*", symbol. The only currently supported partial matches are:
The only currently supported partial matches are: "starts-with" and "contains". For instance, these restrictions are illegal: "email=*@example.net", "firstName=Ro*ert"
Find all active users:
1 2active = true
Find all users with a display name of John Smith:
1 2displayName = "John Smith"
Find all users with a first name starting with Jo:
1 2firstName = "Jo*"
Find all users with an email containing atlassian:
1 2email = "*atlassian*"
The ">
" operator is used to search for entities where the value of the specified field is greater than the specified value. Cannot be used with #string fields.
Note that the ">
" operator can only be used with fields which support ordering (e.g. date fields). To see a field's supported operators, check the individual #field reference.
Find all groups created after 1 January 2010:
1 2createdDate > 2010-01-01
The "<
" operator is used to search for entities where the value of the specified field is less than the specified value. Cannot be used with #string fields.
Note that the "<
" operator can only be used with fields which support ordering (e.g. date fields). To see a field's supported operators, check the individual #field reference.
Find all groups created before the year 2011:
1 2updatedDate < 2011
The following fields may be used in user queries.
Search for users with the specified user name.
Note: this field supports partial-matching.
1 2name
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find the user with username ernie:
1 2name = "ernie"
Find all users with a username starting with ern:
1 2name = "ern*"
Find all users with a username containing rni:
1 2name = *rni*
Search for users with the specified email.
Note: this field supports partial-matching.
1 2
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find all users with an email of bob@example.net:
1 2email = "bob@example.net"
Find all users with an email starting with bob:
1 2email = "bob*"
Find all users with an email containing example:
1 2email = *example*
Search for users with the specified first name.
Note: this field supports partial-matching.
1 2firstName
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find all users with a first name of Shrek:
1 2firstName = "Shrek"
Find all users with a first name starting with Sh:
1 2firstName = "Sh*"
Find all users with a first name containing hr:
1 2firstName = *hr*
Search for users with the specified last name.
Note: this field supports partial-matching.
1 2lastName
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find all users with a last name of Smith:
1 2lastName = "Smith"
Find all users with a last name starting with Smi:
1 2lastName = "Smi*"
Find all users with a last name containing mit:
1 2lastName = *mit*
Search for users with the specified display name.
Note: this field supports partial-matching.
1 2displayName
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find all users with a display name of John Smith:
1 2displayName = "John Smith"
Find all users with a display name starting with John:
1 2displayName = "John*"
Find all users with a display name containing Smi:
1 2displayName = *Smi*
Search for users with the specified active field value. The only valid values for active are: true, false.
1 2active
Boolean
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | no | no |
Find all active users:
1 2active = true
Find all inactive users:
1 2active = false
Search for users created on, before or after a particular date.
The date is specified in ISO-8601 format: YYYY-MM-DDTHH-MM-SS-ZZ±hhmm
The final "±hhmm" is the UTC offset.
Valid examples include:
As seen in the example above, the date element can be omitted from the smallest date element up to (but not including) the year element. It is important to note that though the smaller date elements can be omitted, each of the above examples represent a date instance. So a date of "2010" represents "2010-01-01T00:00:00.000+0000".
1 2createdDate
ISO-8601 Date
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | yes | yes |
Find all users created exactly at 5:23pm on 15 December 2010:
1 2createdDate = 2010-12-15T17:23
Find all users created before 2010:
1 2createdDate < 2010
Find all users created after 15 December 2010 midnight:
1 2createdDate > 2010-12-15
Search for users updated on, before or after a particular date.
The date is specified in ISO-8601 format: YYYY-MM-DDTHH-MM-SS-ZZ±hhmm
The final "±hhmm" is the UTC offset.
Valid examples include:
As seen in the example above, the date element can be omitted from the smallest date element up to (but not including) the year element. It is important to note that though the smaller date elements can be omitted, each of the above examples represent a date instance. So a date of "2010" represents "2010-01-01T00:00:00.000+0000".
1 2updatedDate
ISO-8601 Date
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | yes | yes |
Find all users updated exactly at 5:23pm on 15 December 2010:
1 2updatedDate = 2010-12-15T17:23
Find all users updated before 2010:
1 2updatedDate < 2010
Find all users updated after 15 December 2010 midnight:
1 2updatedDate > 2010-12-15
The following fields may be used in group queries.
Search for groups with the specified name.
Note: this field supports partial-matching.
1 2name
String
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | yes | no | no |
Find the group with the name administrators:
1 2name = "administrators"
Find all groups with a name starting with admin:
1 2name = "admin*"
Find all groups with a name containing nistra:
1 2name = *nistra*
Search for groups with the specified active field value. The only valid values for active are: true, false.
1 2active
Boolean
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | no | no |
Find all active groups:
1 2active = true
Find all inactive groups:
1 2active = false
Search for groups created on, before or after a particular date.
The date is specified in ISO-8601 format: YYYY-MM-DDTHH-MM-SS-ZZ±hhmm
The final "±hhmm" is the UTC offset.
Valid examples include:
As seen in the example above, the date element can be omitted from the smallest date element up to (but not including) the year element. It is important to note that though the smaller date elements can be omitted, each of the above examples represent a date instance. So a date of "2010" represents "2010-01-01T00:00:00.000+0000".
1 2createdDate
ISO-8601 Date
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | yes | yes |
Find all groups created exactly at 5:23pm on 15 December 2010:
1 2createdDate = 2010-12-15T17:23
Find all groups created before 2010:
1 2createdDate < 2010
Find all groups created after 15 December 2010 midnight:
1 2createdDate > 2010-12-15
Search for groups updated on, before or after a particular date.
The date is specified in ISO-8601 format: YYYY-MM-DDTHH-MM-SS-ZZ±hhmm
The final "±hhmm" is the UTC offset.
Valid examples include:
As seen in the example above, the date element can be omitted from the smallest date element up to (but not including) the year element. It is important to note that though the smaller date elements can be omitted, each of the above examples represent a date instance. So a date of "2010" represents "2010-01-01T00:00:00.000+0000".
1 2updatedDate
ISO-8601 Date
= | = with wildcard (*) | > | < |
---|---|---|---|
yes | no | yes | yes |
Find all groups updated exactly at 5:23pm on 15 December 2010:
1 2updatedDate = 2010-12-15T17:23
Find all groups updated before 2010:
1 2updatedDate < 2010
Find all groups updated after 15 December 2010 midnight:
1 2updatedDate > 2010-12-15
You can use parentheses in complex CQL statements to enforce the precedence of #operators.
For example, if you want to find all users with a username of "bob", updated after January 2011, with either an email starting with "bob@ex" or the user was created before 1 January 2010, you can use parentheses to enforce the precedence of the boolean operators in your query, i.e.:
1 2name="bob" AND (email = "bob@ex*" OR createdDate < 2010) AND updatedDate > 2011-01
Note that if you do not use parentheses, the operators have the following precedence starting from least to most:
CQL has a list of reserved characters:
" "
)"+"
"."
","
";"
"?"
"|"
"*"
"/"
"%"
"^"
"$"
"#"
"@"
"["
"]"
"<"
">"
If you wish to use these characters in queries, you need to surround them with quote-marks (you can use either single quote-marks ('
) or double quote-marks ("
)).
For example:
1 2firstName = "John Smith"
While some of these characters are not being used at the moment, it is highly recommended that none of the characters in the above list are used as they may be used in future releases of Crowd.
CQL has a list of reserved words. These words need to be surrounded by quote-marks if you wish to use them in queries:
"and", "or", "<", ">"
You can use either single quote-marks ('
) or double quote-marks ("
).
While some of these words are not being used at the moment, it is highly recommended that none of the words in the above list are used unquoted, as they may be used in future releases of Crowd.
Rate this page: