Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / Request Product Information (No Bundles)

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.

// {
//   "productContexts": [
//     {
//       "product2Id": "{{ClassTrainingProduct}}",
//       "productSellingModelId": "{{OneTimePSM}}"
//     },
//     {
//       "product2Id": "{{VirtualRouterProduct}}"
//     }
//   ],
//   "fields": [
//     "id",
//     "name",
//     "IsActive",
//     "ProductCode"
//   ],
//   "retrievalType": "ExcludeChildComponents"
// }

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("productContexts[0].product2Id","{{ClassTrainingProduct}}")
loo_Json.UpdateString("productContexts[0].productSellingModelId","{{OneTimePSM}}")
loo_Json.UpdateString("productContexts[1].product2Id","{{VirtualRouterProduct}}")
loo_Json.UpdateString("fields[0]","id")
loo_Json.UpdateString("fields[1]","name")
loo_Json.UpdateString("fields[2]","IsActive")
loo_Json.UpdateString("fields[3]","ProductCode")
loo_Json.UpdateString("retrievalType","ExcludeChildComponents")

// 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/catalog-products/actions/get-products","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 '{
  "productContexts": [
    {
      "product2Id": "{{ClassTrainingProduct}}",
      "productSellingModelId": "{{OneTimePSM}}"
    },
    {
      "product2Id": "{{VirtualRouterProduct}}"  
    }
  ],
  "fields": [
    "id",
    "name",
    "IsActive",
    "ProductCode"
  ],
  "retrievalType": "ExcludeChildComponents"
}'
https://domain.com/services/data/v{{version}}/commerce/catalog-products/actions/get-products

Postman Collection Item JSON

{
  "name": "Request Product Information (No Bundles)",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"productContexts\": [\n    {\n      \"product2Id\": \"{{ClassTrainingProduct}}\",\n      \"productSellingModelId\": \"{{OneTimePSM}}\"\n    },\n    {\n      \"product2Id\": \"{{VirtualRouterProduct}}\"  \n    }\n  ],\n  \"fields\": [\n    \"id\",\n    \"name\",\n    \"IsActive\",\n    \"ProductCode\"\n  ],\n  \"retrievalType\": \"ExcludeChildComponents\"\n}"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/commerce/catalog-products/actions/get-products",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "commerce",
        "catalog-products",
        "actions",
        "get-products"
      ]
    },
    "description": "Request information for two products that aren't bundles. For the first product, request only the information about the specified product selling model. For the second product, request information about all related product selling models.\n\nSee [Request Product Information](https://desktop.postman.com/?desktopVersion=10.13.6&webVersion=10.13.7-ui-230522-1730&userId=10709048&teamId=0)."
  },
  "response": [
  ]
}