Context Combinations API

The Context Combinations API generates a cartesian product of all the sets of dimension combination values passed in the request body. If a context dimension is not passed in the request, all the valuesForCaching are used for that dimension to generate the cartesian product. This API also returns a cache key that is required by the context eligibility API.

Keep the pageSize option under 20 to avoid reaching Salesforce governor limits.

You can obtain the dimensions required for the request body of this API from the apiResponse node in the response body of the Context Dimensions API. The code for each element in the API response becomes the key of the dimensions hash map and the valuesForCaching forms its values.

Precondition 

You must first run the Context Dimensions API to obtain the dimensions required for the request body of this API.

URI 

/services/apexrest/{namespace}/v3/admin/catalogs/{catalogCode}/contextcombinations

HTTP Method 

POST

URI Parameters 

If you specify just one of these two parameters, it follows the behavior described in the table below and accepts your defined time for the parameter you specified. If you are using one or both parameters, you must specify them with the same values for all of the Populate Cache APIs in this sequence.

ParameterExampleDefaultOptional/RequiredNotes
effectiveStartTime2001-07-04T12:08:56Current date and timeOptionaleffectiveStartTime is the time that you want your cached catalog entries to be effective. It should be in the UTC date-time format. Your effectiveStartTime must occur after the current time for which you are executing the Populate Cache APIs or you will receive an error message.
expirationTime2001-07-04T12:08:56effectiveStartTime + TimeToLiveOptionalexpirationTime is the time that you want your cached catalog entries to expire. It should also be in the UTC date-time format. Your expirationTime must occur after your effectiveStartTime or you receive an error message. TimeToLive is a custom setting created in CPQ Configuration Setup. It has a default value of 30 days.

Here is an example of how to pass the URI parameters:

1GET /services/apexrest/vlocity_cmt/v3/admin/catalogs/AS-Test-Catalog/contextcombinations?effectiveStartTime=2021-07-04T12:08:56&expirationTime=2021-08-04T12:08:56

Request Body Parameters 

For example,

Parameter

Data Type

Description

Default

Optional/Required

dimensions

Map/Dictionary/Associative array

Key = String

Value = List of strings

Map containing only the dimensions for which you want to reduce the number of values used for creating combinations. This API lets you generate only cached entries for specific context dimensions and values, for example, you can calculate combinations for Gold and Silver values for an Account SLA dimension.

You can leave this parameter blank if you want to perform all the context combinations relevant to your sales catalog or are not using any context dimensions with your catalog.

You can obtain the dimensions required for the request body of this API from the apiResponse node in the response body of the Context Dimensions API.

N/A

Required

pagesize

Positive integer

Number of entries to process

20

Optional

offset

Non-negative integer

Index of the entry from which to start processing

0

Optional

1{
2    "dimensions": {
3    },
4    "pagesize": 4,
5    "offset":12
6}

Sample Request Body 

This is a sample request for a catalog without rules assigned to its offers.

