Relativity Services API (RSAPI) DTOs have been deprecated and are no longer supported. For more information and alternative APIs, see RSAPI deprecation process.

Query for resources

To query data, you can use the POST method and specify a condition in body of the request. The POST method provides you with the option to build complex queries without the restrictions that browsers impose on the number of characters in a URL. You can also run queries with empty bodies that contain no conditions or sort order designation. This type of query is equivalent to the condition where ArtifactID > 0, which the Services API currently supports. For more information, see Query options.

A successful query returns all the results for small data sets or uses paging to return a subset of results for large data sets. When paging is used, the response includes the first page of data, and a token for retrieving subsequent pages as illustrated in the following example. For more information, see Paging.

{
"__Location":http://localhost/Relativity.REST/Workspace/1015423/Document/QueryResult/1437867?start=1&count=1000
 }
        

Note: You can also query for objects through the Object Manager service. For more information about this service, see Query for Relativity objects.

This page contains the following information:

Query options

The body of a POST request for a query may include a JSON representation that contains fields specifying a condition, sort order, and other parameters. This JSON representation of a query illustrates the use of fields.

{
   "condition":" 'Artifact ID' == 1109807",
   "sorts":["Artifact ID"],
   "fields":[{"*"}]
}

You use Field IDs, Field names, or GUIDs in a JSON array of fields. Field names used in JSON representations follow StrictMode mode conventions to ensure that resource and DTO property names match. For a list of these strings, see Constant Field names.

Query code sample

The following code sample illustrates how to query for a workspace resource:

//Set up the client.
            
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost/");
 
//Set the required headers.
            
httpClient.DefaultRequestHeaders.Add("X-CSRF-Header", string.Empty);
httpClient.DefaultRequestHeaders.Add("Authorization", "Basic c2FtcGxlYWRtaW5AcmVsYXRpdml0eS5yZXN0OlMwbTNwQHNzdzByZA==");
 
//Call Query on a Workspace.
            
string url = "Relativity.REST/Relativity/Workspace/QueryResult";
StringContent content = new StringContent(QueryInputJSON, Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.PostAsync(url, content).Result;
string result = response.Content.ReadAsStringAsync().Result;
bool success = HttpStatusCode.Created == response.StatusCode;
 
//Parse the result with Json.NET.
            
JObject resultObject = JObject.Parse(result);
        

You can view additional code samples that illustrate how to perform queries and the related JSON results in the following reference sections:

Syntax for query conditions

You can use the syntax examples in the following table as models for defining query conditions. Make sure that your query conditions don't include special characters such as underscore (_).

Special characters

Your query conditions may require the use of special characters that need to be escaped in your code.

The following table lists special characters that need to be escaped when used in query conditions:

Character

Description

\' Single quotation mark - used for character literals.
\" Double quotation marks - used for string literals.
\\ Backslash
\b Backspace (ASCII character 8)
\f Form feed (ASCII character 12)
\n New line (ASCII character 10)
\r Carriage return (ASCII character 13)
\t Horizontal tab (character 9)
\uxxxx Unicode escape sequence for a character with hexadecimal value of xxxx.
% Percent sign - used as a wildcard. This usage is specific to Relativity.
~ Tilde - used for handling a GUID or Integer as a field name.

Additionally, note that the compiler or interpreter for the programming language that you are using may pre-process strings in your code. For example, the following conditions produce the same result in C# and JavaScript:

  • Example 1:
    " 'Name' == 'chicago\u00A9land' "

    In this example, the compiler or interpreter evaluates the string as chicago©land, which is fed directly into condition parser used by Relativity. Since no escape characters are present, the parser proceeds as normal.

  • Example 2:
    " 'Name' == 'chicago\\u00A9land' "

    In this second example, the extra backslash instructs the compiler or interpreter to escape the Unicode sequence, so it is evaluated as chicago\u00A9land. The Relativity condition parser then further interprets the Unicode escape sequence and evaluate this string to chicago©land.

Supported data grid query operators

Use these operators to query Data Grid-enabled fields:

  • IS SET
  • IS NOT SET
    Notes:
  • The IS SET condition operator excludes the Data Grid records where the field is null or has an empty string value.
  • IS LIKE operator is not supported.

Example: Query for documents in a saved search

To query for documents in a Relativity saved search:

  1. Set up your REST client.

    Headers

    • X-CSRF-Header Cross-site request forgery protection header.

      Note: Set the X-CSRF-Header to any value except an empty string. In general, the header value is set to a dash (-). Don't leave this header value blank.

    • Authorization Relativity user name and password in base64 encoding.

    Content-type

    • application/json
      
  2. Query the existing saved searches in the workspace to find the Artifact ID of the search you want to use. Perform a GET request against this REST API endpoint:
    http(s)://<hostname>/Relativity.REST/Workspace/<workspace artifact ID>/Search

    Note: You can find the Artifact ID of the workspace on the Relativity home view as the Case Artifact ID field. It is also the value of the AppID parameter of the URL when the workspace open in Relativity.

    The response is a collection of saved search objects.

    Use the content of the response to find the Artifact ID of the saved search you want to use in your query.

  3. To query the documents in the saved search, perform a POST request against this REST API endpoint:
    http://relativity.domain.com/Relativity.REST/Workspace/<workspace artifact ID>/Document/QueryResult

    Use this request payload to specify that you want to return all documents in the saved search sorted by Artifact ID with all fields included:

    {
         "condition":"'ArtifactId' IN SAVEDSEARCH 1039270",
         "sorts":["Artifact ID"],
         "fields":["*"]
    }

    See Syntax for query conditions above for setting different type of conditions in you request.

    The response is a collection of document objects.