Chilkat Online Tools

PureBasic / Salesforce Platform APIs / Prediction models

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID/models",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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

    Id.s
    Name.s
    ProfilePhotoUrl.s
    createdDate.s
    historyUrl.s
    id.s
    isRefreshEnabled.i
    label.s
    lastModifiedById.s
    lastModifiedByName.s
    lastModifiedByProfilePhotoUrl.s
    lastModifiedDate.s
    modelId.s
    modelType.s
    name.s
    predictionDefinitionUrl.s
    sortOrder.i
    status.s
    j.i
    count_j.i
    Label.s
    modelFieldName.s
    v_Type.s
    fieldLabel.s
    fieldName.s
    fieldType.s
    k.i
    count_k.i

    totalSize.i = CkJsonObject::ckIntOf(jResp,"totalSize")
    url.s = CkJsonObject::ckStringOf(jResp,"url")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"models")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        Id = CkJsonObject::ckStringOf(jResp,"models[i].createdBy.id")
        Name = CkJsonObject::ckStringOf(jResp,"models[i].createdBy.name")
        ProfilePhotoUrl = CkJsonObject::ckStringOf(jResp,"models[i].createdBy.profilePhotoUrl")
        createdDate = CkJsonObject::ckStringOf(jResp,"models[i].createdDate")
        historyUrl = CkJsonObject::ckStringOf(jResp,"models[i].historyUrl")
        id = CkJsonObject::ckStringOf(jResp,"models[i].id")
        isRefreshEnabled = CkJsonObject::ckBoolOf(jResp,"models[i].isRefreshEnabled")
        label = CkJsonObject::ckStringOf(jResp,"models[i].label")
        lastModifiedById = CkJsonObject::ckStringOf(jResp,"models[i].lastModifiedBy.id")
        lastModifiedByName = CkJsonObject::ckStringOf(jResp,"models[i].lastModifiedBy.name")
        lastModifiedByProfilePhotoUrl = CkJsonObject::ckStringOf(jResp,"models[i].lastModifiedBy.profilePhotoUrl")
        lastModifiedDate = CkJsonObject::ckStringOf(jResp,"models[i].lastModifiedDate")
        modelId = CkJsonObject::ckStringOf(jResp,"models[i].model.id")
        modelType = CkJsonObject::ckStringOf(jResp,"models[i].modelType")
        name = CkJsonObject::ckStringOf(jResp,"models[i].name")
        predictionDefinitionUrl = CkJsonObject::ckStringOf(jResp,"models[i].predictionDefinitionUrl")
        sortOrder = CkJsonObject::ckIntOf(jResp,"models[i].sortOrder")
        status = CkJsonObject::ckStringOf(jResp,"models[i].status")
        url = CkJsonObject::ckStringOf(jResp,"models[i].url")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"models[i].fieldMappingList")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            Label = CkJsonObject::ckStringOf(jResp,"models[i].fieldMappingList[j].modelField.label")
            modelFieldName = CkJsonObject::ckStringOf(jResp,"models[i].fieldMappingList[j].modelField.name")
            v_Type = CkJsonObject::ckStringOf(jResp,"models[i].fieldMappingList[j].modelField.type")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"models[i].filters")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"models[i].prescribableFields")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            fieldLabel = CkJsonObject::ckStringOf(jResp,"models[i].prescribableFields[j].field.label")
            fieldName = CkJsonObject::ckStringOf(jResp,"models[i].prescribableFields[j].field.name")
            fieldType = CkJsonObject::ckStringOf(jResp,"models[i].prescribableFields[j].field.type")
            k = 0
            count_k = CkJsonObject::ckSizeOfArray(jResp,"models[i].prescribableFields[j].customDefinitions")
            While k < count_k
                CkJsonObject::setCkK(jResp, k)
                k = k + 1
            Wend
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

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}"
    }
  ]
}