1{
2    "dimensions": { // This map defines the deviations that you want from the default behavior of the API. If you want the default behavior i.e. populate all combinations, you can leave this hashmap blank.
3        "D1": [
4            "V1",
5            "V2"
6        ],
7        "D2": [
8            "V3",
9            "V4"
10        ],
11        "D3": [
12            "V5",
13            "V6"
14        ],
15        "D4": [
16            "V7",
17            "V8"
18        ]
19    },
20    "pagesize": 4,
21    "offset":12
22}
23
24Here there are 4 dimensions and for each dimension, there are two values.
25Hence there are 16 possible combinations of dimensions:
26
27D1:V1, D2:V3, D3:V5, D4:V7
28D1:V1, D2:V3, D3:V5, D4:V8
29D1:V1, D2:V3, D3:V6, D4:V7
30D1:V1, D2:V3, D3:V6, D4:V8
31
32D1:V1, D2:V4, D3:V5, D4:V7
33D1:V1, D2:V4, D3:V5, D4:V8
34D1:V1, D2:V4, D3:V6, D4:V7
35D1:V1, D2:V4, D3:V6, D4:V8
36
37D1:V2, D2:V3, D3:V5, D4:V7
38D1:V2, D2:V3, D3:V5, D4:V8
39D1:V2, D2:V3, D3:V6, D4:V7
40D1:V2, D2:V3, D3:V6, D4:V8
41
42D1:V2, D2:V4, D3:V5, D4:V7
43D1:V2, D2:V4, D3:V5, D4:V8
44D1:V2, D2:V4, D3:V6, D4:V7
45D1:V2, D2:V4, D3:V6, D4:V8
46
47The above API call will return 4 combinations starting from the 12th combination. i.e.
48
49D1:V2, D2:V4, D3:V5, D4:V7
50D1:V2, D2:V4, D3:V5, D4:V8
51D1:V2, D2:V4, D3:V6, D4:V7
52D1:V2, D2:V4, D3:V6, D4:V8

Remote API 

This is an example of how you invoke the API using Apex:

1String methodName;
2String requestBodyJSON;
3Map<String, Object> input = new Map<String, Object>();
4Map<String, Object> output = new Map<String, Object>();
5Map<String, Object> options = new Map<String, Object>();
6
7// Setting remote parameters
8methodName = 'getContextCombinations';
9requestBodyJSON = '{"dimensions":{"D1":["V1","V2"],"D2":["V4","V5"]},"offset":20,"pagesize":10}';
10input.put('apiName','CMContextCombinations'); // required
11input.put('catalogCode', 'TestCatalog');    // required
12input.put('effectiveStartTime', null);      // optional
13input.put('expirationTime', null);          // optional
14input.put('requestBody', requestBodyJSON);  // required
15input.put('methodName',methodName);         // required
16input.put('requestURL', '/v3/admin/catalogs/TestCatalog/contextcombinations'); //required
17
18//remote action invocation
19vlocity_cmt.CpqAppHandler appHandler = new vlocity_cmt.CpqAppHandler();
20appHandler.invokeMethod(methodName, input, output, options);

Parallel Invocation 

You can run this API in parallel for multiple catalogs. For example, you may have 100 catalogs (Catalog1, Catalog2..Catalog 100). Each catalog has five dimensions with three values each. This gives you a total of 243 combinations for each catalog. If you have a page size of 20, this gives you 13 pages per catalog with a total of 1,300 combinations. Each of these pages can be populated in parallel threads.

1THREAD1 -  POST /services/apexrest/{namespace}/v3/admin/catalogs/catalog1/contextcombinations
2THREAD2 -  POST /services/apexrest/{namespace}/v3/admin/catalogs/catalog1/contextcombinations
3...
4THREAD13 - POST /services/apexrest/{namespace}/v3/admin/catalogs/catalog1/contextcombinations
5THREAD14 - POST /services/apexrest/{namespace}/v3/admin/catalogs/catalog2/contextcombinations
6......
7THREAD1300 - POST /services/apexrest/{namespace}/v3/admin/catalogs/catalog100/contextcombinations

HTTP Headers 

HeaderDescription
Content-Typeapplication/json

Response Body 

This example shows a cartesian product of dimension combination values passed in the request body.

1{
2    "cacheKey": "fac5fff741e461da4b74355c892277ec",
3    "apiResponse": [
4        {
5            "D1": "V1",
6            "D2": "V4"
7        },
8        {
9            "D1": "V1",
10            "D2": "V5"
11        },
12        {
13            "D1": "V2",
14            "D2": "V4"
15        },
16        {
17            "D1": "V2",
18            "D2": "V5"
19        }
20    ],
21    "catalogCode": "allDimensionProductsCatalog-",
22    "errorCode": "INVOKE-200",
23    "error": "OK"
24}

HTTP Response Codes 

CodeDescription
200OK
500Internal Server Error