Chilkat Online Tools

PowerBuilder / Salesforce Platform APIs / Prediction definitions

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_CountOfActiveModels
integer li_CountOfModels
string ls_Id
string ls_Name
string ls_ProfilePhotoUrl
string ls_CreatedDate
string ls_Id
string ls_Label
string ls_LastModifiedById
string ls_LastModifiedByName
string ls_LastModifiedByProfilePhotoUrl
string ls_LastModifiedDate
string ls_ModelsUrl
string ls_Name
string ls_Goal
string ls_Label
string ls_OutcomeName
string ls_PredictionType
string ls_Status
string ls_NextPageUrl
integer li_TotalSize
string ls_Url
integer i
integer li_Count_i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
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

ls_NextPageUrl = loo_JResp.StringOf("nextPageUrl")
li_TotalSize = loo_JResp.IntOf("totalSize")
ls_Url = loo_JResp.StringOf("url")
i = 0
li_Count_i = loo_JResp.SizeOfArray("predictionDefinitions")
do while i < li_Count_i
    loo_JResp.I = i
    li_CountOfActiveModels = loo_JResp.IntOf("predictionDefinitions[i].countOfActiveModels")
    li_CountOfModels = loo_JResp.IntOf("predictionDefinitions[i].countOfModels")
    ls_Id = loo_JResp.StringOf("predictionDefinitions[i].createdBy.id")
    ls_Name = loo_JResp.StringOf("predictionDefinitions[i].createdBy.name")
    ls_ProfilePhotoUrl = loo_JResp.StringOf("predictionDefinitions[i].createdBy.profilePhotoUrl")
    ls_CreatedDate = loo_JResp.StringOf("predictionDefinitions[i].createdDate")
    ls_Id = loo_JResp.StringOf("predictionDefinitions[i].id")
    ls_Label = loo_JResp.StringOf("predictionDefinitions[i].label")
    ls_LastModifiedById = loo_JResp.StringOf("predictionDefinitions[i].lastModifiedBy.id")
    ls_LastModifiedByName = loo_JResp.StringOf("predictionDefinitions[i].lastModifiedBy.name")
    ls_LastModifiedByProfilePhotoUrl = loo_JResp.StringOf("predictionDefinitions[i].lastModifiedBy.profilePhotoUrl")
    ls_LastModifiedDate = loo_JResp.StringOf("predictionDefinitions[i].lastModifiedDate")
    ls_ModelsUrl = loo_JResp.StringOf("predictionDefinitions[i].modelsUrl")
    ls_Name = loo_JResp.StringOf("predictionDefinitions[i].name")
    ls_Goal = loo_JResp.StringOf("predictionDefinitions[i].outcome.goal")
    ls_Label = loo_JResp.StringOf("predictionDefinitions[i].outcome.label")
    ls_OutcomeName = loo_JResp.StringOf("predictionDefinitions[i].outcome.name")
    ls_PredictionType = loo_JResp.StringOf("predictionDefinitions[i].predictionType")
    ls_Status = loo_JResp.StringOf("predictionDefinitions[i].status")
    ls_Url = loo_JResp.StringOf("predictionDefinitions[i].url")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

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