Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
int countOfActiveModels;
int countOfModels;
const char *Id;
const char *Name;
const char *ProfilePhotoUrl;
const char *createdDate;
const char *id;
const char *label;
const char *lastModifiedById;
const char *lastModifiedByName;
const char *lastModifiedByProfilePhotoUrl;
const char *lastModifiedDate;
const char *modelsUrl;
const char *name;
const char *Goal;
const char *Label;
const char *outcomeName;
const char *predictionType;
const char *status;
const char *nextPageUrl;
int totalSize;
const char *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 = 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",sbResponseBody);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttp_getLastStatus(http);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttp_lastHeader(http));
printf("Failed.\n");
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
// 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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
nextPageUrl = CkJsonObject_stringOf(jResp,"nextPageUrl");
totalSize = CkJsonObject_IntOf(jResp,"totalSize");
url = CkJsonObject_stringOf(jResp,"url");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"predictionDefinitions");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
countOfActiveModels = CkJsonObject_IntOf(jResp,"predictionDefinitions[i].countOfActiveModels");
countOfModels = CkJsonObject_IntOf(jResp,"predictionDefinitions[i].countOfModels");
Id = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].createdBy.id");
Name = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].createdBy.name");
ProfilePhotoUrl = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].createdBy.profilePhotoUrl");
createdDate = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].createdDate");
id = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].id");
label = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].label");
lastModifiedById = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].lastModifiedBy.id");
lastModifiedByName = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].lastModifiedBy.name");
lastModifiedByProfilePhotoUrl = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].lastModifiedBy.profilePhotoUrl");
lastModifiedDate = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].lastModifiedDate");
modelsUrl = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].modelsUrl");
name = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].name");
Goal = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].outcome.goal");
Label = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].outcome.label");
outcomeName = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].outcome.name");
predictionType = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].predictionType");
status = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].status");
url = CkJsonObject_stringOf(jResp,"predictionDefinitions[i].url");
i = i + 1;
}
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
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}"
}
]
}