Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / Create Order (Evergreen & Termed)

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.

// {
//   "allOrNone": true,
//   "compositeRequest": [
//     {
//       "method": "POST",
//       "url": "/services/data/v{{version}}/sobjects/Order",
//       "referenceId": "refOrder",
//       "body": {
//         "AccountId": "{{defaultAccount}}",
//         "EffectiveDate": "2022-01-01",
//         "Pricebook2Id": "{{standardPricebook}}",
//         "BillToContactId": "{{defaultBillToContact}}",
//         "Status": "Draft"
//       }
//     },
//     {
//       "method": "POST",
//       "url": "/services/data/v{{version}}/sobjects/AppUsageAssignment",
//       "referenceId": "refAppTag",
//       "body": {
//         "AppUsageType": "SubscriptionManagement",
//         "RecordId": "@{refOrder.id}"
//       }
//     },
//     {
//       "method": "POST",
//       "url": "/services/data/v{{version}}/sobjects/OrderAction",
//       "referenceId": "refOrderAction",
//       "body": {
//         "OrderId": "@{refOrder.id}",
//         "Type": "New Sale"
//       }
//     },
//     {
//       "method": "POST",
//       "url": "/services/data/v{{version}}/sobjects/OrderItem",
//       "referenceId": "Item_1_Evergreen",
//       "body": {
//         "OrderId": "@{refOrder.id}",
//         "OrderActionId": "@{refOrderAction.id}",
//         "PricebookEntryId": "{{VirtualRouterEvergrnPBE}}",
//         "Quantity": 2.0,
//         "UnitPrice": 25.0,
//         "NetUnitPrice": 25.0,
//         "TotalLineAmount": 50.0,
//         "PeriodBoundary": "Anniversary",
//         "BillingFrequency2": "Monthly",
//         "ServiceDate": "2022-02-01",
//         "TaxTreatmentId": "{{defaultTaxTreatment}}"
//       }
//     },
//     {
//       "method": "POST",
//       "url": "/services/data/v{{version}}/sobjects/OrderItem",
//       "referenceId": "Item_2_termed",
//       "body": {
//         "OrderId": "@{refOrder.id}",
//         "OrderActionId": "@{refOrderAction.id}",
//         "PricebookEntryId": "{{VirtualRouterTermedPBE}}",
//         "Quantity": 10.0,
//         "UnitPrice": 50.0,
//         "NetUnitPrice": 50.0,
//         "TotalLineAmount": 500.0,
//         "PeriodBoundary": "Anniversary",
//         "BillingFrequency2": "Monthly",
//         "PricingTermCount": 12.0,
//         "ServiceDate": "2022-02-01",
//         "EndDate": "2023-01-01",
//         "TaxTreatmentId": "{{defaultTaxTreatment}}"
//       }
//     }
//   ]
// }

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.UpdateBool("allOrNone",1)
loo_Json.UpdateString("compositeRequest[0].method","POST")
loo_Json.UpdateString("compositeRequest[0].url","/services/data/v{{version}}/sobjects/Order")
loo_Json.UpdateString("compositeRequest[0].referenceId","refOrder")
loo_Json.UpdateString("compositeRequest[0].body.AccountId","{{defaultAccount}}")
loo_Json.UpdateString("compositeRequest[0].body.EffectiveDate","2022-01-01")
loo_Json.UpdateString("compositeRequest[0].body.Pricebook2Id","{{standardPricebook}}")
loo_Json.UpdateString("compositeRequest[0].body.BillToContactId","{{defaultBillToContact}}")
loo_Json.UpdateString("compositeRequest[0].body.Status","Draft")
loo_Json.UpdateString("compositeRequest[1].method","POST")
loo_Json.UpdateString("compositeRequest[1].url","/services/data/v{{version}}/sobjects/AppUsageAssignment")
loo_Json.UpdateString("compositeRequest[1].referenceId","refAppTag")
loo_Json.UpdateString("compositeRequest[1].body.AppUsageType","SubscriptionManagement")
loo_Json.UpdateString("compositeRequest[1].body.RecordId","@{refOrder.id}")
loo_Json.UpdateString("compositeRequest[2].method","POST")
loo_Json.UpdateString("compositeRequest[2].url","/services/data/v{{version}}/sobjects/OrderAction")
loo_Json.UpdateString("compositeRequest[2].referenceId","refOrderAction")
loo_Json.UpdateString("compositeRequest[2].body.OrderId","@{refOrder.id}")
loo_Json.UpdateString("compositeRequest[2].body.Type","New Sale")
loo_Json.UpdateString("compositeRequest[3].method","POST")
loo_Json.UpdateString("compositeRequest[3].url","/services/data/v{{version}}/sobjects/OrderItem")
loo_Json.UpdateString("compositeRequest[3].referenceId","Item_1_Evergreen")
loo_Json.UpdateString("compositeRequest[3].body.OrderId","@{refOrder.id}")
loo_Json.UpdateString("compositeRequest[3].body.OrderActionId","@{refOrderAction.id}")
loo_Json.UpdateString("compositeRequest[3].body.PricebookEntryId","{{VirtualRouterEvergrnPBE}}")
loo_Json.UpdateNumber("compositeRequest[3].body.Quantity","2.0")
loo_Json.UpdateNumber("compositeRequest[3].body.UnitPrice","25.0")
loo_Json.UpdateNumber("compositeRequest[3].body.NetUnitPrice","25.0")
loo_Json.UpdateNumber("compositeRequest[3].body.TotalLineAmount","50.0")
loo_Json.UpdateString("compositeRequest[3].body.PeriodBoundary","Anniversary")
loo_Json.UpdateString("compositeRequest[3].body.BillingFrequency2","Monthly")
loo_Json.UpdateString("compositeRequest[3].body.ServiceDate","2022-02-01")
loo_Json.UpdateString("compositeRequest[3].body.TaxTreatmentId","{{defaultTaxTreatment}}")
loo_Json.UpdateString("compositeRequest[4].method","POST")
loo_Json.UpdateString("compositeRequest[4].url","/services/data/v{{version}}/sobjects/OrderItem")
loo_Json.UpdateString("compositeRequest[4].referenceId","Item_2_termed")
loo_Json.UpdateString("compositeRequest[4].body.OrderId","@{refOrder.id}")
loo_Json.UpdateString("compositeRequest[4].body.OrderActionId","@{refOrderAction.id}")
loo_Json.UpdateString("compositeRequest[4].body.PricebookEntryId","{{VirtualRouterTermedPBE}}")
loo_Json.UpdateNumber("compositeRequest[4].body.Quantity","10.0")
loo_Json.UpdateNumber("compositeRequest[4].body.UnitPrice","50.0")
loo_Json.UpdateNumber("compositeRequest[4].body.NetUnitPrice","50.0")
loo_Json.UpdateNumber("compositeRequest[4].body.TotalLineAmount","500.0")
loo_Json.UpdateString("compositeRequest[4].body.PeriodBoundary","Anniversary")
loo_Json.UpdateString("compositeRequest[4].body.BillingFrequency2","Monthly")
loo_Json.UpdateNumber("compositeRequest[4].body.PricingTermCount","12.0")
loo_Json.UpdateString("compositeRequest[4].body.ServiceDate","2022-02-01")
loo_Json.UpdateString("compositeRequest[4].body.EndDate","2023-01-01")
loo_Json.UpdateString("compositeRequest[4].body.TaxTreatmentId","{{defaultTaxTreatment}}")

// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"

loo_Resp = loo_Http.PostJson3("https://domain.com/services/data/v{{version}}/composite","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>"
	-d '{
    "allOrNone": true,
    "compositeRequest": [
        {
            "method": "POST",
            "url": "/services/data/v{{version}}/sobjects/Order",
            "referenceId": "refOrder",
            "body": {
                "AccountId": "{{defaultAccount}}",
                "EffectiveDate": "2022-01-01",
                "Pricebook2Id": "{{standardPricebook}}",
                "BillToContactId": "{{defaultBillToContact}}",
                "Status": "Draft"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v{{version}}/sobjects/AppUsageAssignment",
            "referenceId": "refAppTag",
            "body": {
                "AppUsageType": "SubscriptionManagement",
                "RecordId": "@{refOrder.id}"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v{{version}}/sobjects/OrderAction",
            "referenceId": "refOrderAction",
            "body": {
                "OrderId": "@{refOrder.id}",
                "Type": "New Sale"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v{{version}}/sobjects/OrderItem",
            "referenceId": "Item_1_Evergreen",
            "body": {
                "OrderId": "@{refOrder.id}",
                "OrderActionId": "@{refOrderAction.id}",
                "PricebookEntryId": "{{VirtualRouterEvergrnPBE}}",
                "Quantity": 2.0,
                "UnitPrice": 25.0,
                "NetUnitPrice": 25.0,
                "TotalLineAmount": 50.0,
                "PeriodBoundary": "Anniversary",
                "BillingFrequency2": "Monthly",                
                "ServiceDate": "2022-02-01",
                "TaxTreatmentId": "{{defaultTaxTreatment}}"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v{{version}}/sobjects/OrderItem",
            "referenceId": "Item_2_termed",
            "body": {
                "OrderId": "@{refOrder.id}",
                "OrderActionId": "@{refOrderAction.id}",
                "PricebookEntryId": "{{VirtualRouterTermedPBE}}",
                "Quantity": 10.0,
                "UnitPrice": 50.0,
                "NetUnitPrice": 50.0,
                "TotalLineAmount": 500.0,
                "PeriodBoundary": "Anniversary",
                "BillingFrequency2": "Monthly",
                "PricingTermCount": 12.0,                
                "ServiceDate": "2022-02-01",
                "EndDate": "2023-01-01",
                "TaxTreatmentId": "{{defaultTaxTreatment}}"
            }
        }        
    ]
}'
https://domain.com/services/data/v{{version}}/composite

Postman Collection Item JSON

{
  "name": "Create Order (Evergreen & Termed)",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"allOrNone\": true,\n    \"compositeRequest\": [\n        {\n            \"method\": \"POST\",\n            \"url\": \"/services/data/v{{version}}/sobjects/Order\",\n            \"referenceId\": \"refOrder\",\n            \"body\": {\n                \"AccountId\": \"{{defaultAccount}}\",\n                \"EffectiveDate\": \"2022-01-01\",\n                \"Pricebook2Id\": \"{{standardPricebook}}\",\n                \"BillToContactId\": \"{{defaultBillToContact}}\",\n                \"Status\": \"Draft\"\n            }\n        },\n        {\n            \"method\": \"POST\",\n            \"url\": \"/services/data/v{{version}}/sobjects/AppUsageAssignment\",\n            \"referenceId\": \"refAppTag\",\n            \"body\": {\n                \"AppUsageType\": \"SubscriptionManagement\",\n                \"RecordId\": \"@{refOrder.id}\"\n            }\n        },\n        {\n            \"method\": \"POST\",\n            \"url\": \"/services/data/v{{version}}/sobjects/OrderAction\",\n            \"referenceId\": \"refOrderAction\",\n            \"body\": {\n                \"OrderId\": \"@{refOrder.id}\",\n                \"Type\": \"New Sale\"\n            }\n        },\n        {\n            \"method\": \"POST\",\n            \"url\": \"/services/data/v{{version}}/sobjects/OrderItem\",\n            \"referenceId\": \"Item_1_Evergreen\",\n            \"body\": {\n                \"OrderId\": \"@{refOrder.id}\",\n                \"OrderActionId\": \"@{refOrderAction.id}\",\n                \"PricebookEntryId\": \"{{VirtualRouterEvergrnPBE}}\",\n                \"Quantity\": 2.0,\n                \"UnitPrice\": 25.0,\n                \"NetUnitPrice\": 25.0,\n                \"TotalLineAmount\": 50.0,\n                \"PeriodBoundary\": \"Anniversary\",\n                \"BillingFrequency2\": \"Monthly\",                \n                \"ServiceDate\": \"2022-02-01\",\n                \"TaxTreatmentId\": \"{{defaultTaxTreatment}}\"\n            }\n        },\n        {\n            \"method\": \"POST\",\n            \"url\": \"/services/data/v{{version}}/sobjects/OrderItem\",\n            \"referenceId\": \"Item_2_termed\",\n            \"body\": {\n                \"OrderId\": \"@{refOrder.id}\",\n                \"OrderActionId\": \"@{refOrderAction.id}\",\n                \"PricebookEntryId\": \"{{VirtualRouterTermedPBE}}\",\n                \"Quantity\": 10.0,\n                \"UnitPrice\": 50.0,\n                \"NetUnitPrice\": 50.0,\n                \"TotalLineAmount\": 500.0,\n                \"PeriodBoundary\": \"Anniversary\",\n                \"BillingFrequency2\": \"Monthly\",\n                \"PricingTermCount\": 12.0,                \n                \"ServiceDate\": \"2022-02-01\",\n                \"EndDate\": \"2023-01-01\",\n                \"TaxTreatmentId\": \"{{defaultTaxTreatment}}\"\n            }\n        }        \n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/composite",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "composite"
      ]
    },
    "description": "Creates a Subscription Management order with two order items. One order item is sold on a monthly termed subscription, and the other order item is sold as an evergreen subscription."
  },
  "response": [
  ]
}