Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://domain.com/services/data/v{{version}}/smartdatadiscovery/predictionDefinitions', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- 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
DECLARE @countOfActiveModels int
DECLARE @countOfModels int
DECLARE @Id nvarchar(4000)
DECLARE @Name nvarchar(4000)
DECLARE @ProfilePhotoUrl nvarchar(4000)
DECLARE @createdDate nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @label nvarchar(4000)
DECLARE @lastModifiedById nvarchar(4000)
DECLARE @lastModifiedByName nvarchar(4000)
DECLARE @lastModifiedByProfilePhotoUrl nvarchar(4000)
DECLARE @lastModifiedDate nvarchar(4000)
DECLARE @modelsUrl nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @Goal nvarchar(4000)
DECLARE @Label nvarchar(4000)
DECLARE @outcomeName nvarchar(4000)
DECLARE @predictionType nvarchar(4000)
DECLARE @status nvarchar(4000)
DECLARE @nextPageUrl nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @nextPageUrl OUT, 'nextPageUrl'
DECLARE @totalSize int
EXEC sp_OAMethod @jResp, 'IntOf', @totalSize OUT, 'totalSize'
DECLARE @url nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'url'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'predictionDefinitions'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'IntOf', @countOfActiveModels OUT, 'predictionDefinitions[i].countOfActiveModels'
EXEC sp_OAMethod @jResp, 'IntOf', @countOfModels OUT, 'predictionDefinitions[i].countOfModels'
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'predictionDefinitions[i].createdBy.id'
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'predictionDefinitions[i].createdBy.name'
EXEC sp_OAMethod @jResp, 'StringOf', @ProfilePhotoUrl OUT, 'predictionDefinitions[i].createdBy.profilePhotoUrl'
EXEC sp_OAMethod @jResp, 'StringOf', @createdDate OUT, 'predictionDefinitions[i].createdDate'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'predictionDefinitions[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @label OUT, 'predictionDefinitions[i].label'
EXEC sp_OAMethod @jResp, 'StringOf', @lastModifiedById OUT, 'predictionDefinitions[i].lastModifiedBy.id'
EXEC sp_OAMethod @jResp, 'StringOf', @lastModifiedByName OUT, 'predictionDefinitions[i].lastModifiedBy.name'
EXEC sp_OAMethod @jResp, 'StringOf', @lastModifiedByProfilePhotoUrl OUT, 'predictionDefinitions[i].lastModifiedBy.profilePhotoUrl'
EXEC sp_OAMethod @jResp, 'StringOf', @lastModifiedDate OUT, 'predictionDefinitions[i].lastModifiedDate'
EXEC sp_OAMethod @jResp, 'StringOf', @modelsUrl OUT, 'predictionDefinitions[i].modelsUrl'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'predictionDefinitions[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @Goal OUT, 'predictionDefinitions[i].outcome.goal'
EXEC sp_OAMethod @jResp, 'StringOf', @Label OUT, 'predictionDefinitions[i].outcome.label'
EXEC sp_OAMethod @jResp, 'StringOf', @outcomeName OUT, 'predictionDefinitions[i].outcome.name'
EXEC sp_OAMethod @jResp, 'StringOf', @predictionType OUT, 'predictionDefinitions[i].predictionType'
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'predictionDefinitions[i].status'
EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'predictionDefinitions[i].url'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
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}"
}
]
}