Chilkat Online Tools

unicodeC / Cognite API v1 / Create events

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"items[0].externalId",L"incididunt cillum adipisicing");
    CkJsonObjectW_UpdateInt(json,L"items[0].dataSetId",123);
    CkJsonObjectW_UpdateInt(json,L"items[0].startTime",44041889);
    CkJsonObjectW_UpdateInt(json,L"items[0].endTime",96620943);
    CkJsonObjectW_UpdateString(json,L"items[0].type",L"repr");
    CkJsonObjectW_UpdateString(json,L"items[0].subtype",L"in qui nisi amet adipisicing");
    CkJsonObjectW_UpdateString(json,L"items[0].description",L"occaecat labore aute aliquip culpa");
    CkJsonObjectW_UpdateNewObject(json,L"items[0].metadata");
    CkJsonObjectW_UpdateInt(json,L"items[0].assetIds[0]",4718222394395170);
    CkJsonObjectW_UpdateInt(json,L"items[0].assetIds[1]",910139302320326);
    CkJsonObjectW_UpdateString(json,L"items[0].source",L"tempor amet");
    CkJsonObjectW_UpdateString(json,L"items[1].externalId",L"eiusmod non occaecat Lorem veniam");
    CkJsonObjectW_UpdateInt(json,L"items[1].dataSetId",123);
    CkJsonObjectW_UpdateInt(json,L"items[1].startTime",25642627);
    CkJsonObjectW_UpdateInt(json,L"items[1].endTime",13905808);
    CkJsonObjectW_UpdateString(json,L"items[1].type",L"reprehenderit ut voluptate ea in");
    CkJsonObjectW_UpdateString(json,L"items[1].subtype",L"ut mollit irure cupidatat nulla");
    CkJsonObjectW_UpdateString(json,L"items[1].description",L"quis culpa dolore");
    CkJsonObjectW_UpdateNewObject(json,L"items[1].metadata");
    CkJsonObjectW_UpdateInt(json,L"items[1].assetIds[0]",3955311648854054);
    CkJsonObjectW_UpdateInt(json,L"items[1].assetIds[1]",7221931367126430);
    CkJsonObjectW_UpdateString(json,L"items[1].source",L"consectetur");

    CkHttpW_SetRequestHeader(http,L"content-type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"api-key",L"{{api-key}}");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/api/v1/projects/{{project}}/events",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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