Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / Calculate Price (New Sale)

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "listPricebookId": "{{standardPricebook}}",
//   "pricingFlow": "GET_PRICE_USING_CONTEXT",
//   "graph": {
//     "graphId": "1",
//     "records": [
//       {
//         "referenceId": "ref_sales_txn",
//         "record": {
//           "attributes": {
//             "type": "SalesTransactionShape"
//           },
//           "CurrencyIsoCode": "USD"
//         }
//       },
//       {
//         "referenceId": "Item_1_Evergreen",
//         "record": {
//           "attributes": {
//             "type": "SalesTransactionItemShape"
//           },
//           "SalesTransactionShapeId": "@{ref_sales_txn.Id}",
//           "StartDate": "2023-01-01",
//           "ProductId": "{{SLA_BronzeProduct}}",
//           "ProductSellingModelId": "{{EvergreenMonthlyPSM}}",
//           "Quantity": 3.0,
//           "PricingTransactionType": "NewSale",
//           "CurrencyIsoCode": "USD"
//         }
//       },
//       {
//         "referenceId": "Item_2_Termed",
//         "record": {
//           "attributes": {
//             "type": "SalesTransactionItemShape"
//           },
//           "SalesTransactionShapeId": "@{ref_sales_txn.Id}",
//           "StartDate": "2023-01-01",
//           "EndDate": "2023-12-31",
//           "ProductId": "{{VirtualRouterProduct}}",
//           "ProductSellingModelId": "{{TermMonthlyPSM}}",
//           "Quantity": 100.0,
//           "PricingTransactionType": "NewSale",
//           "CurrencyIsoCode": "USD"
//         }
//       }
//     ]
//   }
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("listPricebookId","{{standardPricebook}}")
loo_Json.UpdateString("pricingFlow","GET_PRICE_USING_CONTEXT")
loo_Json.UpdateString("graph.graphId","1")
loo_Json.UpdateString("graph.records[0].referenceId","ref_sales_txn")
loo_Json.UpdateString("graph.records[0].record.attributes.type","SalesTransactionShape")
loo_Json.UpdateString("graph.records[0].record.CurrencyIsoCode","USD")
loo_Json.UpdateString("graph.records[1].referenceId","Item_1_Evergreen")
loo_Json.UpdateString("graph.records[1].record.attributes.type","SalesTransactionItemShape")
loo_Json.UpdateString("graph.records[1].record.SalesTransactionShapeId","@{ref_sales_txn.Id}")
loo_Json.UpdateString("graph.records[1].record.StartDate","2023-01-01")
loo_Json.UpdateString("graph.records[1].record.ProductId","{{SLA_BronzeProduct}}")
loo_Json.UpdateString("graph.records[1].record.ProductSellingModelId","{{EvergreenMonthlyPSM}}")
loo_Json.UpdateNumber("graph.records[1].record.Quantity","3.0")
loo_Json.UpdateString("graph.records[1].record.PricingTransactionType","NewSale")
loo_Json.UpdateString("graph.records[1].record.CurrencyIsoCode","USD")
loo_Json.UpdateString("graph.records[2].referenceId","Item_2_Termed")
loo_Json.UpdateString("graph.records[2].record.attributes.type","SalesTransactionItemShape")
loo_Json.UpdateString("graph.records[2].record.SalesTransactionShapeId","@{ref_sales_txn.Id}")
loo_Json.UpdateString("graph.records[2].record.StartDate","2023-01-01")
loo_Json.UpdateString("graph.records[2].record.EndDate","2023-12-31")
loo_Json.UpdateString("graph.records[2].record.ProductId","{{VirtualRouterProduct}}")
loo_Json.UpdateString("graph.records[2].record.ProductSellingModelId","{{TermMonthlyPSM}}")
loo_Json.UpdateNumber("graph.records[2].record.Quantity","100.0")
loo_Json.UpdateString("graph.records[2].record.PricingTransactionType","NewSale")
loo_Json.UpdateString("graph.records[2].record.CurrencyIsoCode","USD")

// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Content-Type","application/json")

