I have added products and calculated quote using the below apex class:
public class CpqEditQuoteApi {
public static string editAPI(String quoteId, String productId, Integer quantity){
//get access token from custom setting
CPQ_Acess_Token__c ct = [Select name, Access_Token__c FROM CPQ_Acess_Token__c WHERE name = 'Access Token' LIMIT 1 ];
String Token = ct.Access_Token__c;
System.debug('Access token from custom setting ==> '+Token);
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://<my instance>.my.salesforce.com/services/apexrest/SBQQ/ServiceRouter');
req.setHeader('Content-Type', 'application/json; charset=utf-8');
req.setHeader('Authorization', 'Bearer '+Token);
//set body with selected quoteid & productid
req.setBody('{"saver": "SBQQ.QuoteAPI.QuoteSaver", "model": "{\\\"record\\\":{\\\"attributes\\\":{\\\"type\\\":\\\"SBQQ__Quote__c\\\",\\\"url\\\":\\\"/services/data/v59.0/sobjects/SBQQ__Quote__c/' + productId + '\\\"},\\\"Name\\\":\\\"Q-00132\\\",\\\"Id\\\":\\\"' + quoteId + '\\\"},\\\"nextKey\\\":2,\\\"netTotal\\\":0.00,\\\"lineItems\\\":[{\\\"record\\\": {\\\"attributes\\\": {\\\"type\\\":\\\"SBQQ__QuoteLine__c\\\"},\\\"SBQQ__Product__c\\\": \\\"' + productId + '\\\",\\\"SBQQ__Quantity__c\\\":'+ quantity +' ,\\\"SBQQ__ConfigurationRequired__c\\\":true},\\\"productQuantityEditable\\\": true,\\\"productHasDimensions\\\": false,\\\"key\\\": 1,\\\"descriptionLocked\\\": false}],\\\"lineItemGroups\\\":[],\\\"customerTotal\\\":0.00}"}');
req.setTimeout(120000);
HttpResponse res = new Http().send(req);
System.debug(res.toString());
System.debug(res.getBody());
System.debug('res' + res);
System.debug('Response body: ' + res.getBody()); // debug response body
//Read Quote API
QuoteReader reader = new QuoteReader();
QuoteModel quoteModels = reader.read(quoteId);
System.debug('quoteModel: ' + quoteModels);
//Read Product
ProductReader reader1 = new ProductReader();
ProductModel product1 = reader1.read(productId,'01s2w00000N5qciAAB','USD');
System.debug('Product Model: '+product1);
//Add Product
List<ProductModel> productModels = new List<ProductModel>();
productModels.add(product1);
ProductAdder adder = new ProductAdder();
QuoteModel quoteWithProducts = adder.add(quoteModels, productModels, 0);
System.debug('Quote with Product: '+quoteWithProducts);
//Calculate quote API;
quoteModels.lineItems[0].record.SBQQ__Quantity__c = quantity;
QuoteCalculator calculator = new QuoteCalculator();
calculator.calculate(quoteModels, 'MyCallback');
//Update the quote with Response body
SBQQ__Quote__c quote = [SELECT Id, CPQ_API_Response__c FROM SBQQ__Quote__c WHERE Id =: quoteId];
quote.CPQ_API_Response__c = res.getBody();
update quote;
return res.getBody();
}
}
Now I want to add a bundle product with option how we can achieve this? What I need to change with my code to add bundle product with its options?
