Chilkat Online Tools

unicodeC / Salesforce Platform APIs / runExpressionSet

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonArrayW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonArrayW jarrResp;
    int respStatusCode;
    HCkJsonObjectW json;
    const wchar_t *actionName;
    const wchar_t *errors;
    BOOL isSuccess;
    int Output;
    int version;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

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

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

    // {
    //   "inputs": [
    //     {}
    //   ]
    // }

    json = CkJsonObjectW_Create();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jarrResp = CkJsonArrayW_Create();
    CkJsonArrayW_LoadSb(jarrResp,sbResponseBody);
    CkJsonArrayW_putEmitCompact(jarrResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonArrayW_emit(jarrResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonArrayW_Dispose(jarrResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // [
    //   {
    //     "actionName": "myExpressionSet",
    //     "errors": null,
    //     "isSuccess": true,
    //     "outputValues": {
    //       "output": 1
    //     },
    //     "version": 1
    //   }
    // ]

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    i = 0;
    count_i = CkJsonArrayW_getSize(jarrResp);
    while (i < count_i) {
        json = CkJsonArrayW_ObjectAt(jarrResp,i);
        actionName = CkJsonObjectW_stringOf(json,L"actionName");
        errors = CkJsonObjectW_stringOf(json,L"errors");
        isSuccess = CkJsonObjectW_BoolOf(json,L"isSuccess");
        Output = CkJsonObjectW_IntOf(json,L"outputValues.output");
        version = CkJsonObjectW_IntOf(json,L"version");
        CkJsonObjectW_Dispose(json);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonArrayW_Dispose(jarrResp);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "inputs": [
        {}
    ]
}'
https://domain.com/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName

Postman Collection Item JSON

{
  "name": "runExpressionSet",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"inputs\": [\n        {}\n    ]\n}"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "actions",
        "custom",
        "runExpressionSet",
        ":expressionSetAPIName"
      ],
      "variable": [
        {
          "key": "expressionSetAPIName",
          "value": "myExpressionSet",
          "description": "The API name of an expression set is unique within your Salesforce instance."
        }
      ]
    },
    "description": "# Expression Set Actions\n\nInvoke an active expression set. An expression set is a user-defined rule that accepts an input and returns the output based on the configured function.\n\nThe configured function of an expression set can be a simple decision matrix lookup, a calculation based on a mathematical formula, a condition, or another expression set.\n\nThese actions are available in API version 55.0 and later.\n\n## Supported REST HTTP Methods\n\nURI/services/data/v55.0/actions/custom/runExpressionSet/{ApiName}\n\n> `Note` \n  \n> `The API name of an expression set is unique within your Salesforce instance.` \n  \n\nFormats\n\nJSON\n\nHTTP Methods\n\nPOST\n\nAuthentication\n\nAuthorization: Bearer token\n\n## Inputs\n\nVary depending on the selected expression set.\n\n## Outputs\n\nVary depending on the inputs of the selected expression set.\n\n## Usage\n\nThis section has the sample request and response for invoking an expression set that does the following:\n\n1. Find the tax percentage and the premium corresponding to specific age and salary using a decision matrix lookup.\n    \n2. Check the age criterion to calculate the total tax.\n    \n3. Calculate the total tax to be paid based on the age group, salary, and the tax percentage.\n    \n\nSample request\n\nHere’s an example POST request that has the inputs, such as, age and salary:\n\n```\n{\n   \"inputs\":[\n      {\n         \"Age\":\"25.00\",\n         \"Salary\":\"50000.00\"\n      }\n   ]\n}\n\n ```\n\nSample response\n\nHere’s an example response that has the premium and tax values based on the inputs provided in the example request:\n\n```\n[\n   {\n      \"actionName\":\"TaxPremiumES\",\n      \"errors\":null,\n      \"isSuccess\":true,\n      \"outputValues\":{\n         \"TaxPremium__Premium\":1000,\n         \"TaxPremium__Tax\":10,\n         \"TaxToBePaid\":1050,\n         \"condition_output__2\":\"false\",\n         \"condition_output__1\":\"true\"\n      }\n   }\n]\n\n ```"
  },
  "response": [
    {
      "name": "Status400-EmptyExpressionSetAPIName",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"inputs\": [\n        {}\n    ]\n}"
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runExpressionSet",
            ":expressionSetAPIName"
          ],
          "variable": [
            {
              "key": "expressionSetAPIName",
              "value": "",
              "description": "The API name of an expression set is unique within your Salesforce instance."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 09:04:01 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=1/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"actionName\": \":expressionSetAPIName\",\n        \"errors\": [\n            {\n                \"statusCode\": \"MISSING_RECORD\",\n                \"message\": \"Action name not found: :expressionSetAPIName\",\n                \"fields\": []\n            }\n        ],\n        \"isSuccess\": false,\n        \"outputValues\": null,\n        \"version\": 1\n    }\n]"
    },
    {
      "name": "Status400-ExpressionNotFound",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"inputs\": [\n        {}\n    ]\n}"
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runExpressionSet",
            ":expressionSetAPIName"
          ],
          "variable": [
            {
              "key": "expressionSetAPIName",
              "value": "ghfgh",
              "description": "The API name of an expression set is unique within your Salesforce instance."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 09:05:16 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=1/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"actionName\": \"ghfgh\",\n        \"errors\": [\n            {\n                \"statusCode\": \"MISSING_RECORD\",\n                \"message\": \"Action name not found: ghfgh\",\n                \"fields\": []\n            }\n        ],\n        \"isSuccess\": false,\n        \"outputValues\": null,\n        \"version\": 1\n    }\n]"
    },
    {
      "name": "Status500-EmptyBody",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": ""
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runExpressionSet",
            ":expressionSetAPIName"
          ],
          "variable": [
            {
              "key": "expressionSetAPIName",
              "value": "myExpressionSet",
              "description": "The API name of an expression set is unique within your Salesforce instance."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 09:06:44 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=3/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"message\": \"The HTTP entity body is required, but this request has no entity body.\",\n        \"errorCode\": \"JSON_PARSER_ERROR\"\n    }\n]"
    },
    {
      "name": "Status400-InvalidBody",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n}"
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runExpressionSet",
            ":expressionSetAPIName"
          ],
          "variable": [
            {
              "key": "expressionSetAPIName",
              "value": "myExpressionSet",
              "description": "The API name of an expression set is unique within your Salesforce instance."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 09:07:21 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=4/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"errorCode\": \"BAD_REQUEST\",\n        \"message\": \"Invalid Request Body\"\n    }\n]"
    },
    {
      "name": "Status200-Successfull",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"inputs\": [\n        {}\n    ]\n}"
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runExpressionSet/:expressionSetAPIName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runExpressionSet",
            ":expressionSetAPIName"
          ],
          "variable": [
            {
              "key": "expressionSetAPIName",
              "value": "myExpressionSet",
              "description": "The API name of an expression set is unique within your Salesforce instance."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 09:08:00 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "Sforce-Limit-Info",
          "value": "api-usage=5/15000"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"actionName\": \"myExpressionSet\",\n        \"errors\": null,\n        \"isSuccess\": true,\n        \"outputValues\": {\n            \"output\": 1\n        },\n        \"version\": 1\n    }\n]"
    }
  ]
}