loo_Resp = loo_Http.PostJson3("https://domain.com/services/data/v{{version}}/commerce/pricing/salestransaction/actions/calculate-price","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Json

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "listPricebookId": "{{standardPricebook}}",
    "pricingFlow": "GET_PRICE_USING_CONTEXT",
    "graph": {
        "graphId": "1",
        "records": [
            {
                "referenceId": "ref_sales_txn",
                "record": {
                    "attributes": {
                        "type": "SalesTransactionShape"
                    },
                    "CurrencyIsoCode": "USD"
                }
            },
            {
                "referenceId": "Item_1_Evergreen",
                "record": {
                    "attributes": {
                        "type": "SalesTransactionItemShape"
                    },
                    "SalesTransactionShapeId": "@{ref_sales_txn.Id}",
                    "StartDate": "2023-01-01",
                    "ProductId": "{{SLA_BronzeProduct}}",
                    "ProductSellingModelId": "{{EvergreenMonthlyPSM}}",
                    "Quantity": 3.0,
                    "PricingTransactionType": "NewSale",
                    "CurrencyIsoCode": "USD"
                }
            },
            {
                "referenceId": "Item_2_Termed",
                "record": {
                    "attributes": {
                        "type": "SalesTransactionItemShape"
                    },
                    "SalesTransactionShapeId": "@{ref_sales_txn.Id}",
                    "StartDate": "2023-01-01",
                    "EndDate": "2023-12-31",
                    "ProductId": "{{VirtualRouterProduct}}",
                    "ProductSellingModelId": "{{TermMonthlyPSM}}",
                    "Quantity": 100.0,
                    "PricingTransactionType": "NewSale",
                    "CurrencyIsoCode": "USD"
                }
            }
        ]
    }
}'
https://domain.com/services/data/v{{version}}/commerce/pricing/salestransaction/actions/calculate-price

Postman Collection Item JSON

{
  "name": "Calculate Price (New Sale)",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"listPricebookId\": \"{{standardPricebook}}\",\n    \"pricingFlow\": \"GET_PRICE_USING_CONTEXT\",\n    \"graph\": {\n        \"graphId\": \"1\",\n        \"records\": [\n            {\n                \"referenceId\": \"ref_sales_txn\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"SalesTransactionShape\"\n                    },\n                    \"CurrencyIsoCode\": \"USD\"\n                }\n            },\n            {\n                \"referenceId\": \"Item_1_Evergreen\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"SalesTransactionItemShape\"\n                    },\n                    \"SalesTransactionShapeId\": \"@{ref_sales_txn.Id}\",\n                    \"StartDate\": \"2023-01-01\",\n                    \"ProductId\": \"{{SLA_BronzeProduct}}\",\n                    \"ProductSellingModelId\": \"{{EvergreenMonthlyPSM}}\",\n                    \"Quantity\": 3.0,\n                    \"PricingTransactionType\": \"NewSale\",\n                    \"CurrencyIsoCode\": \"USD\"\n                }\n            },\n            {\n                \"referenceId\": \"Item_2_Termed\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"SalesTransactionItemShape\"\n                    },\n                    \"SalesTransactionShapeId\": \"@{ref_sales_txn.Id}\",\n                    \"StartDate\": \"2023-01-01\",\n                    \"EndDate\": \"2023-12-31\",\n                    \"ProductId\": \"{{VirtualRouterProduct}}\",\n                    \"ProductSellingModelId\": \"{{TermMonthlyPSM}}\",\n                    \"Quantity\": 100.0,\n                    \"PricingTransactionType\": \"NewSale\",\n                    \"CurrencyIsoCode\": \"USD\"\n                }\n            }\n        ]\n    }\n}"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/commerce/pricing/salestransaction/actions/calculate-price",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "commerce",
        "pricing",
        "salestransaction",
        "actions",
        "calculate-price"
      ]
    },
    "description": "Calculate the price of a new sale that contains two order items: a term-defined subscription order for a bronze-level SLA, and an evergreen subscription order for a virtual router. The payload for the term-defined order contains both a start date and an end date. Instead of an end date, you can also include a start date and a subscription term.\n\nSee [Calculate Price](https://developer.salesforce.com/docs/revenue/subscription-management/references/prices?meta=Summary)."
  },
  "response": [
  ]
}