SQL Server / Cognite API v1 / Create 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.
-- {
-- "items": [
-- {
-- "externalId": "incididunt cillum adipisicing",
-- "dataSetId": 423131483236284,
-- "startTime": 44041889,
-- "endTime": 96620943,
-- "type": "repr",
-- "subtype": "in qui nisi amet adipisicing",
-- "description": "occaecat labore aute aliquip culpa",
-- "metadata": {},
-- "assetIds": [
-- 4718222394395170,
-- 910139302320326
-- ],
-- "source": "tempor amet"
-- },
-- {
-- "externalId": "eiusmod non occaecat Lorem veniam",
-- "dataSetId": 1722008537542636,
-- "startTime": 25642627,
-- "endTime": 13905808,
-- "type": "reprehenderit ut voluptate ea in",
-- "subtype": "ut mollit irure cupidatat nulla",
-- "description": "quis culpa dolore",
-- "metadata": {},
-- "assetIds": [
-- 3955311648854054,
-- 7221931367126430
-- ],
-- "source": "consectetur"
-- }
-- ]
-- }
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, 'UpdateString', @success OUT, 'items[0].externalId', 'incididunt cillum adipisicing'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].dataSetId', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].startTime', 44041889
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].endTime', 96620943
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].type', 'repr'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].subtype', 'in qui nisi amet adipisicing'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].description', 'occaecat labore aute aliquip culpa'
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[0].metadata'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].assetIds[0]', 4718222394395170
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].assetIds[1]', 910139302320326
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].source', 'tempor amet'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].externalId', 'eiusmod non occaecat Lorem veniam'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].dataSetId', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].startTime', 25642627
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].endTime', 13905808
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].type', 'reprehenderit ut voluptate ea in'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].subtype', 'ut mollit irure cupidatat nulla'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].description', 'quis culpa dolore'
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'items[1].metadata'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].assetIds[0]', 3955311648854054
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].assetIds[1]', 7221931367126430
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].source', 'consectetur'
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', '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 '{
"items": [
{
"externalId": "incididunt cillum adipisicing",
"dataSetId": 423131483236284,
"startTime": 44041889,
"endTime": 96620943,
"type": "repr",
"subtype": "in qui nisi amet adipisicing",
"description": "occaecat labore aute aliquip culpa",
"metadata": {},
"assetIds": [
4718222394395170,
910139302320326
],
"source": "tempor amet"
},
{
"externalId": "eiusmod non occaecat Lorem veniam",
"dataSetId": 1722008537542636,
"startTime": 25642627,
"endTime": 13905808,
"type": "reprehenderit ut voluptate ea in",
"subtype": "ut mollit irure cupidatat nulla",
"description": "quis culpa dolore",
"metadata": {},
"assetIds": [
3955311648854054,
7221931367126430
],
"source": "consectetur"
}
]
}'
https://domain.com/api/v1/projects/{{project}}/events
Postman Collection Item JSON
{
"id": "createEvents",
"name": "Create events",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"events"
],
"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"
}
],
"description": "Creates multiple event objects in the same project. It is possible to post a maximum of 1000 events per request.",
"body": {
"mode": "raw",
"raw": "{\n \"items\": [\n {\n \"externalId\": \"incididunt cillum adipisicing\",\n \"dataSetId\": 423131483236284,\n \"startTime\": 44041889,\n \"endTime\": 96620943,\n \"type\": \"repr\",\n \"subtype\": \"in qui nisi amet adipisicing\",\n \"description\": \"occaecat labore aute aliquip culpa\",\n \"metadata\": {},\n \"assetIds\": [\n 4718222394395170,\n 910139302320326\n ],\n \"source\": \"tempor amet\"\n },\n {\n \"externalId\": \"eiusmod non occaecat Lorem veniam\",\n \"dataSetId\": 1722008537542636,\n \"startTime\": 25642627,\n \"endTime\": 13905808,\n \"type\": \"reprehenderit ut voluptate ea in\",\n \"subtype\": \"ut mollit irure cupidatat nulla\",\n \"description\": \"quis culpa dolore\",\n \"metadata\": {},\n \"assetIds\": [\n 3955311648854054,\n 7221931367126430\n ],\n \"source\": \"consectetur\"\n }\n ]\n}"
}
}
}