SQL Server / Cognite API v1 / Search within events
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
DECLARE @iTmp0 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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "filter": {
-- "startTime": {
-- "max": 28954538,
-- "min": 46490486
-- },
-- "endTime": {
-- "isNull": false
-- },
-- "activeAtTime": {
-- "max": 27359549,
-- "min": 32947272
-- },
-- "metadata": {},
-- "assetIds": [
-- 4883269954114660,
-- 2578912121595962
-- ],
-- "assetExternalIds": [
-- "exercitation dolor do",
-- "occaecat"
-- ],
-- "rootAssetIds": [
-- {
-- "id": 491458656026080
-- },
-- {
-- "id": 1026689202395094
-- }
-- ],
-- "assetSubtreeIds": [
-- {
-- "externalId": "laborum"
-- },
-- {
-- "externalId": "velit Duis"
-- }
-- ],
-- "dataSetIds": [
-- {
-- "externalId": "ad"
-- },
-- {
-- "externalId": "culpa"
-- }
-- ],
-- "source": "deserunt ut mollit anim l",
-- "type": "sed nisi exercita",
-- "subtype": "aliqua Ut",
-- "createdTime": {
-- "max": 39562876,
-- "min": 1881975
-- },
-- "lastUpdatedTime": {
-- "max": 69566439,
-- "min": 58702695
-- },
-- "externalIdPrefix": "in Excepteur"
-- },
-- "search": {
-- "description": "proident ut"
-- },
-- "limit": 100
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.startTime.max', 28954538
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.startTime.min', 46490486
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.endTime.isNull', 0
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.activeAtTime.max', 27359549
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.activeAtTime.min', 32947272
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[0]', 4883269954114660
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[1]', 2578912121595962
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[0]', 'exercitation dolor do'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[1]', 'occaecat'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[0].id', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[1].id', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetSubtreeIds[0].externalId', 'laborum'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetSubtreeIds[1].externalId', 'velit Duis'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[0].externalId', 'ad'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[1].externalId', 'culpa'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.source', 'deserunt ut mollit anim l'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.type', 'sed nisi exercita'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.subtype', 'aliqua Ut'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 39562876
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 1881975
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 69566439
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 58702695
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'in Excepteur'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'search.description', 'proident ut'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'limit', 100
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'api-key', '{{api-key}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/projects/{{project}}/events/search', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
Curl Command
curl -X POST
-H "api-key: {{api-key}}"
-H "content-type: application/json"
-d '{
"filter": {
"startTime": {
"max": 28954538,
"min": 46490486
},
"endTime": {
"isNull": false
},
"activeAtTime": {
"max": 27359549,
"min": 32947272
},
"metadata": {},
"assetIds": [
4883269954114660,
2578912121595962
],
"assetExternalIds": [
"exercitation dolor do",
"occaecat"
],
"rootAssetIds": [
{
"id": 491458656026080
},
{
"id": 1026689202395094
}
],
"assetSubtreeIds": [
{
"externalId": "laborum"
},
{
"externalId": "velit Duis"
}
],
"dataSetIds": [
{
"externalId": "ad"
},
{
"externalId": "culpa"
}
],
"source": "deserunt ut mollit anim l",
"type": "sed nisi exercita",
"subtype": "aliqua Ut",
"createdTime": {
"max": 39562876,
"min": 1881975
},
"lastUpdatedTime": {
"max": 69566439,
"min": 58702695
},
"externalIdPrefix": "in Excepteur"
},
"search": {
"description": "proident ut"
},
"limit": 100
}'
https://domain.com/api/v1/projects/{{project}}/events/search
Postman Collection Item JSON
{
"id": "searchEvents",
"name": "Search within events",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"events",
"search"
],
"query": [
],
"variable": [
]
},
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{api-key}}",
"description": "An admin can create API keys in the Cognite console."
},
{
"key": "content-type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"filter\": {\n \"startTime\": {\n \"max\": 28954538,\n \"min\": 46490486\n },\n \"endTime\": {\n \"isNull\": false\n },\n \"activeAtTime\": {\n \"max\": 27359549,\n \"min\": 32947272\n },\n \"metadata\": {},\n \"assetIds\": [\n 4883269954114660,\n 2578912121595962\n ],\n \"assetExternalIds\": [\n \"exercitation dolor do\",\n \"occaecat\"\n ],\n \"rootAssetIds\": [\n {\n \"id\": 491458656026080\n },\n {\n \"id\": 1026689202395094\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"externalId\": \"laborum\"\n },\n {\n \"externalId\": \"velit Duis\"\n }\n ],\n \"dataSetIds\": [\n {\n \"externalId\": \"ad\"\n },\n {\n \"externalId\": \"culpa\"\n }\n ],\n \"source\": \"deserunt ut mollit anim l\",\n \"type\": \"sed nisi exercita\",\n \"subtype\": \"aliqua Ut\",\n \"createdTime\": {\n \"max\": 39562876,\n \"min\": 1881975\n },\n \"lastUpdatedTime\": {\n \"max\": 69566439,\n \"min\": 58702695\n },\n \"externalIdPrefix\": \"in Excepteur\"\n },\n \"search\": {\n \"description\": \"proident ut\"\n },\n \"limit\": 100\n}"
}
}
}