Chilkat Online Tools

unicodeC / Salesforce Platform APIs / Prediction models

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *Id;
    const wchar_t *Name;
    const wchar_t *ProfilePhotoUrl;
    const wchar_t *createdDate;
    const wchar_t *historyUrl;
    const wchar_t *id;
    BOOL isRefreshEnabled;
    const wchar_t *label;
    const wchar_t *lastModifiedById;
    const wchar_t *lastModifiedByName;
    const wchar_t *lastModifiedByProfilePhotoUrl;
    const wchar_t *lastModifiedDate;
    const wchar_t *modelId;
    const wchar_t *modelType;
    const wchar_t *name;
    const wchar_t *predictionDefinitionUrl;
    int sortOrder;
    const wchar_t *status;
    int j;
    int count_j;
    const wchar_t *Label;
    const wchar_t *modelFieldName;
    const wchar_t *v_Type;
    const wchar_t *fieldLabel;
    const wchar_t *fieldName;
    const wchar_t *fieldType;
    int k;
    int count_k;
    int totalSize;
    const wchar_t *url;
    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();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID/models",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

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

    // {
    //   "models": [
    //     {
    //       "createdBy": {
    //         "id": "0055Y00000DWwAIQA1",
    //         "name": "Philippe Ozil",
    //         "profilePhotoUrl": "https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T"
    //       },
    //       "createdDate": "2021-03-04T13:37:03.000Z",
    //       "fieldMappingList": [
    //         {
    //           "modelField": {
    //             "label": "Category",
    //             "name": "Category",
    //             "type": "Text"
    //           }
    //         },
    //         {
    //           "modelField": {
    //             "label": "Sales",
    //             "name": "Sales",
    //             "type": "Number"
    //           }
    //         },
    //         {
    //           "modelField": {
    //             "label": "Profit per Order",
    //             "name": "Profit_per_Order",
    //             "type": "Number"
    //           }
    //         },
    //         {
    //           "modelField": {
    //             "label": "Sub-Category",
    //             "name": "Sub_Category",
    //             "type": "Text"
    //           }
    //         },
    //         {
    //           "modelField": {
    //             "label": "Quantity",
    //             "name": "Quantity",
    //             "type": "Number"
    //           }
    //         }
    //       ],
    //       "filters": [
    //       ],
    //       "historyUrl": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models/1Ot5Y0000010wzNSAQ/histories",
    //       "id": "1Ot5Y0000010wzNSAQ",
    //       "isRefreshEnabled": false,
    //       "label": "superstore-orders",
    //       "lastModifiedBy": {
    //         "id": "0055Y00000DWwAIQA1",
    //         "name": "Philippe Ozil",
    //         "profilePhotoUrl": "https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T"
    //       },
    //       "lastModifiedDate": "2021-03-04T13:37:03.000Z",
    //       "model": {
    //         "id": "1OT5Y0000010zlzWAA"
    //       },
    //       "modelType": "Regression",
    //       "name": "superstore_orders",
    //       "predictionDefinitionUrl": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA",
    //       "prescribableFields": [
    //         {
    //           "customDefinitions": [
    //           ],
    //           "field": {
    //             "label": "Quantity",
    //             "name": "Quantity",
    //             "type": "Number"
    //           }
    //         }
    //       ],
    //       "sortOrder": 0,
    //       "status": "Enabled",
    //       "url": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models/1Ot5Y0000010wzNSAQ"
    //     }
    //   ],
    //   "totalSize": 1,
    //   "url": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models"
    // }

    // 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.

    totalSize = CkJsonObjectW_IntOf(jResp,L"totalSize");
    url = CkJsonObjectW_stringOf(jResp,L"url");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"models");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Id = CkJsonObjectW_stringOf(jResp,L"models[i].createdBy.id");
        Name = CkJsonObjectW_stringOf(jResp,L"models[i].createdBy.name");
        ProfilePhotoUrl = CkJsonObjectW_stringOf(jResp,L"models[i].createdBy.profilePhotoUrl");
        createdDate = CkJsonObjectW_stringOf(jResp,L"models[i].createdDate");
        historyUrl = CkJsonObjectW_stringOf(jResp,L"models[i].historyUrl");
        id = CkJsonObjectW_stringOf(jResp,L"models[i].id");
        isRefreshEnabled = CkJsonObjectW_BoolOf(jResp,L"models[i].isRefreshEnabled");
        label = CkJsonObjectW_stringOf(jResp,L"models[i].label");
        lastModifiedById = CkJsonObjectW_stringOf(jResp,L"models[i].lastModifiedBy.id");
        lastModifiedByName = CkJsonObjectW_stringOf(jResp,L"models[i].lastModifiedBy.name");
        lastModifiedByProfilePhotoUrl = CkJsonObjectW_stringOf(jResp,L"models[i].lastModifiedBy.profilePhotoUrl");
        lastModifiedDate = CkJsonObjectW_stringOf(jResp,L"models[i].lastModifiedDate");
        modelId = CkJsonObjectW_stringOf(jResp,L"models[i].model.id");
        modelType = CkJsonObjectW_stringOf(jResp,L"models[i].modelType");
        name = CkJsonObjectW_stringOf(jResp,L"models[i].name");
        predictionDefinitionUrl = CkJsonObjectW_stringOf(jResp,L"models[i].predictionDefinitionUrl");
        sortOrder = CkJsonObjectW_IntOf(jResp,L"models[i].sortOrder");
        status = CkJsonObjectW_stringOf(jResp,L"models[i].status");
        url = CkJsonObjectW_stringOf(jResp,L"models[i].url");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"models[i].fieldMappingList");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            Label = CkJsonObjectW_stringOf(jResp,L"models[i].fieldMappingList[j].modelField.label");
            modelFieldName = CkJsonObjectW_stringOf(jResp,L"models[i].fieldMappingList[j].modelField.name");
            v_Type = CkJsonObjectW_stringOf(jResp,L"models[i].fieldMappingList[j].modelField.type");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"models[i].filters");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"models[i].prescribableFields");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            fieldLabel = CkJsonObjectW_stringOf(jResp,L"models[i].prescribableFields[j].field.label");
            fieldName = CkJsonObjectW_stringOf(jResp,L"models[i].prescribableFields[j].field.name");
            fieldType = CkJsonObjectW_stringOf(jResp,L"models[i].prescribableFields[j].field.type");
            k = 0;
            count_k = CkJsonObjectW_SizeOfArray(jResp,L"models[i].prescribableFields[j].customDefinitions");
            while (k < count_k) {
                CkJsonObjectW_putK(jResp,k);
                k = k + 1;
            }

            j = j + 1;
        }

        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID/models

