Using query parameters on included resources

Some endpoints support the ability to query for a given type of resource and for resource types related to that type. For example, by default, the GET /activities endpoint returns only activity resources. However, you can use the include query parameter to include any notes related to the returned activities in the response payload. These types of resources are referred to as included resources. The technique of adding included resources to a GET is sometimes referred to as response inclusion or read inclusion.

The syntax for adding included resources is:

?include=<resourceName>

For example GET /activities?include=notes returns all activities assigned to the current caller, and all notes associated with those activities.

For more information on the default behavior of include, see Payload structure for a response with included resources.

Most query parameters that can be used on primary resources can also be used on included resources.

Specifying query parameters that apply to an included resource

The general pattern for query expressions on included resources is to specify the included resource name somewhere in the expression's value. For example, the following call gets all activities assigned to the current user and any related notes. The number of notes returned is limited to 5.

GET /activities?include=notes&pageSize=notes:5

Included resources and primary resources

Query expressions for included resources are independent of query expressions for primary resources. There could be a query expression for primary resources only, for included resources only, or for both. For example, the following three queries all return activities and their related notes. But, the impact of the pageSize parameter varies.

  • GET /activities?pageSize=7&include=notes
    • The response is limited to 7 activities.
    • There is no limit on notes.
  • GET /activities?include=notes&pageSize=notes:5
    • There is no limit on activities.
    • The response is limited to 5 notes per activity.
  • GET /activities?pageSize=7&include=notes&pageSize=notes:5
    • The response is limited to 7 activities.
    • The response is limited to 5 notes per activity.

Included resources and other included resources

Query expressions for each included resource are also independent of query expressions for other included resources. If a given GET includes multiple included resources and you want to apply a given query expression to all included resources, you must specify the query expression for each included resource.

For example, suppose you want to GET all claims. But you want the response payload to include only the main contact and reporter, and you want only the id, primary phone, and work phone for these contacts. To get this response, you must send the following:

GET /claims?include=mainContact,reporter
           &fields=mainContact,reporter
           &fields=mainContact:id,primaryPhone,workPhone
           &fields=reporter:id,primaryPhone,workPhone

Note that, in this example, the logic to restrict the returned fields to only id, primary phone, and work phone needs to be specified for each included resource.

Summary of query parameters for included resources

The filter parameter

You can filter out included resources that do not meet a given criteria.

  • Syntax: filter=resource:field:op:value
  • Example:
    GET claim/v1/claims/demo_sample:1?
           include=activities&
           filter=activities:escalated:eq:true
  • Returns: Claim demo_sample:1 and its included activities that have been escalated

The fields parameter

You can specify which fields you want returned in the included resources.

  • Syntax: fields=resource:field_list
  • Example:
    GET claim/v1/claims/demo_sample:1?
              include=activities&
              fields=activities:id,dueDate
  • Returns: Claim demo_sample:1 and its included activities. For the activities, return only id and dueDate.

The sort parameter

You can sort the included resources. This sorting is reflected in both the payload's related sections and the included section.

  • Syntax: sort=resource:properties_list
  • Example:
    GET claim/v1/claims/demo_sample:1?
              include=activities&
              sort=activities:dueDate
  • Returns: Claim demo_sample:1 and its included activities, sorted by their due date.

The pageSize parameter

You can specify a maximum number of included resources per root resource. Also, when you use pageSize on included resources, there are no prev and next links at the included resource level.

  • Syntax: pageSize=resource:n
  • Example:
    GET claim/v1/claims/demo_sample:1?
              include=activities&
              pageSize=activities:5
  • Returns: Claim demo_sample:1 and up to 5 of its included activities.

The includeTotal parameter

You can include the total number of included resources.

  • Syntax: includeTotal=resource:true
  • Example:
    GET claim/v1/claims/demo_sample:1?
              include=activities&
              includeTotal=activities:true
  • Returns: Claim demo_sample:1, its included activities, and the total number of included activities for demo_sample:1.

Tutorial: Send a GET with query parameters for included resources

This tutorial assumes you have set up your environment with Postman and the correct sample data set. For more information, see Tutorial: Set up your Postman environment.

Tutorial steps

  1. In Postman, start a new request by clicking the + to the right of the Launchpad tab.
    1. On the Authorization tab, select Basic Auth using user aapplegate and password gw.
  2. Enter the following and click Send:

    GET http://localhost:8080/cc/rest/claim/v1/claims?include=activities

  3. Open a second request tab and right-clicking the first tab and selecting Duplicate Tab.
  4. Enter the following and click Send:

    GET http://localhost:8080/cc/rest/claim/v1/claims?fields=id,claimNumber&include=activities&filter=activities:escalated:eq:true

Checking your results

Compare the two payloads. Note the following differences:

In the first payload:

  • For claims, the default claim fields are returned.
  • For activities, all activities are returned.

In the second payload:

  • For claims, only the id and claimNumber fields are returned.
  • For activities, only the escalated activities are returned.