The Digital Commerce APIs use the vlocity_cmtAPIParamsc field in the vlocity_cmtVlocityAPIMetaDatac sObject to configure request response fields, batch size, and other options. This field is also used to identify certain settings of the API while processing batch jobs or while processing API requests at run time.
However, the vlocity_cmt_APIParams__c field is by default limited to 255 characters. In some scenarios, this can be insufficient. For example, consider the following JSON request for a batch job:
{"batchSize":20,"scopeAll":true, "productFields" : ["vlocity_cmt__IsActive__c"]}
In this example, if you specify multiple fields in productFields, the vlocity_cmt_APIParams__c field might exceed the 255 character limitation. In such cases, to increase the number of characters this field can contain, you can override the default character limitation. To do this, you can create an Apex class along with an interface implementation. For example, create an implementation similar to the following sample.
Sample Implementation Name
DCAPIParamsImplementation
Sample Implementation Method
fetchAPIParamsOverride
Input
| Key | Type | Description |
|---|---|---|
| apiName | String | Defines the name of the API from vlocity_cmtVlocityAPIMetaDatac.vlocity_cmtAPINamec |
| params | String | Defines the parameters of the given API name. This represents vlocity_cmtVlocityAPIMetaDatac.vlocity_cmtVlocityAPIMetaDatac |
Output
| Key | Type | Description |
|---|---|---|
| result | String | Updates the API parameters for the given API name. |
Sample Implementation
/*
* We can override this default implementation by defining the following interface
* INTERFACE : DCAPIParamsInterface
*/
global class DCAPIParamsImplementation implements vlocity_cmt.VlocityOpenInterface {
public static Map < String, String > overiddenParamMap = new Map < String, String > {};
static {
//Field should have their own string here for getoffers api
overiddenParamMap.put('GetOffers', '{"batchSize":20,"productFields" : ["vlocity_cmt__IsActive__c"]}');
//Field should have their own string here for getofferdetails api
overiddenParamMap.put('GetOfferDetails', '{"batchSize":20}');
//Field should have their own string here for getrelatedofferdetails api
overiddenParamMap.put('GetRelatedOffers', '{"batchSize":20, "productFields" : ["vlocity_cmt__IsActive__c"]}');
}
global DCAPIParamsImplementation() {}
global static Boolean invokeMethod(String methodName, Map < String, Object > inputs, Map < String, Object > outputs, Map < String, Object > options) {
if (methodName == 'fetchAPIParamsOverride') {
return fetchAPIParamsOverride(inputs, outputs, options);
}
return false;
}
/*
Inputs :
1) key : apiName, type : String
2) key : params, type : String
Outputs :
1) key : result, type : String
*/
public static Boolean fetchAPIParamsOverride(Map < String, Object > inputs, Map < String, Object > outputs, Map < String, Object > options) {
String apiName = (String) inputs.get('apiName');
String overiddenParam = overiddenParamMap.get(apiName) == null ? ((String) inputs.get('params')) : overiddenParamMap.get(apiName);
outputs.put('result', overiddenParam);
return true;
}
}