Constructing composite requests
The /composite
endpoint
To create a composite request, use the /composite
endpoint in the
Composite API. This is different than batches. Every API has its own /batch
endpoint. But in all of Cloud API, there is only one /composite
endpoint,
and it is in the Composite API.
The syntax for the composite request call is:
Sections of a composite request
A composite request can have up to two sections:
- A
requests
section, which contains the subrequests that commit data. - A
selections
section, which contains the subselections that query for data. These are executed after the subrequests, and only if all the subrequests commit data successfully.
At a high level, the syntax for these sections is as follows:
The requests
section
In the requests section, the only supported operations are POST,
PATCH, and DELETE. This includes both POSTs that create data and POSTs that execute business
actions (such as POST /assign
).
The basic syntax for the requests section is shown below.
For example, the following simple composite request creates two notes for activity xc:202.
For the complete syntax that includes all composite request features, see Complete composite request syntax.
Using variables to share information across subrequests
Information from one subrequest can be used in later subrequests. You can do this through the use of composite variables.
Declaring variables
Composite variables are declared in a subrequest's vars
section. Each
variable has a name
and path
. The name
is
an arbitrary string. The path
specifies what to set the variable to. It is
set to a JSON path expression that identifies a value in the subrequest's response payload.
For example, suppose a subrequest that creates an activity has the following:
This creates a variable named newActivityId
, which is set to the value of
the data section's attributes
section's id
field (which
would typically be the id of the newly created activity).
Referencing variables
To reference a variable, use the following syntax:
You can use variables anywhere in the body of a subrequest. The most common uses for variable values are:
- In an
attributes
field - Within the path of a
uri
- As part of a query parameter
For example, suppose there is a subrequest that creates an activity, and it is followed by
a subrequest that creates a note. The first subrequest creates a
newActivityId
variable as shown previously. The uri
for
the second subrequest is:
This would create the new note as a child of the first subrequest's activity.
The following is the complete code for the previous examples.
Responses to the subrequests
The response to a composite request contains a responses section. This section contains one subresponse for each subrequest. Every subresponse has three sections:
- A
body
section, which by default contains the default response data defined in the corresponding endpoint. - A
headers
section, which contains any custom headers. - A
status
field, which indicates the subresponse's status code.
For example, the following is the responses section and the first subresponse for a composite request whose first subrequest created an activity:
Fields whose values are generated when data is committed
The individual subresponses to each subrequest specify data that has technically not been committed yet. However, some fields contain values that are not generated until the data is committed.
When a subresponse includes a value that is generated as part of the commit, Cloud API makes effort to match the data that will be committed as closely as possible. For example, the composite request reserves id values so that these ids can be provided in subresponses and committed to the database.
But, there are some fields for which Cloud API cannot match the value. For example, the
values for createTime
and updateTime
cannot be determined
prior to the commit. Fields of this type are always omitted from a subrequest's subresponse.
But, they can be retrieved through a subselection.
Suppressing subresponse details
In some cases, a given object may be modified by multiple subrequests. This makes the intermediate subresponses unnecessary, and those subresponses can increase the size of the composite response unnecessarily and make the composite response harder to parse.
You can simplify the composite response by suppressing the amount of information returned for one or more subrequests. To do this, include the following with each relevant subrequest:
For example:
The composite response still includes a subresponse for the subrequest. But instead of providing the endpoint's default response, the subresponse appears as:
The responseIncluded
field defaults to true. If you want a detailed
response for a given subrequest, simply omit the responseIncluded
reference.
Using query parameters in subrequests
For a POST or PATCH subrequest, you can also refine which fields are returned. To do this, use the fields query parameter. The syntax for this is:
For example, the following code snippet creates an activity. For the subresponse, it specifies to include only the activity's id and the assigned user.
For a given API, you can see a complete list of all query parameters that can be used in
composite requests by executing a GET /openapi.json
call. If a query
parameter is available to composite requests, the OpenAPI output will include the following
line: "x-gw-allowForCompositeApi": true
.
The selections
section
The selections
section contains subselections that query for data. These are
executed after the subselections in the requests section, and only if all the subrequests
commit data successfully.
The basic syntax for the selections section is shown below. You do not need to specify a method for each subselection, as the only valid method in the selections section is GET.
For example, the following code creates a new activity and a note for that activity. It then queries for the newly created activity.
For the complete syntax that includes all composite request features, see Complete composite request syntax.
Using query parameters in the selections section
You can use certain query parameters for each subselection. This includes:
fields
filter
includeTotal
pageOffset
pageSize
sort
Each subselection is independent from the others. You can use different query parameters for each subselection, and you can have some subselections with query parameters and others without query parameters.
The syntax for adding query parameters to a subselection is as follows:
Note the following:
fields
is specified as a single string of one or more fields, delimited by commas. The entire string is surrounded by quotes.- For example,
"assignedUser,dueDate,priority,subject"
- For example,
filter
andsort
are stringified arrays consisting of one or more expressions. Each individual expression is surrounded by quotes. The list of expressions is then surrounded by [ and ].- For example:
["dueDate:gt:2022-12-20","status:in:open,complete"]
- For example:
includeTotal
,pageOffset
, andpageSize
are either Boolean or integer values, and therefore do not use quotes.
For example, when querying for activities, to return only the assigned user, due date, priority and subject fields:
To return only open and complete activities with due dates after 2022-12-20:
To return activities based on multiple criteria:
For a given API, you can see a complete list of all query parameters that can be used in
composite requests by executing a GET /openapi.json
call. If a query
parameter is available to composite requests, the OpenAPI output will include the following
line: "x-gw-allowForCompositeApi": true
.
Composite requests that execute only queries
You can create a composite request that does not create or modify data and instead only
queries for data. To do this, create a composite request with only a
selections
section and no requests
section. In this
case, the GETs in the selections
section are always executed.
Responses to the selections subrequests
When a composite request contains a selections
section, the response also
contains a selections
section. This section has the same structure as the
responses
section. It contains one subresponse for each subselection.
Every subresponse has three sections:
- A
body
section, which by default contains the default response data defined in the corresponding endpoint. - A
headers
section, which contains any custom headers. - A
status
field, which indicates the subresponse's status code.
Composite request limitations
Composite requests have the following general limitations:
- The number of subrequests and subselections in a single composite request must be less
than or equal to the value of the
MaximumAllowedNumberOfCompositeSubRequests
configuration parameter. (In the base configuration, this is set to 100.) - The subrequests can make use of other endpoints that are part of Cloud API. However, they cannot make use of endpoints outside of Cloud API, such as custom endpoints created by an insurer.
- You cannot use request inclusion in composite requests.
- For more information on request inclusion, see Request inclusion.
- You cannot include a subrequest that uses a content type other than application/json.
- For example, you cannot work with document resources in composite requests, as documents use multipart/form-data.
- You cannot use any POST
/search/...
endpoint in a composite request (such as the ClaimCenter POST/claim/v1/search/claims-v2
or the PolicyCenter POST/policy/v1/search/policies
endpoint) - There is no mechanism for iterating over a set of things.
- For example, you cannot start with a list of elements and include related resources for each item in that list.
There may be some business requirements where you are required to use a composite request. For example, when creating a new claim with an unverified policy, you must create the policy and claim in a composite request.
There are also specific business requirements where you cannot use a composite request. For example:
- You cannot have a single composite request operate on more than one claim.
- For service requests that are Quote Only, Quote and Service, or Service Only, you can create and submit a service request in a single composite request. But you cannot advance these types of service requests to any other stage in its life cycle (such as in progress, declined, or canceled at the vendor’s or insurer’s request) in the same composite request.
- Within a composite request, the only financial object you can create or
modify is final non-recurring check sets. You otherwise cannot create or modify financial
objects. This includes reserve sets and reserve transactions, recurring check sets and
payment transactions, and the check life cycle endpoints (such as POST
/mark-issued
). However, within a composite request, you can GET information on financial objects.
Many of the examples in the previous list pertain to situations where there must be an intermediate data commit, which composite requests do not allow by design. However, the previous list is not intended to be exhaustive. Refer to the section of the documentation that discusses each business requirement for more information on requirements or limitations related to composite requests.
Composite request examples
This documentation includes examples of composite requests for common business tasks. This includes the following:
- Creating a new claim with an unverified policy: Sample composite claim payload
- Creating, closing, and paying out a claim: Sample composite first-and-final