Chilkat Online Tools

unicodeC / Cognite API v1 / Aggregate assets

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": {
    //     "name": "tempor in",
    //     "parentIds": [
    //       2218036985580300,
    //       1325609532768832
    //     ],
    //     "parentExternalIds": [
    //       "proident magna occaecat id",
    //       "elit sint in"
    //     ],
    //     "rootIds": [
    //       {
    //         "id": 2434556236080026
    //       },
    //       {
    //         "id": 3030224117188012
    //       }
    //     ],
    //     "assetSubtreeIds": [
    //       {
    //         "id": 5500566008705236
    //       },
    //       {
    //         "externalId": "magna pariatur ullamco aute"
    //       }
    //     ],
    //     "dataSetIds": [
    //       {
    //         "externalId": "magna mollit eiusmod"
    //       },
    //       {
    //         "externalId": "nulla tempor consectetur occaecat sit"
    //       }
    //     ],
    //     "metadata": {},
    //     "source": "quis",
    //     "createdTime": {
    //       "max": 51644802,
    //       "min": 78848688
    //     },
    //     "lastUpdatedTime": {
    //       "max": 42756152,
    //       "min": 67449504
    //     },
    //     "root": false,
    //     "externalIdPrefix": "aute officia sint nisi",
    //     "labels": {
    //       "containsAny": [
    //         {
    //           "externalId": "quis"
    //         },
    //         {
    //           "externalId": "ex tempor"
    //         }
    //       ]
    //     }
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"filter.name",L"tempor in");
    CkJsonObjectW_UpdateInt(json,L"filter.parentIds[0]",2218036985580300);
    CkJsonObjectW_UpdateInt(json,L"filter.parentIds[1]",1325609532768832);
    CkJsonObjectW_UpdateString(json,L"filter.parentExternalIds[0]",L"proident magna occaecat id");
    CkJsonObjectW_UpdateString(json,L"filter.parentExternalIds[1]",L"elit sint in");
    CkJsonObjectW_UpdateInt(json,L"filter.rootIds[0].id",123);
    CkJsonObjectW_UpdateInt(json,L"filter.rootIds[1].id",123);
    CkJsonObjectW_UpdateInt(json,L"filter.assetSubtreeIds[0].id",123);
    CkJsonObjectW_UpdateString(json,L"filter.assetSubtreeIds[1].externalId",L"magna pariatur ullamco aute");
    CkJsonObjectW_UpdateString(json,L"filter.dataSetIds[0].externalId",L"magna mollit eiusmod");
    CkJsonObjectW_UpdateString(json,L"filter.dataSetIds[1].externalId",L"nulla tempor consectetur occaecat sit");
    CkJsonObjectW_UpdateNewObject(json,L"filter.metadata");
    CkJsonObjectW_UpdateString(json,L"filter.source",L"quis");
    CkJsonObjectW_UpdateInt(json,L"filter.createdTime.max",51644802);
    CkJsonObjectW_UpdateInt(json,L"filter.createdTime.min",78848688);
    CkJsonObjectW_UpdateInt(json,L"filter.lastUpdatedTime.max",42756152);
    CkJsonObjectW_UpdateInt(json,L"filter.lastUpdatedTime.min",67449504);
    CkJsonObjectW_UpdateBool(json,L"filter.root",FALSE);
    CkJsonObjectW_UpdateString(json,L"filter.externalIdPrefix",L"aute officia sint nisi");
    CkJsonObjectW_UpdateString(json,L"filter.labels.containsAny[0].externalId",L"quis");
    CkJsonObjectW_UpdateString(json,L"filter.labels.containsAny[1].externalId",L"ex tempor");

    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}}/assets/aggregate",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": {
        "name": "tempor in",
        "parentIds": [
            2218036985580300,
            1325609532768832
        ],
        "parentExternalIds": [
            "proident magna occaecat id",
            "elit sint in"
        ],
        "rootIds": [
            {
                "id": 2434556236080026
            },
            {
                "id": 3030224117188012
            }
        ],
        "assetSubtreeIds": [
            {
                "id": 5500566008705236
            },
            {
                "externalId": "magna pariatur ullamco aute"
            }
        ],
        "dataSetIds": [
            {
                "externalId": "magna mollit eiusmod"
            },
            {
                "externalId": "nulla tempor consectetur occaecat sit"
            }
        ],
        "metadata": {},
        "source": "quis",
        "createdTime": {
            "max": 51644802,
            "min": 78848688
        },
        "lastUpdatedTime": {
            "max": 42756152,
            "min": 67449504
        },
        "root": false,
        "externalIdPrefix": "aute officia sint nisi",
        "labels": {
            "containsAny": [
                {
                    "externalId": "quis"
                },
                {
                    "externalId": "ex tempor"
                }
            ]
        }
    }
}'
https://domain.com/api/v1/projects/{{project}}/assets/aggregate

Postman Collection Item JSON

{
  "id": "aggregateAssets",
  "name": "Aggregate assets",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "assets",
        "aggregate"
      ],
      "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": "Use advanced filtering options to agggregate assets.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"tempor in\",\n        \"parentIds\": [\n            2218036985580300,\n            1325609532768832\n        ],\n        \"parentExternalIds\": [\n            \"proident magna occaecat id\",\n            \"elit sint in\"\n        ],\n        \"rootIds\": [\n            {\n                \"id\": 2434556236080026\n            },\n            {\n                \"id\": 3030224117188012\n            }\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 5500566008705236\n            },\n            {\n                \"externalId\": \"magna pariatur ullamco aute\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"magna mollit eiusmod\"\n            },\n            {\n                \"externalId\": \"nulla tempor consectetur occaecat sit\"\n            }\n        ],\n        \"metadata\": {},\n        \"source\": \"quis\",\n        \"createdTime\": {\n            \"max\": 51644802,\n            \"min\": 78848688\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 42756152,\n            \"min\": 67449504\n        },\n        \"root\": false,\n        \"externalIdPrefix\": \"aute officia sint nisi\",\n        \"labels\": {\n            \"containsAny\": [\n                {\n                    \"externalId\": \"quis\"\n                },\n                {\n                    \"externalId\": \"ex tempor\"\n                }\n            ]\n        }\n    }\n}"
    }
  }
}