Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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/v57.0/sobjects/Order",
// "referenceId": "refOrder",
// "body": {
// "AccountId": "{{defaultAccount}}",
// "EffectiveDate": "2023-01-01",
// "Pricebook2Id": "{{standardPricebook}}",
// "BillToContactId": "{{defaultBillToContact}}",
// "Status": "Draft"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/AppUsageAssignment",
// "referenceId": "refAppTag",
// "body": {
// "AppUsageType": "SubscriptionManagement",
// "RecordId": "@{refOrder.id}"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderAction",
// "referenceId": "refOrderAction",
// "body": {
// "OrderId": "@{refOrder.id}",
// "Type": "New Sale"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderItem",
// "referenceId": "refWorkAnywhereBundle",
// "body": {
// "OrderId": "@{refOrder.id}",
// "OrderActionId": "@{refOrderAction.id}",
// "PricebookEntryId": "{{WorkAnywhereBundlePBE}}",
// "ServiceDate": "2023-01-01",
// "Quantity": 1,
// "UnitPrice": 10000,
// "NetUnitPrice": 10000,
// "TotalLineAmount": 10000,
// "PeriodBoundary": "AlignToCalendar",
// "BillingFrequency2": "Monthly"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderItem",
// "referenceId": "refVirtualRouter",
// "body": {
// "OrderId": "@{refOrder.id}",
// "OrderActionId": "@{refOrderAction.id}",
// "PricebookEntryId": "{{VirtualRouterEvergrnPBE}}",
// "ServiceDate": "2023-01-01",
// "Quantity": 100,
// "UnitPrice": 0,
// "NetUnitPrice": 0,
// "TotalLineAmount": 0,
// "PeriodBoundary": "AlignToCalendar",
// "BillingFrequency2": "Monthly"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderItem",
// "referenceId": "refBronzeSLA",
// "body": {
// "OrderId": "@{refOrder.id}",
// "OrderActionId": "@{refOrderAction.id}",
// "PricebookEntryId": "{{SLABronzeEvergrnMonthPBE}}",
// "ServiceDate": "2023-01-01",
// "Quantity": 3,
// "UnitPrice": 0,
// "NetUnitPrice": 0,
// "TotalLineAmount": 0,
// "PeriodBoundary": "AlignToCalendar",
// "BillingFrequency2": "Monthly"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderItemRelationship",
// "referenceId": "refOrderItemRelationship1",
// "body": {
// "ProductRelationshipTypeId": "{{BundleProductRelationshipType}}",
// "MainOrderItemId": "@{refWorkAnywhereBundle.id}",
// "AssociatedOrderItemId": "@{refVirtualRouter.id}",
// "AssociatedOrderItemPricing": "IncludedInBundlePrice",
// "AssociatedQuantScaleMethod": "Proportional"
// }
// },
// {
// "method": "POST",
// "url": "/services/data/v57.0/sobjects/OrderItemRelationship",
// "referenceId": "refOrderItemRelationship2",
// "body": {
// "ProductRelationshipTypeId": "{{BundleProductRelationshipType}}",
// "MainOrderItemId": "@{refWorkAnywhereBundle.id}",
// "AssociatedOrderItemId": "@{refBronzeSLA.id}",
// "AssociatedOrderItemPricing": "IncludedInBundlePrice",
// "AssociatedQuantScaleMethod": "Constant"
// }
// }
// ]
// }
let json = CkoJsonObject()!
json.updateBool("allOrNone", value: true)
json.update("compositeRequest[0].method", value: "POST")
json.update("compositeRequest[0].url", value: "/services/data/v57.0/sobjects/Order")
json.update("compositeRequest[0].referenceId", value: "refOrder")
json.update("compositeRequest[0].body.AccountId", value: "{{defaultAccount}}")
json.update("compositeRequest[0].body.EffectiveDate", value: "2023-01-01")
json.update("compositeRequest[0].body.Pricebook2Id", value: "{{standardPricebook}}")
json.update("compositeRequest[0].body.BillToContactId", value: "{{defaultBillToContact}}")
json.update("compositeRequest[0].body.Status", value: "Draft")
json.update("compositeRequest[1].method", value: "POST")
json.update("compositeRequest[1].url", value: "/services/data/v57.0/sobjects/AppUsageAssignment")
json.update("compositeRequest[1].referenceId", value: "refAppTag")
json.update("compositeRequest[1].body.AppUsageType", value: "SubscriptionManagement")
json.update("compositeRequest[1].body.RecordId", value: "@{refOrder.id}")
json.update("compositeRequest[2].method", value: "POST")
json.update("compositeRequest[2].url", value: "/services/data/v57.0/sobjects/OrderAction")
json.update("compositeRequest[2].referenceId", value: "refOrderAction")
json.update("compositeRequest[2].body.OrderId", value: "@{refOrder.id}")
json.update("compositeRequest[2].body.Type", value: "New Sale")
json.update("compositeRequest[3].method", value: "POST")
json.update("compositeRequest[3].url", value: "/services/data/v57.0/sobjects/OrderItem")
json.update("compositeRequest[3].referenceId", value: "refWorkAnywhereBundle")
json.update("compositeRequest[3].body.OrderId", value: "@{refOrder.id}")
json.update("compositeRequest[3].body.OrderActionId", value: "@{refOrderAction.id}")
json.update("compositeRequest[3].body.PricebookEntryId", value: "{{WorkAnywhereBundlePBE}}")
json.update("compositeRequest[3].body.ServiceDate", value: "2023-01-01")
json.updateInt("compositeRequest[3].body.Quantity", value: 1)
json.updateInt("compositeRequest[3].body.UnitPrice", value: 10000)
json.updateInt("compositeRequest[3].body.NetUnitPrice", value: 10000)
json.updateInt("compositeRequest[3].body.TotalLineAmount", value: 10000)
json.update("compositeRequest[3].body.PeriodBoundary", value: "AlignToCalendar")
json.update("compositeRequest[3].body.BillingFrequency2", value: "Monthly")
json.update("compositeRequest[4].method", value: "POST")
json.update("compositeRequest[4].url", value: "/services/data/v57.0/sobjects/OrderItem")
json.update("compositeRequest[4].referenceId", value: "refVirtualRouter")
json.update("compositeRequest[4].body.OrderId", value: "@{refOrder.id}")
json.update("compositeRequest[4].body.OrderActionId", value: "@{refOrderAction.id}")
json.update("compositeRequest[4].body.PricebookEntryId", value: "{{VirtualRouterEvergrnPBE}}")
json.update("compositeRequest[4].body.ServiceDate", value: "2023-01-01")
json.updateInt("compositeRequest[4].body.Quantity", value: 100)
json.updateInt("compositeRequest[4].body.UnitPrice", value: 0)
json.updateInt("compositeRequest[4].body.NetUnitPrice", value: 0)
json.updateInt("compositeRequest[4].body.TotalLineAmount", value: 0)
json.update("compositeRequest[4].body.PeriodBoundary", value: "AlignToCalendar")
json.update("compositeRequest[4].body.BillingFrequency2", value: "Monthly")
json.update("compositeRequest[5].method", value: "POST")
json.update("compositeRequest[5].url", value: "/services/data/v57.0/sobjects/OrderItem")
json.update("compositeRequest[5].referenceId", value: "refBronzeSLA")
json.update("compositeRequest[5].body.OrderId", value: "@{refOrder.id}")
json.update("compositeRequest[5].body.OrderActionId", value: "@{refOrderAction.id}")
json.update("compositeRequest[5].body.PricebookEntryId", value: "{{SLABronzeEvergrnMonthPBE}}")
json.update("compositeRequest[5].body.ServiceDate", value: "2023-01-01")
json.updateInt("compositeRequest[5].body.Quantity", value: 3)
json.updateInt("compositeRequest[5].body.UnitPrice", value: 0)
json.updateInt("compositeRequest[5].body.NetUnitPrice", value: 0)
json.updateInt("compositeRequest[5].body.TotalLineAmount", value: 0)
json.update("compositeRequest[5].body.PeriodBoundary", value: "AlignToCalendar")
json.update("compositeRequest[5].body.BillingFrequency2", value: "Monthly")
json.update("compositeRequest[6].method", value: "POST")
json.update("compositeRequest[6].url", value: "/services/data/v57.0/sobjects/OrderItemRelationship")
json.update("compositeRequest[6].referenceId", value: "refOrderItemRelationship1")
json.update("compositeRequest[6].body.ProductRelationshipTypeId", value: "{{BundleProductRelationshipType}}")
json.update("compositeRequest[6].body.MainOrderItemId", value: "@{refWorkAnywhereBundle.id}")
json.update("compositeRequest[6].body.AssociatedOrderItemId", value: "@{refVirtualRouter.id}")
json.update("compositeRequest[6].body.AssociatedOrderItemPricing", value: "IncludedInBundlePrice")
json.update("compositeRequest[6].body.AssociatedQuantScaleMethod", value: "Proportional")
json.update("compositeRequest[7].method", value: "POST")
json.update("compositeRequest[7].url", value: "/services/data/v57.0/sobjects/OrderItemRelationship")
json.update("compositeRequest[7].referenceId", value: "refOrderItemRelationship2")
json.update("compositeRequest[7].body.ProductRelationshipTypeId", value: "{{BundleProductRelationshipType}}")
json.update("compositeRequest[7].body.MainOrderItemId", value: "@{refWorkAnywhereBundle.id}")
json.update("compositeRequest[7].body.AssociatedOrderItemId", value: "@{refBronzeSLA.id}")
json.update("compositeRequest[7].body.AssociatedOrderItemPricing", value: "IncludedInBundlePrice")
json.update("compositeRequest[7].body.AssociatedQuantScaleMethod", value: "Constant")
// Adds the "Authorization: Bearer <access_token>" header.
http.authToken = "<access_token>"
var resp: CkoHttpResponse? = http.postJson3("https://domain.com/services/data/v{{version}}/composite", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"allOrNone": true,
"compositeRequest": [
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/Order",
"referenceId": "refOrder",
"body": {
"AccountId": "{{defaultAccount}}",
"EffectiveDate": "2023-01-01",
"Pricebook2Id": "{{standardPricebook}}",
"BillToContactId": "{{defaultBillToContact}}",
"Status": "Draft"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/AppUsageAssignment",
"referenceId": "refAppTag",
"body": {
"AppUsageType": "SubscriptionManagement",
"RecordId": "@{refOrder.id}"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderAction",
"referenceId": "refOrderAction",
"body": {
"OrderId": "@{refOrder.id}",
"Type": "New Sale"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderItem",
"referenceId": "refWorkAnywhereBundle",
"body": {
"OrderId": "@{refOrder.id}",
"OrderActionId": "@{refOrderAction.id}",
"PricebookEntryId": "{{WorkAnywhereBundlePBE}}",
"ServiceDate": "2023-01-01",
"Quantity": 1,
"UnitPrice": 10000,
"NetUnitPrice": 10000,
"TotalLineAmount": 10000,
"PeriodBoundary": "AlignToCalendar",
"BillingFrequency2": "Monthly"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderItem",
"referenceId": "refVirtualRouter",
"body": {
"OrderId": "@{refOrder.id}",
"OrderActionId": "@{refOrderAction.id}",
"PricebookEntryId": "{{VirtualRouterEvergrnPBE}}",
"ServiceDate": "2023-01-01",
"Quantity": 100,
"UnitPrice": 0,
"NetUnitPrice": 0,
"TotalLineAmount": 0,
"PeriodBoundary": "AlignToCalendar",
"BillingFrequency2": "Monthly"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderItem",
"referenceId": "refBronzeSLA",
"body": {
"OrderId": "@{refOrder.id}",
"OrderActionId": "@{refOrderAction.id}",
"PricebookEntryId": "{{SLABronzeEvergrnMonthPBE}}",
"ServiceDate": "2023-01-01",
"Quantity": 3,
"UnitPrice": 0,
"NetUnitPrice": 0,
"TotalLineAmount": 0,
"PeriodBoundary": "AlignToCalendar",
"BillingFrequency2": "Monthly"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderItemRelationship",
"referenceId": "refOrderItemRelationship1",
"body": {
"ProductRelationshipTypeId": "{{BundleProductRelationshipType}}",
"MainOrderItemId": "@{refWorkAnywhereBundle.id}",
"AssociatedOrderItemId": "@{refVirtualRouter.id}",
"AssociatedOrderItemPricing": "IncludedInBundlePrice",
"AssociatedQuantScaleMethod": "Proportional"
}
},
{
"method": "POST",
"url": "/services/data/v57.0/sobjects/OrderItemRelationship",
"referenceId": "refOrderItemRelationship2",
"body": {
"ProductRelationshipTypeId": "{{BundleProductRelationshipType}}",
"MainOrderItemId": "@{refWorkAnywhereBundle.id}",
"AssociatedOrderItemId": "@{refBronzeSLA.id}",
"AssociatedOrderItemPricing": "IncludedInBundlePrice",
"AssociatedQuantScaleMethod": "Constant"
}
}
]
}'
https://domain.com/services/data/v{{version}}/composite
Postman Collection Item JSON
{
"name": "Create Order With Bundle",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"allOrNone\": true,\n \"compositeRequest\": [\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/Order\",\n \"referenceId\": \"refOrder\",\n \"body\": {\n \"AccountId\": \"{{defaultAccount}}\",\n \"EffectiveDate\": \"2023-01-01\",\n \"Pricebook2Id\": \"{{standardPricebook}}\",\n \"BillToContactId\": \"{{defaultBillToContact}}\",\n \"Status\": \"Draft\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/AppUsageAssignment\",\n \"referenceId\": \"refAppTag\",\n \"body\": {\n \"AppUsageType\": \"SubscriptionManagement\",\n \"RecordId\": \"@{refOrder.id}\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/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/v57.0/sobjects/OrderItem\",\n \"referenceId\": \"refWorkAnywhereBundle\",\n \"body\": {\n \"OrderId\": \"@{refOrder.id}\",\n \"OrderActionId\": \"@{refOrderAction.id}\",\n \"PricebookEntryId\": \"{{WorkAnywhereBundlePBE}}\",\n \"ServiceDate\": \"2023-01-01\",\n \"Quantity\": 1,\n \"UnitPrice\": 10000,\n \"NetUnitPrice\": 10000,\n \"TotalLineAmount\": 10000,\n \"PeriodBoundary\": \"AlignToCalendar\",\n \"BillingFrequency2\": \"Monthly\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/OrderItem\",\n \"referenceId\": \"refVirtualRouter\",\n \"body\": {\n \"OrderId\": \"@{refOrder.id}\",\n \"OrderActionId\": \"@{refOrderAction.id}\",\n \"PricebookEntryId\": \"{{VirtualRouterEvergrnPBE}}\",\n \"ServiceDate\": \"2023-01-01\",\n \"Quantity\": 100,\n \"UnitPrice\": 0,\n \"NetUnitPrice\": 0,\n \"TotalLineAmount\": 0,\n \"PeriodBoundary\": \"AlignToCalendar\",\n \"BillingFrequency2\": \"Monthly\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/OrderItem\",\n \"referenceId\": \"refBronzeSLA\",\n \"body\": {\n \"OrderId\": \"@{refOrder.id}\",\n \"OrderActionId\": \"@{refOrderAction.id}\",\n \"PricebookEntryId\": \"{{SLABronzeEvergrnMonthPBE}}\",\n \"ServiceDate\": \"2023-01-01\",\n \"Quantity\": 3,\n \"UnitPrice\": 0,\n \"NetUnitPrice\": 0,\n \"TotalLineAmount\": 0,\n \"PeriodBoundary\": \"AlignToCalendar\",\n \"BillingFrequency2\": \"Monthly\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/OrderItemRelationship\",\n \"referenceId\": \"refOrderItemRelationship1\",\n \"body\": {\n \"ProductRelationshipTypeId\": \"{{BundleProductRelationshipType}}\",\n \"MainOrderItemId\": \"@{refWorkAnywhereBundle.id}\",\n \"AssociatedOrderItemId\": \"@{refVirtualRouter.id}\",\n \"AssociatedOrderItemPricing\": \"IncludedInBundlePrice\",\n \"AssociatedQuantScaleMethod\": \"Proportional\"\n }\n },\n {\n \"method\": \"POST\",\n \"url\": \"/services/data/v57.0/sobjects/OrderItemRelationship\",\n \"referenceId\": \"refOrderItemRelationship2\",\n \"body\": {\n \"ProductRelationshipTypeId\": \"{{BundleProductRelationshipType}}\",\n \"MainOrderItemId\": \"@{refWorkAnywhereBundle.id}\",\n \"AssociatedOrderItemId\": \"@{refBronzeSLA.id}\",\n \"AssociatedOrderItemPricing\": \"IncludedInBundlePrice\",\n \"AssociatedQuantScaleMethod\": \"Constant\"\n }\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 for a product bundle."
},
"response": [
]
}