Chilkat Online Tools

VB.NET / Salesforce Platform APIs / Prediction definitions

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

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

Dim sbResponseBody As New Chilkat.StringBuilder
success = http.QuickGetSb("https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions",sbResponseBody)
If (success = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim jResp As New Chilkat.JsonObject
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

Debug.WriteLine("Response Body:")
Debug.WriteLine(jResp.Emit())

Dim respStatusCode As Integer = http.LastStatus
Debug.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(http.LastHeader)
    Debug.WriteLine("Failed.")
    Exit Sub
End If


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

' {
'   "nextPageUrl": null,
'   "predictionDefinitions": [
'     {
'       "countOfActiveModels": 1,
'       "countOfModels": 1,
'       "createdBy": {
'         "id": "0055Y00000DWwAIQA1",
'         "name": "Philippe Ozil",
'         "profilePhotoUrl": "https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T"
'       },
'       "createdDate": "2021-03-04T13:37:02.000Z",
'       "id": "1OR5Y0000010ws8WAA",
'       "label": "Sales_per_Customer",
'       "lastModifiedBy": {
'         "id": "0055Y00000DWwAIQA1",
'         "name": "Philippe Ozil",
'         "profilePhotoUrl": "https://crm-analytics-deorg-dev-ed--c.documentforce.com/profilephoto/005/T"
'       },
'       "lastModifiedDate": "2021-03-04T13:37:02.000Z",
'       "modelsUrl": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models",
'       "name": "Sales_per_Customer",
'       "outcome": {
'         "goal": "Maximize",
'         "label": "Sales per Customer",
'         "name": "Sales_per_Customer"
'       },
'       "predictionType": "Regression",
'       "status": "Enabled",
'       "url": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA"
'     }
'   ],
'   "totalSize": 1,
'   "url": "/services/data/v51.0/smartdatadiscovery/predictiondefinitions?pageSize=25"
' }

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



Dim countOfActiveModels As Integer
Dim countOfModels As Integer
Dim Id As String
Dim Name As String
Dim ProfilePhotoUrl As String
Dim createdDate As String
Dim id As String
Dim label As String
Dim lastModifiedById As String
Dim lastModifiedByName As String
Dim lastModifiedByProfilePhotoUrl As String
Dim lastModifiedDate As String
Dim modelsUrl As String
Dim name As String
Dim Goal As String
Dim Label As String
Dim outcomeName As String
Dim predictionType As String
Dim status As String

Dim nextPageUrl As String = jResp.StringOf("nextPageUrl")
Dim totalSize As Integer = jResp.IntOf("totalSize")
Dim url As String = jResp.StringOf("url")
Dim i As Integer = 0
Dim count_i As Integer = jResp.SizeOfArray("predictionDefinitions")
While i < count_i
    jResp.I = i
    countOfActiveModels = jResp.IntOf("predictionDefinitions[i].countOfActiveModels")
    countOfModels = jResp.IntOf("predictionDefinitions[i].countOfModels")
    Id = jResp.StringOf("predictionDefinitions[i].createdBy.id")
    Name = jResp.StringOf("predictionDefinitions[i].createdBy.name")
    ProfilePhotoUrl = jResp.StringOf("predictionDefinitions[i].createdBy.profilePhotoUrl")
    createdDate = jResp.StringOf("predictionDefinitions[i].createdDate")
    id = jResp.StringOf("predictionDefinitions[i].id")
    label = jResp.StringOf("predictionDefinitions[i].label")
    lastModifiedById = jResp.StringOf("predictionDefinitions[i].lastModifiedBy.id")
    lastModifiedByName = jResp.StringOf("predictionDefinitions[i].lastModifiedBy.name")
    lastModifiedByProfilePhotoUrl = jResp.StringOf("predictionDefinitions[i].lastModifiedBy.profilePhotoUrl")
    lastModifiedDate = jResp.StringOf("predictionDefinitions[i].lastModifiedDate")
    modelsUrl = jResp.StringOf("predictionDefinitions[i].modelsUrl")
    name = jResp.StringOf("predictionDefinitions[i].name")
    Goal = jResp.StringOf("predictionDefinitions[i].outcome.goal")
    Label = jResp.StringOf("predictionDefinitions[i].outcome.label")
    outcomeName = jResp.StringOf("predictionDefinitions[i].outcome.name")
    predictionType = jResp.StringOf("predictionDefinitions[i].predictionType")
    status = jResp.StringOf("predictionDefinitions[i].status")
    url = jResp.StringOf("predictionDefinitions[i].url")
    i = i + 1
End While

Curl Command

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

Postman Collection Item JSON

{
  "name": "Prediction definitions",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "smartdatadiscovery",
        "predictionDefinitions"
      ]
    },
    "description": "Get available prediction definitions."
  },
  "response": [
    {
      "name": "Prediction definitions",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "smartdatadiscovery",
            "predictionDefinitions"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 04 Mar 2021 13:45:15 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    \"nextPageUrl\": null,\n    \"predictionDefinitions\": [\n        {\n            \"countOfActiveModels\": 1,\n            \"countOfModels\": 1,\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:02.000Z\",\n            \"id\": \"1OR5Y0000010ws8WAA\",\n            \"label\": \"Sales_per_Customer\",\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:02.000Z\",\n            \"modelsUrl\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA/models\",\n            \"name\": \"Sales_per_Customer\",\n            \"outcome\": {\n                \"goal\": \"Maximize\",\n                \"label\": \"Sales per Customer\",\n                \"name\": \"Sales_per_Customer\"\n            },\n            \"predictionType\": \"Regression\",\n            \"status\": \"Enabled\",\n            \"url\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions/1OR5Y0000010ws8WAA\"\n        }\n    ],\n    \"totalSize\": 1,\n    \"url\": \"/services/data/v51.0/smartdatadiscovery/predictiondefinitions?pageSize=25\"\n}"
    }
  ]
}