Read Product API

The Read Product API takes the request’s product ID, pricebook ID, and currency code and returns a Product model. The Product model loads the product from your catalog when the user requests it.

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

JSON, Apex

HTTP Method

PATCH

Authentication

Authorization: Bearer token

Special Access Rules 

Users must have read access to the product2 object.

Request 

Parameter 1

Name: productId

Type: ID

Required: Yes

Description: The ID of the product record to load

Parameter 2

Name: pricebookId

Type: ID

Required: Yes

Description: The ID of the pricebook that contains the product record to load

Parameter 3

Name: currencyCode

Type: String

Required: Required only for multi-currency orgs

Description: The ISO code of a Salesforce currency where the product’s price is loaded

Response 

Type

ProductModel

Description

The representation of product data

REST Examples 

1curl "https://YOURINSTANCE.salesforce.com/services/apexrest/SBQQ/ServiceRouter?loader=SBQQ.ProductAPI.ProductLoader&uid=01t610000033JNt" -H "Content-Type: application/json" -H "Authorization: Bearer token" -X PATCH -d "@loaderContext.json"

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

1{"context" : "{\"pricebookId\": \"01sA0000000wuhg\", \"currencyCode\":\"USD\"}"}

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

1{
2  "record": {
3    "attributes": {
4      "type": "Product2",
5      "url": "/services/data/v42.0/sobjects/Product2/01tA0000005uzfZ"
6    },
7    "Id": "01tA0000005uzfZ",
8    "Name": "Apple"
9  },
10  "options": [],
11  "features": [],
12  "configuration": {}
13}

Apex Examples 

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

1public with sharing class ProductReader { 
2    
3    public ProductModel read(Id productId, Id pricebookId, String currencyCode) {
4        ProductReaderContext ctx = new ProductReaderContext(pricebookId, currencyCode);
5        String productJSON = SBQQ.ServiceRouter.load('SBQQ.ProductAPI.ProductLoader', productId, JSON.serialize(ctx));
6        return (ProductModel) JSON.deserialize(productJSON, ProductModel.class);
7    }
8    
9    private class ProductReaderContext {
10        private Id pricebookId;
11        private String currencyCode;
12        
13        private ProductReaderContext(Id pricebookId, String currencyCode) {
14            this.pricebookId = pricebookId;
15            this.currencyCode = currencyCode;
16        }
17    } 
18}

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

1ProductReader reader = new ProductReader();
2ProductModel product = reader.read('01tj0000003P1SN','01sj0000003THhKAAW','USD');
3System.debug(product);