Create a product, a tax code, and associate them to a tag
- Step 1: Create a POST request
- Step 2: Configure authorization
- Step 3: Configure headers
- Step 4: Add JSON payload
- Step 5: Send your request
This example shows how to create a new product together with a tax code and associate them to a tag.
To try out the steps in this section, install Postman and open the Postman collection we have prepared for you. In the collection, open the Create a product and tax code, associate them to a tag request and replace variables with actual values.
Download Postman Open Postman Collection
Step 1: Create a POST request
Configure your application to send the following composite request:
POST https://{your_Salesforce_domain}/services/data/v44.0/composite
where
- {your_Salesforce_domain} is your Salesforce sandbox or production domain, for example, my-domain-1234.cs89.my.salesforce.com.
- v44.0 is the Force.com REST API version you want to use.
Step 2: Configure authorization
Make sure your request uses OAuth 2.0. Authorization data must be included in the request URL.
Step 3: Configure headers
Configure the request headers to include the following key-value pairs:
Key | Value |
---|---|
Authorization | Bearer {access_token} Example: Bearer 00D0N000000h6Yq!AR0AQObORnk9lCldrMydk1Y3cuyqpscqcU.T1xvoM1uWkWrr8MLu2ehJLKp7Mz3Qeu.eQGI13qlH_HfGEEMxV_J8FdI1TwdR |
Content-Type | application/json |
Step 4: Add JSON payload
Add your JSON payload to the request body. For example:
{
"allOrNone" : true,
"compositeRequest" :
[
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/Sage_COR_Company__c/a1C0Y0000011P37UAE?fields=Legislation__c,Id",
"referenceId" : "Company"
},
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/Sage_ACC_Dimension__c/UID__c/Product/?fields=Id",
"referenceId" : "ProductDimension"
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/Product2",
"referenceId" : "MyNewProduct",
"body" : {
"Name" : "My New Product"
}
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/Sage_TAX_Tax_Code__c/",
"referenceId" : "MyNewTaxCode",
"body" : {
"Name" : "MyNewTaxCode",
"Code__c": "123456",
"Legislation__c": "@{Company.Legislation__c}",
"UID__c": "AvaTax_123456"
}
},
{
"method" : "POST",
"referenceId" : "MyNewProductTag",
"url" : "/services/data/v44.0/sobjects/Sage_ACC_Tag__c/",
"body" : {
"Name" : "MyNewProduct",
"Dimension__c": "@{ProductDimension.Id}",
"Company__c": "@{Company.Id}",
"Product__c": "@{MyNewProduct.id}",
"Tax_Code__c": "@{MyNewTaxCode.id}"
}
}
]
}
In this example payload:
- GET /services/data/v44.0/sobjects/Sage_COR_Company__c/a1C0Y0000011P37UAE?fields=Legislation__c,Id
Retrieves the ID and Legislation values of the Company whose ID isa1C0Y0000011P37UAE
. Stores the ID and Legislation values in theCompany
variable. - GET /services/data/v44.0/sobjects/Sage_ACC_Dimension__c/UID__c/Product/?fields=Id
Retrieves the ID of the Product dimension and stores it in theProductDimension
variable. - POST /services/data/v44.0/sobjects/Product2
Creates a new product named My New Product and stores it in theMyNewProduct
variable. - POST /services/data/v44.0/sobjects/Sage_TAX_Tax_Code__c/
Creates a new tax code named MyNewTaxCode. The code value is 123456 and its unique ID is AvaTax_123456. The tax code uses the Legislation value from theCompany
variable. - POST /services/data/v44.0/sobjects/Sage_ACC_Tag__c/
Creates a new tag named MyNewProduct. The tag uses the dimension from theProductDimension
variable, company from theCompany
variable, product from theMyNewProduct
variable, and tax code from theMyNewTaxCode
variable.
Consider the following behavior of Salesforce:
- When retrieving data from a variable that stores the result of a GET operation, you must use an upper-case
Id
like in"Dimension__c": "@{ProductDimension.Id}"
in the example payload. - When retrieving data from a variable that stores the result of a POST operation, you must use a lower-case
id
like in"Product__c": "@{MyNewProduct.id}"
in the example payload.
NOTE: We use the referenceId
parameter in the fifth request just because it must be present in each request that’s part of a composite request.
Step 5: Send your request
Send your request to create the product, tax code, and tag.