Postman Collection Item JSON

{
  "name": "Prediction models",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID/models",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "smartdatadiscovery",
        "predictionDefinitions",
        ":PREDICTION_DEFINITION_ID",
        "models"
      ],
      "variable": [
        {
          "key": "PREDICTION_DEFINITION_ID",
          "value": ""
        }
      ]
    },
    "description": "Get available prediction definitions."
  },
  "response": [
    {
      "name": "Prediction models",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/1OR5Y0000010ws8WAA/models",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "smartdatadiscovery",
            "predictionDefinitions",
            "1OR5Y0000010ws8WAA",
            "models"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 04 Mar 2021 13:48:31 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536002; includeSubDomains"
        },
        {
          "key": "Expect-CT",
          "value": "max-age=86400, report-uri=\"https://a.forcesslreports.com/Expect-CT-report/00D5Y000001crJvm\""
        },
        {
          "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": "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    \"models\": [\n        {\n            \"createdBy\": {\n                \"id\": \"0055Y00000DWwAIQA1\",\n                \"name\": \"Philippe Ozil\",\n                \"profilePhotoUrl\": \"https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T\"\n            },\n            \"createdDate\": \"2021-03-04T13:37:03.000Z\",\n            \"fieldMappingList\": [\n                {\n                    \"modelField\": {\n                        \"label\": \"Category\",\n                        \"name\": \"Category\",\n                        \"type\": \"Text\"\n                    }\n                },\n                {\n                    \"modelField\": {\n                        \"label\": \"Sales\",\n                        \"name\": \"Sales\",\n                        \"type\": \"Number\"\n                    }\n                },\n                {\n                    \"modelField\": {\n                        \"label\": \"Profit per Order\",\n                        \"name\": \"Profit_per_Order\",\n                        \"type\": \"Number\"\n                    }\n                },\n                {\n                    \"modelField\": {\n                        \"label\": \"Sub-Category\",\n                        \"name\": \"Sub_Category\",\n                        \"type\": \"Text\"\n                    }\n                },\n                {\n                    \"modelField\": {\n                        \"label\": \"Quantity\",\n                        \"name\": \"Quantity\",\n                        \"type\": \"Number\"\n                    }\n                }\n            ],\n            \"filters\": [],\n            \"historyUrl\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models/1Ot5Y0000010wzNSAQ/histories\",\n            \"id\": \"1Ot5Y0000010wzNSAQ\",\n            \"isRefreshEnabled\": false,\n            \"label\": \"superstore-orders\",\n            \"lastModifiedBy\": {\n                \"id\": \"0055Y00000DWwAIQA1\",\n                \"name\": \"Philippe Ozil\",\n                \"profilePhotoUrl\": \"https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T\"\n            },\n            \"lastModifiedDate\": \"2021-03-04T13:37:03.000Z\",\n            \"model\": {\n                \"id\": \"1OT5Y0000010zlzWAA\"\n            },\n            \"modelType\": \"Regression\",\n            \"name\": \"superstore_orders\",\n            \"predictionDefinitionUrl\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA\",\n            \"prescribableFields\": [\n                {\n                    \"customDefinitions\": [],\n                    \"field\": {\n                        \"label\": \"Quantity\",\n                        \"name\": \"Quantity\",\n                        \"type\": \"Number\"\n                    }\n                }\n            ],\n            \"sortOrder\": 0,\n            \"status\": \"Enabled\",\n            \"url\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models/1Ot5Y0000010wzNSAQ\"\n        }\n    ],\n    \"totalSize\": 1,\n    \"url\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models\"\n}"
    }
  ]
}