Chilkat Online Tools

ERROR!

------------------- GenerateCode ----------------------
ImpliedContentType: application/json
explicitContentType: application/json
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.

new Http http;
ckbool success;

// Use this online tool to generate code from sample JSON: {{.https://tools.chilkat.io/jsonCreate|||Generate Code to Create JSON.}}

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

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

new JsonObject json;
ignore = json.UpdateString("inputs[0].myColumnInput","One");

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>";
call http.SetRequestHeader("Content-Type","application/json");

HttpResponse resp = http.PostJson3("https://domain.com/services/data/v{{version}}/actions/custom/runDecisionMatrix/:UniqueName","application/json",json);
if (http.LastMethodSuccess == ckfalse) {
    println http.LastErrorText;
    return;
}

new StringBuilder sbResponseBody;
ignore = resp.GetBodySb(sbResponseBody);

new JsonArray jarrResp;
call jarrResp.LoadSb(sbResponseBody);
jarrResp.EmitCompact = ckfalse;

println "Response Body:";
println jarrResp.Emit();

int respStatusCode = resp.StatusCode;
println "Response Status Code = ",respStatusCode;
if (respStatusCode >= 400) {
    println "Response Header:";
    println resp.Header;
    println "Failed.";
    delete resp;
    return;
}
delete resp;

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

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

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: {{.https://tools.chilkat.io/jsonParse|||Generate JSON Parsing Code.}}

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

JsonObject json;
string actionName;
string errors;
ckbool isSuccess;
string MyColumnOutput;
int version;

int i = 0;
int count_i = jarrResp.Size;
while i < count_i {
    json = jarrResp.ObjectAt(i);
    actionName = json.StringOf("actionName");
    errors = json.StringOf("errors");
    isSuccess = json.BoolOf("isSuccess");
    MyColumnOutput = json.StringOf("outputValues.myColumnOutput");
    version = json.IntOf("version");
    delete json;
    i = i + 1;
}



---- end chilkat script ----

delphiDll / Salesforce Platform APIs / runDecisionMatrix

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jarrResp: HCkJsonArray;
respStatusCode: Integer;
json: HCkJsonObject;
actionName: PWideChar;
errors: PWideChar;
isSuccess: Boolean;
MyColumnOutput: PWideChar;
version: Integer;
i: Integer;
count_i: Integer;

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

http := CkHttp_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": [
//     {
//       "myColumnInput": "One"
//     }
//   ]
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'inputs[0].myColumnInput','One');

// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');

resp := CkHttp_PostJson3(http,'https://domain.com/services/data/v{{version}}/actions/custom/runDecisionMatrix/:UniqueName','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jarrResp := CkJsonArray_Create();
CkJsonArray_LoadSb(jarrResp,sbResponseBody);
CkJsonArray_putEmitCompact(jarrResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonArray__emit(jarrResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

// [
//   {
//     "actionName": "myDecisionMatrix",
//     "errors": null,
//     "isSuccess": true,
//     "outputValues": {
//       "myColumnOutput": "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

ERROR: Var already declared: json

i := 0;
count_i := CkJsonArray_getSize(jarrResp);
while i < count_i do
  begin
    json := CkJsonArray_ObjectAt(jarrResp,i);
    actionName := CkJsonObject__stringOf(json,'actionName');
    errors := CkJsonObject__stringOf(json,'errors');
    isSuccess := CkJsonObject_BoolOf(json,'isSuccess');
    MyColumnOutput := CkJsonObject__stringOf(json,'outputValues.myColumnOutput');
    version := CkJsonObject_IntOf(json,'version');
    CkJsonObject_Dispose(json);
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonArray_Dispose(jarrResp);

Curl Command

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

Postman Collection Item JSON

{
  "name": "runDecisionMatrix",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n   \"inputs\":[\n      {\n         \"myColumnInput\":\"One\"\n      }\n   ]\n}\n"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runDecisionMatrix/:UniqueName",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "actions",
        "custom",
        "runDecisionMatrix",
        ":UniqueName"
      ],
      "variable": [
        {
          "key": "UniqueName",
          "value": "myDecisionMatrix",
          "description": "The value of UniqueName is the unique identifier of the record, which is sourced from the name of a decision matrix."
        }
      ]
    },
    "description": "# Decision Matrix Actions\n\nInvoke a decision matrix in a flow with the Decision Matrix Actions. A decision matrix is a user-defined table where you can look up an output based on the inputs you provide.\n\nFor example, you can look up a candidate’s eligibility to avail medical insurance in a decision matrix based on the candidate’s age and gender.\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/runDecisionMatrix/{UniqueName}\n\nNote\n\nThe value of UniqueName is the unique identifier of the record, which is sourced from the name of a decision matrix.\n\nFormatsJSONHTTP MethodsPOSTAuthenticationAuthorization: Bearer token\n\n## Inputs\n\nVary depending on the selected decision matrix.\n\n## Outputs\n\nVary depending on the inputs of the selected decision matrix.\n\n## Usage\n\nSample Request\n\nHere’s an example POST request that has the inputs, such as, age and state:\n\n```\n{\n   \"inputs\":[\n      {\n         \"age\":\"25\",\n         \"state\":\"NY\"\n      },\n      {\n         \"age\":\"25\",\n         \"state\":\"CA\"\n      },\n      {\n         \"age\":\"\",\n         \"state\":\"WA\"\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\":\"premiumTaxLookup\",\n      \"errors\":null,\n      \"isSuccess\":true,\n      \"outputValues\":{\n         \"premium\":2400.0,\n         \"tax\":200.0\n      }\n   },\n   {\n      \"actionName\":\"premiumTaxLookup\",\n      \"errors\":null,\n      \"isSuccess\":true,\n      \"outputValues\":{\n         \"premium\":2400.0,\n         \"tax\":200.0\n      }\n   },\n   {\n      \"actionName\":\"premiumTaxLookup\",\n      \"errors\":[\n         {\n            \"statusCode\":\"REQUIRED_FIELD_MISSING\",\n            \"message\":\"Missing required input parameter: age\",\n            \"fields\":[\n            ]\n         }\n      ],\n      \"isSuccess\":false,\n      \"outputValues\":null\n   }\n]\n\n ```"
  },
  "response": [
    {
      "name": "runDecisionMatrix",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n   \"inputs\":[\n      {\n         \"myColumnInput\":\"One\"\n      }\n   ]\n}\n"
        },
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/actions/custom/runDecisionMatrix/:UniqueName",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "actions",
            "custom",
            "runDecisionMatrix",
            ":UniqueName"
          ],
          "variable": [
            {
              "key": "UniqueName",
              "value": "myDecisionMatrix",
              "description": "The value of UniqueName is the unique identifier of the record, which is sourced from the name of a decision matrix."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 07 Sep 2023 13:00:30 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=15/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\": \"myDecisionMatrix\",\n        \"errors\": null,\n        \"isSuccess\": true,\n        \"outputValues\": {\n            \"myColumnOutput\": \"1\"\n        },\n        \"version\": 1\n    }\n]"
    }
  ]
}