unicodeC / Cognite API v1 / Search within 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.
// {
// "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
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateInt(json,L"filter.startTime.max",28954538);
CkJsonObjectW_UpdateInt(json,L"filter.startTime.min",46490486);
CkJsonObjectW_UpdateBool(json,L"filter.endTime.isNull",FALSE);
CkJsonObjectW_UpdateInt(json,L"filter.activeAtTime.max",27359549);
CkJsonObjectW_UpdateInt(json,L"filter.activeAtTime.min",32947272);
CkJsonObjectW_UpdateNewObject(json,L"filter.metadata");
CkJsonObjectW_UpdateInt(json,L"filter.assetIds[0]",4883269954114660);
CkJsonObjectW_UpdateInt(json,L"filter.assetIds[1]",2578912121595962);
CkJsonObjectW_UpdateString(json,L"filter.assetExternalIds[0]",L"exercitation dolor do");
CkJsonObjectW_UpdateString(json,L"filter.assetExternalIds[1]",L"occaecat");
CkJsonObjectW_UpdateInt(json,L"filter.rootAssetIds[0].id",123);
CkJsonObjectW_UpdateInt(json,L"filter.rootAssetIds[1].id",123);
CkJsonObjectW_UpdateString(json,L"filter.assetSubtreeIds[0].externalId",L"laborum");
CkJsonObjectW_UpdateString(json,L"filter.assetSubtreeIds[1].externalId",L"velit Duis");
CkJsonObjectW_UpdateString(json,L"filter.dataSetIds[0].externalId",L"ad");
CkJsonObjectW_UpdateString(json,L"filter.dataSetIds[1].externalId",L"culpa");
CkJsonObjectW_UpdateString(json,L"filter.source",L"deserunt ut mollit anim l");
CkJsonObjectW_UpdateString(json,L"filter.type",L"sed nisi exercita");
CkJsonObjectW_UpdateString(json,L"filter.subtype",L"aliqua Ut");
CkJsonObjectW_UpdateInt(json,L"filter.createdTime.max",39562876);
CkJsonObjectW_UpdateInt(json,L"filter.createdTime.min",1881975);
CkJsonObjectW_UpdateInt(json,L"filter.lastUpdatedTime.max",69566439);
CkJsonObjectW_UpdateInt(json,L"filter.lastUpdatedTime.min",58702695);
CkJsonObjectW_UpdateString(json,L"filter.externalIdPrefix",L"in Excepteur");
CkJsonObjectW_UpdateString(json,L"search.description",L"proident ut");
CkJsonObjectW_UpdateInt(json,L"limit",100);
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/search",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 '{
"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}"
}
}
}