Add Products API

Receive a CPQ quote, product collection, and quote group key in a request, and return a Quote model with all provided products added as quote lines.

Required Editions
Available in: Salesforce CPQ Summer ’16 and later
Formats

JSON, Apex

HTTP Method

PATCH

Authentication

Authorization: Bearer token

REQUEST

Parameter 1

Name: quote

Type: QuoteModel

Required: Yes

Description: A representation of SBQQ__Quote__c data

Parameter 2

Name: products

Type: ProductModel[]

Required: Yes

Description: An array of representations of product data

Parameter 3

Name: groupKey

Type: Integer

Required: Required only for grouped quotes

Description: An index of the existing quote line group where you’re adding products (0 indexed by default)

Parameter 4

Name: ignoreCalculate

Type: Boolean

Required: Yes

Description: Always use true for this value

RESPONSE

Type

QuoteModel

Description

The representation of SBQQ__Quote__c data

REST Examples 

1curl "https://YOURINSTANCE.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteProductAdder" 
2-H "Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d "@adderContext.json"

This request body adderContext.json file reads a product. The context value is a JSON formatted string.

1{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\",\"url\":\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\"},
2\"Name\":\"Q-00905\",\"Id\":\"a0p61000004IpR8AAK\"},\"nextKey\":2,\"netTotal\":0.00,\"lineItems\":[],\"lineItemGroups\":[],
3\"customerTotal\":0.00},\"products\":[],\"groupKey\":0, \"ignoreCalculate\": true}"}

An example response body after adding a product. The actual response is a JSON formatted string.

1{
2  "record": {
3    "attributes": {
4      "type": "SBQQ__Quote__c",
5      "url": "/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK"
6    }
7  },
8  "nextKey": 4,
9  "netTotal": 0.00,
10  "lineItems": [
11    {
12      "record": {
13        "attributes": {
14          "type": "SBQQ__QuoteLine__c"
15        },
16        "SBQQ__Product__c": "01t610000033JNtAAM"
17      },
18      "productQuantityEditable": true,
19      "productHasDimensions": false,
20      "key": 3,
21      "descriptionLocked": false
22    },
23    {
24      "record": {
25        "attributes": {
26          "type": "SBQQ__QuoteLine__c"
27        },
28        "SBQQ__Product__c": "01t610000033JNUAA2",
29        "SBQQ__Product__r": {
30          "attributes": {
31            "type": "Product2",
32            "url": "/services/data/v41.0/sobjects/Product2/01t610000033JNUAA2"
33          },
34          "Id": "01t610000033JNUAA2",
35          "Name": "Product 2",
36          "ProductCode": "P2"
37        }
38      }
39    }
40  ],
41  "lineItemGroups": [
42    {
43      "record": {
44        "attributes": {
45          "type": "SBQQ__QuoteLineGroup__c",
46          "url": "/services/data/v41.0/sobjects/SBQQ__QuoteLineGroup__c/a0k61000008WIF1AAO"
47        },
48        "SBQQ__Quote__c": "a0p61000004IpR8AAK",
49        "Id": "a0k61000008WIF1AAO",
50        "SBQQ__Number__c": 1.0,
51        "SBQQ__SeparateContract__c": false,
52        "Name": "Group1"
53      },
54      "key": 2,
55      "hasMultiSegmentLines": false
56    }
57  ],
58  "customerTotal": 0.00
59}

Apex Examples 

Before saving the ProductAdder example class, make sure that the CPQ model classes are added as individual Apex classes in your org.

1public with sharing class ProductAdder {
2    
3    public QuoteModel add(QuoteModel quote, ProductModel[] products, Integer groupKey) {
4        AddProductsContext ctx = new AddProductsContext(quote, products, groupKey);
5        String quoteJSON = SBQQ.ServiceRouter.load('SBQQ.QuoteAPI.QuoteProductAdder', null, JSON.serialize(ctx));
6        return (QuoteModel) JSON.deserialize(quoteJSON, QuoteModel.class);
7    }
8
9    private class AddProductsContext {
10        private QuoteModel quote;
11        private ProductModel[] products;
12        private Integer groupKey;
13        private final Boolean ignoreCalculate = true; //Must be hardcoded to true
14    
15        private AddProductsContext(QuoteModel quote, ProductModel[] products, Integer groupKey) {
16            this.quote = quote;
17            this.products = products;
18            this.groupKey = groupKey;
19        }
20    }
21}

For an example of the ProductAdder, run the following code in anonymous Apex.

1QuoteModel quoteModel; //Use Read Quote API to obtain a QuoteModelProductModel
2productModel; //Use Read Product API to obtain a ProductModel
3
4List<ProductModel> productModels = new List<ProductModel>();
5productModels.add(productModel);
6ProductAdder adder = new ProductAdder();
7QuoteModel quoteWithProducts = adder.add(quoteModel, productModels, 0);
8System.debug(quoteWithProducts);