CPQ API Quickstart Guide
CPQ API Quickstart Guide
Review examples of integrating Salesforce CPQ API with your platform.
| Available in: Salesforce CPQ Summer ’16 and later |
Anonymous Apex
This example reads a quote, adds a product, and saves the quote.
1/**
2 * Note: this doesn’t perform a calculation. Reference the calculate API to see how to calculate a quote.
3 */
4
5//the Id of the quote
6String quoteId = 'a0Wf100000J1vk1';
7
8//the Id of the product to add to the quote
9String productId = '01tj0000003P1SN';
10
11//the Id of the pricebook for the quote and product being added
12String pricebookId = '01sj0000003THhKAAW';
13
14//the currency code
15String currencyCode = 'USD';
16
17//the JSON formatted String representing the quote model to add a product to
18String quoteModel = SBQQ.ServiceRouter.read('SBQQ.QuoteAPI.QuoteReader', quoteId);
19
20//the JSON formatted String representing the product to be added to the quote
21String productModel = SBQQ.ServiceRouter.load('SBQQ.ProductAPI.ProductLoader', productId, '{"pricebookId" : "' + pricebookId + '", "currencyCode" : "' + currencyCode + '"}');
22
23//the JSON formatted String representing the quote with the product added to it
24String updatedQuoteModel = SBQQ.ServiceRouter.load('SBQQ.QuoteAPI.QuoteProductAdder', null, '{"quote" : ' + quoteModel + ', "products" : [' + productModel + '], "ignoreCalculate" : true}');
25
26//the JSON formatted String represeting the saved quote
27String savedQuoteModel = SBQQ.ServiceRouter.save('SBQQ.QuoteAPI.QuoteSaver', updatedQuoteModel);NODEJS
This example reads a quote, adds a product, calculates the quote, and saves it.
1// 3rd party library to call into a Salesforce org
2var jsforce = require('jsforce');
3
4// login credentials to the org
5var loginUrl = 'https://MyDomainName.my.salesforce.com'; // Your org’s My Domain login URL is listed on the My Domain Setup page.
6var username = 'admin.user@company.com';
7var password = 'password';
8
9// quote and product details
10var quoteId = 'a0bA000000FW2o4';
11var productId = '01tA0000005NsiA';
12var pricebookId = '01tA0000005NsiA';
13var currencyCode = 'USD';
14
15// log in to the org with with a valid username and password using jsforce
16var conn = new jsforce.Connection({loginUrl: loginUrl});
17conn.login(username, password).then(function () {
18 return Promise.resolve(conn);
19})
20
21.then(function (conn) {
22 // read both the quote and the product to add
23 var quotePromise = conn.apex.get('/SBQQ/ServiceRouter?reader=SBQQ.QuoteAPI.QuoteReader&uid=' + quoteId);
24 var productPromise = conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.ProductAPI.ProductLoader&uid=' + productId, {
25 context: JSON.stringify({
26 pricebookId: pricebookId,
27 currencyCode: currencyCode
28 })
29 });
30 return Promise.all([quotePromise, productPromise]);
31})
32
33.then(function (models) {
34 // add the retrieved product to the retrieved quote in the first group
35 var quoteModel = JSON.parse(models[0]);
36 var productModel = JSON.parse(models[1]);
37 return conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteProductAdder', {
38 context: JSON.stringify({
39 quote: quoteModel,
40 products: [productModel],
41 groupKey: 0,
42 ignoreCalculate: true
43 })
44 });
45})
46.then(function (quoteWithProduct) {
47 var quote = JSON.parse(quoteWithProduct);
48 // calculate the quote with the added product
49 return conn.apex.patch('/SBQQ/ServiceRouter?loader=SBQQ.QuoteAPI.QuoteCalculator', {
50 context: JSON.stringify({
51 quote: quote
52 })
53 });
54})
55.then(function (calculatedQuote) {
56 var quote = JSON.parse(calculatedQuote);
57 // save the calculated quote
58 return conn.apex.post('/SBQQ/ServiceRouter', {
59 saver: 'SBQQ.QuoteAPI.QuoteSaver',
60 model: JSON.stringify(quote)
61 });
62})
63.then(function (savedQuoted) {
64 // log the quote has been saved
65 console.log('Quote finished processing', savedQuoted);
66});