Chilkat Online Tools

delphiDll / Salesforce Platform APIs / Prediction definition metadata

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
countOfActiveModels: Integer;
countOfModels: Integer;
Id: PWideChar;
Name: PWideChar;
ProfilePhotoUrl: PWideChar;
createdDate: PWideChar;
id: PWideChar;
label: PWideChar;
lastModifiedById: PWideChar;
lastModifiedByName: PWideChar;
lastModifiedByProfilePhotoUrl: PWideChar;
lastModifiedDate: PWideChar;
modelsUrl: PWideChar;
name: PWideChar;
Goal: PWideChar;
Label: PWideChar;
outcomeName: PWideChar;
predictionType: PWideChar;
status: PWideChar;
url: PWideChar;

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

http := CkHttp_Create();

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

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

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

// {
//   "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"
// }

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

countOfActiveModels := CkJsonObject_IntOf(jResp,'countOfActiveModels');
countOfModels := CkJsonObject_IntOf(jResp,'countOfModels');
Id := CkJsonObject__stringOf(jResp,'createdBy.id');
Name := CkJsonObject__stringOf(jResp,'createdBy.name');
ProfilePhotoUrl := CkJsonObject__stringOf(jResp,'createdBy.profilePhotoUrl');
createdDate := CkJsonObject__stringOf(jResp,'createdDate');
id := CkJsonObject__stringOf(jResp,'id');
label := CkJsonObject__stringOf(jResp,'label');
lastModifiedById := CkJsonObject__stringOf(jResp,'lastModifiedBy.id');
lastModifiedByName := CkJsonObject__stringOf(jResp,'lastModifiedBy.name');
lastModifiedByProfilePhotoUrl := CkJsonObject__stringOf(jResp,'lastModifiedBy.profilePhotoUrl');
lastModifiedDate := CkJsonObject__stringOf(jResp,'lastModifiedDate');
modelsUrl := CkJsonObject__stringOf(jResp,'modelsUrl');
name := CkJsonObject__stringOf(jResp,'name');
Goal := CkJsonObject__stringOf(jResp,'outcome.goal');
Label := CkJsonObject__stringOf(jResp,'outcome.label');
outcomeName := CkJsonObject__stringOf(jResp,'outcome.name');
predictionType := CkJsonObject__stringOf(jResp,'predictionType');
status := CkJsonObject__stringOf(jResp,'status');
url := CkJsonObject__stringOf(jResp,'url');

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

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

Postman Collection Item JSON

{
  "name": "Prediction definition metadata",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/:PREDICTION_DEFINITION_ID",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "smartdatadiscovery",
        "predictionDefinitions",
        ":PREDICTION_DEFINITION_ID"
      ],
      "variable": [
        {
          "key": "PREDICTION_DEFINITION_ID",
          "value": ""
        }
      ]
    },
    "description": "Get available prediction definitions."
  },
  "response": [
    {
      "name": "Prediction definition metadata",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions/1OR5Y0000010ws8WAA",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "smartdatadiscovery",
            "predictionDefinitions",
            "1OR5Y0000010ws8WAA"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 04 Mar 2021 13:45:58 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    \"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}"
    }
  ]
}