Create an invoice together with required records
- 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 and post an invoice using only one existing record (Company). We create all other records required for the invoice from scratch.
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 an invoice together with required records 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, for example, v41.0.
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 JSON payload to the request body. For example:
{
"allOrNone" : true,
"compositeRequest" :
[
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Dimension__c/s2cor__UID__c/Customer/?fields=Id",
"referenceId" : "CustomerDimension"
},
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_COR_Company__c/a1G1N0000066tG6UAI?fields=Id",
"referenceId" : "Company"
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/Account",
"referenceId" : "NewAccount",
"body" : {
"Name" : "Example account 2"
}
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Tag__c",
"referenceId" : "NewCustomerTag",
"body" : {
"Name" : "Example customer tag 2",
"s2cor__Account__c": "@{NewAccount.id}",
"s2cor__Dimension__c": "@{CustomerDimension.Id}",
"s2cor__Company__c" : "@{Company.Id}"
}
},
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Dimension__c/s2cor__UID__c/Product/?fields=Id",
"referenceId" : "ProductDimension"
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/Product2",
"referenceId" : "NewProduct",
"body" : {
"Name" : "Example product 2"
}
},
{
"method" : "POST",
"referenceId" : "NewProductTag",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_ACC_Tag__c/",
"body" : {
"Name" : "Example product tag 2",
"s2cor__Dimension__c": "@{ProductDimension.Id}",
"s2cor__Company__c": "@{Company.Id}",
"s2cor__Product__c": "@{NewProduct.id}"
}
},
{
"method" : "GET",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document_Type__c/s2cor__UID__c/SalesInvoice_TD_US?fields=Id",
"referenceId" : "SalesInvoiceType"
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document__c",
"referenceId" : "NewSalesInvoice",
"body" : {
"s2cor__Account__c": "@{NewAccount.id}",
"s2cor__Trade_Document_Type__c": "@{SalesInvoiceType.Id}"
}
},
{
"method" : "POST",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document_Item__c",
"referenceId" : "NewLineItem",
"body" : {
"s2cor__Product__c": "@{NewProduct.id}",
"s2cor__Unit_Price__c": "1000.00",
"s2cor__Trade_Document__c": "@{NewSalesInvoice.id}"
}
},
{
"method" : "PATCH",
"url" : "/services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document__c/@{NewSalesInvoice.id}",
"referenceId" : "PostedSalesInvoice",
"body" : {
"s2cor__Status__c": "Submitted"
}
}
]
}
In this JSON payload:
- GET /services/data/v44.0/sobjects/s2cor__Sage_ACC_Dimension__c/s2cor__UID__c/Customer/?fields=Id
Retrieves the ID of the Customer dimension and stores it in theCustomerDimension
variable. - GET /services/data/v44.0/sobjects/s2cor__Sage_COR_Company__c/a1G1N0000066tG6UAI?fields=Id
Retrieves the ID of the Company recorda1G1N0000066tG6UAI
and stores it in theCompany
variable. We’ll use this Company record to create a Customer tag and Product tag for the new invoice. - POST /services/data/v44.0/sobjects/Account
Creates a new Account record (Example new account 2) and stores its details in theNewAccount
variable. - POST /services/data/v44.0/sobjects/s2cor__Sage_ACC_Tag__c
Creates a new Dimension Tag record (Example customer tag 2) that combines the Customer dimension ID, Company record ID, and Account record ID. The Dimension Tag record defines the new customer. - GET /services/data/v44.0/sobjects/s2cor__Sage_ACC_Dimension__c/s2cor__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 (Example product 2) and stores its details in the NewProduct variable. - POST /services/data/v44.0/sobjects/s2cor__Sage_ACC_Tag__c/
Creates a new Dimension Tag record (Example product tag 2) that combines the Product dimension ID, Company record ID, and Product record ID. The Dimension Tag record defines the new product. - GET /services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document_Type__c/s2cor__UID__c/SalesInvoice_TD_US?fields=Id
Retrieves theSalesInvoice_TD_US
sales invoice type and stores it in theSalesInvoiceType
variable. - POST /services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document__c
Creates a new invoice for the account stored in theNewAccount
variable using the invoice type stored in theSalesInvoiceType
variable. The new invoice is stored in theNewSalesInvoice
variable. - POST /services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document_Item__c
Adds a new line item to the invoice stored in theNewSalesInvoice
variable. The line item is created for the product stored in theNewProduct
variable. - PATCH /services/data/v44.0/sobjects/s2cor__Sage_INV_Trade_Document_Item__c
Submits (posts) the invoice stored in theNewSalesInvoice
variable.
Step 5: Send your request
Send your request to retrieve the records.