Chilkat Online Tools

Node.js / Salesforce Platform APIs / Eligible Promotions

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

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

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

    // {
    //   "cart": {
    //     "cartDetails": [
    //       {
    //         "activityStartDate": "2023-06-14T12:45:19Z",
    //         "contactId": "003xx000004WjzAAAS",
    //         "transactionAmount": 499,
    //         "currencyISOCode": "INR",
    //         "cartLineDetails": [
    //           {
    //             "cartLineProductId": "01txx0000006iTsAAI",
    //             "cartLineItemQuantity": 3,
    //             "cartLineItemAmount": 499,
    //             "cartLineProductCatalogId": "0ZSSB0000002d8X4AQ"
    //           }
    //         ]
    //       }
    //     ]
    //   }
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("cart.cartDetails[0].activityStartDate","2023-06-14T12:45:19Z");
    json.UpdateString("cart.cartDetails[0].contactId","003xx000004WjzAAAS");
    json.UpdateInt("cart.cartDetails[0].transactionAmount",499);
    json.UpdateString("cart.cartDetails[0].currencyISOCode","INR");
    json.UpdateString("cart.cartDetails[0].cartLineDetails[0].cartLineProductId","01txx0000006iTsAAI");
    json.UpdateInt("cart.cartDetails[0].cartLineDetails[0].cartLineItemQuantity",3);
    json.UpdateInt("cart.cartDetails[0].cartLineDetails[0].cartLineItemAmount",499);
    json.UpdateString("cart.cartDetails[0].cartLineDetails[0].cartLineProductCatalogId","0ZSSB0000002d8X4AQ");

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

    // resp: HttpResponse
    var resp = http.PostJson3("https://domain.com/services/data/v{{version}}/global-promotions-management/eligible-promotions","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
   "cart":{
      "cartDetails":[
         {
            "activityStartDate":"2023-06-14T12:45:19Z",
            "contactId":"003xx000004WjzAAAS",
            "transactionAmount":499,
            "currencyISOCode":"INR",
            "cartLineDetails":[
               {
                  "cartLineProductId":"01txx0000006iTsAAI",
                  "cartLineItemQuantity":3,
                  "cartLineItemAmount":499,
                  "cartLineProductCatalogId":"0ZSSB0000002d8X4AQ"
               }
            ]
         }
      ]
   }
}'
https://domain.com/services/data/v{{version}}/global-promotions-management/eligible-promotions

Postman Collection Item JSON

{
  "name": "Eligible Promotions",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "//pm.variables.set('loyaltyProgramName','xyz');",
          "pm.variables.set('processName','TierProcessing');"
        ],
        "type": "text/javascript",
        "packages": {}
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n   \"cart\":{\n      \"cartDetails\":[\n         {\n            \"activityStartDate\":\"2023-06-14T12:45:19Z\",\n            \"contactId\":\"003xx000004WjzAAAS\",\n            \"transactionAmount\":499,\n            \"currencyISOCode\":\"INR\",\n            \"cartLineDetails\":[\n               {\n                  \"cartLineProductId\":\"01txx0000006iTsAAI\",\n                  \"cartLineItemQuantity\":3,\n                  \"cartLineItemAmount\":499,\n                  \"cartLineProductCatalogId\":\"0ZSSB0000002d8X4AQ\"\n               }\n            ]\n         }\n      ]\n   }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/global-promotions-management/eligible-promotions",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "global-promotions-management",
        "eligible-promotions"
      ],
      "query": [
        {
          "key": "journalTypeId",
          "value": "",
          "disabled": true
        }
      ]
    },
    "description": "[Eligible Promotions](https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_eligible_promotions.htm)\n\nNOTE:\n\nIn the Pre-request. Script Tab, make changes in the variables value accordingly with the real Process Name to invoke."
  },
  "response": [
    {
      "name": "example of the details of a customer’s cart whose eligible promotions are to be fetched",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{accessToken}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n   \"cart\":{\n      \"cartDetails\":[\n         {\n            \"activityStartDate\":\"2023-06-14T12:45:19Z\",\n            \"contactId\":\"003xx000004WjzAAAS\",\n            \"transactionAmount\":499,\n            \"currencyISOCode\":\"INR\",\n            \"cartLineDetails\":[\n               {\n                  \"cartLineProductId\":\"01txx0000006iTsAAI\",\n                  \"cartLineItemQuantity\":3,\n                  \"cartLineItemAmount\":499,\n                  \"cartLineProductCatalogId\":\"0ZSSB0000002d8X4AQ\"\n               }\n            ]\n         }\n      ]\n   }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://itab2c--devloyalty.sandbox.my.salesforce.com/services/data/v60.0/connect/loyalty/programs/Volare/program-processes/processName",
          "protocol": "https",
          "host": [
            "itab2c--devloyalty",
            "sandbox",
            "my",
            "salesforce",
            "com"
          ],
          "path": [
            "services",
            "data",
            "v60.0",
            "connect",
            "loyalty",
            "programs",
            "Volare",
            "program-processes",
            "processName"
          ],
          "query": [
            {
              "key": "journalTypeId",
              "value": null,
              "disabled": true
            }
          ]
        }
      },
      "_postman_previewlanguage": null,
      "header": null,
      "cookie": [
      ],
      "body": null
    },
    {
      "name": "example of the details of a loyalty program member’s cart whose eligible loyalty program promotions are to be fetched:",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{accessToken}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n   \"cart\":{\n      \"cartDetails\":[\n         {\n            \"activityStartDate\":\"2023-06-14T12:45:19Z\",\n            \"currencyISOCode\":\"INR\",\n            \"transactionAmount\":499,\n            \"membershipNumber\":\"Member-005\",\n            \"cartLineDetails\":[\n               {\n                  \"cartLineProductId\":\"01txx0000006iTsAAI\",\n                  \"cartLineItemQuantity\":2,\n                  \"cartLineItemAmount\":99,\n                  \"cartLineProductCatalogId\":\"0ZSSB0000002d8X4AQ\"\n               },\n               {\n                  \"cartLineProduct\":\"Coke\",\n                  \"cartLineItemQuantity\":10,\n                  \"cartLineItemAmount\":400,\n                  \"cartLineProductCatalog\":\"Beverages\"\n               }\n            ]\n         }\n      ]\n   }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/connect/loyalty/programs/:loyaltyProgramName/program-processes/:processName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "connect",
            "loyalty",
            "programs",
            ":loyaltyProgramName",
            "program-processes",
            ":processName"
          ],
          "query": [
            {
              "key": "journalTypeId",
              "value": null,
              "disabled": true
            }
          ],
          "variable": [
            {
              "key": "loyaltyProgramName"
            },
            {
              "key": "processName"
            }
          ]
        }
      },
      "_postman_previewlanguage": null,
      "header": null,
      "cookie": [
      ],
      "body": null
    }
  ]
}