Chilkat Online Tools

Swift3 / Cognite API v1 / Aggregate time series

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    // 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": "et exercitation s",
    //     "unit": "pariatur esse qui",
    //     "isString": true,
    //     "isStep": false,
    //     "metadata": {},
    //     "assetIds": [
    //       2274246036570026,
    //       8922483798410046
    //     ],
    //     "assetExternalIds": [
    //       "proident Ut consequat in",
    //       "elit incididunt aliqua"
    //     ],
    //     "rootAssetIds": [
    //       7714215516056826,
    //       4275780546438472
    //     ],
    //     "assetSubtreeIds": [
    //       {
    //         "id": 7555548287718054
    //       },
    //       {
    //         "externalId": "re"
    //       }
    //     ],
    //     "dataSetIds": [
    //       {
    //         "id": 5946532482497628
    //       },
    //       {
    //         "externalId": "exercitation nisi elit"
    //       }
    //     ],
    //     "externalIdPrefix": "aute Ut nostrud commodo in",
    //     "createdTime": {
    //       "max": 16041500,
    //       "min": 71538919
    //     },
    //     "lastUpdatedTime": {
    //       "max": 2438620,
    //       "min": 18087967
    //     }
    //   }
    // }

    let json = CkoJsonObject()!
    json.update("filter.name", value: "et exercitation s")
    json.update("filter.unit", value: "pariatur esse qui")
    json.updateBool("filter.isString", value: true)
    json.updateBool("filter.isStep", value: false)
    json.updateNewObject("filter.metadata")
    json.updateInt("filter.assetIds[0]", value: 2274246036570026)
    json.updateInt("filter.assetIds[1]", value: 8922483798410046)
    json.update("filter.assetExternalIds[0]", value: "proident Ut consequat in")
    json.update("filter.assetExternalIds[1]", value: "elit incididunt aliqua")
    json.updateInt("filter.rootAssetIds[0]", value: 7714215516056826)
    json.updateInt("filter.rootAssetIds[1]", value: 4275780546438472)
    json.updateInt("filter.assetSubtreeIds[0].id", value: 123)
    json.update("filter.assetSubtreeIds[1].externalId", value: "re")
    json.updateInt("filter.dataSetIds[0].id", value: 123)
    json.update("filter.dataSetIds[1].externalId", value: "exercitation nisi elit")
    json.update("filter.externalIdPrefix", value: "aute Ut nostrud commodo in")
    json.updateInt("filter.createdTime.max", value: 16041500)
    json.updateInt("filter.createdTime.min", value: 71538919)
    json.updateInt("filter.lastUpdatedTime.max", value: 2438620)
    json.updateInt("filter.lastUpdatedTime.min", value: 18087967)

    http.setRequestHeader("content-type", value: "application/json")
    http.setRequestHeader("api-key", value: "{{api-key}}")

    var resp: CkoHttpResponse? = http.postJson3("https://domain.com/api/v1/projects/{{project}}/timeseries/aggregate", contentType: "application/json", json: json)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "filter": {
        "name": "et exercitation s",
        "unit": "pariatur esse qui",
        "isString": true,
        "isStep": false,
        "metadata": {},
        "assetIds": [
            2274246036570026,
            8922483798410046
        ],
        "assetExternalIds": [
            "proident Ut consequat in",
            "elit incididunt aliqua"
        ],
        "rootAssetIds": [
            7714215516056826,
            4275780546438472
        ],
        "assetSubtreeIds": [
            {
                "id": 7555548287718054
            },
            {
                "externalId": "re"
            }
        ],
        "dataSetIds": [
            {
                "id": 5946532482497628
            },
            {
                "externalId": "exercitation nisi elit"
            }
        ],
        "externalIdPrefix": "aute Ut nostrud commodo in",
        "createdTime": {
            "max": 16041500,
            "min": 71538919
        },
        "lastUpdatedTime": {
            "max": 2438620,
            "min": 18087967
        }
    }
}'
https://domain.com/api/v1/projects/{{project}}/timeseries/aggregate

Postman Collection Item JSON

{
  "id": "aggregateTimeSeries",
  "name": "Aggregate time series",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "timeseries",
        "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": "Count the number of time series that match the given filter",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"et exercitation s\",\n        \"unit\": \"pariatur esse qui\",\n        \"isString\": true,\n        \"isStep\": false,\n        \"metadata\": {},\n        \"assetIds\": [\n            2274246036570026,\n            8922483798410046\n        ],\n        \"assetExternalIds\": [\n            \"proident Ut consequat in\",\n            \"elit incididunt aliqua\"\n        ],\n        \"rootAssetIds\": [\n            7714215516056826,\n            4275780546438472\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 7555548287718054\n            },\n            {\n                \"externalId\": \"re\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"id\": 5946532482497628\n            },\n            {\n                \"externalId\": \"exercitation nisi elit\"\n            }\n        ],\n        \"externalIdPrefix\": \"aute Ut nostrud commodo in\",\n        \"createdTime\": {\n            \"max\": 16041500,\n            \"min\": 71538919\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 2438620,\n            \"min\": 18087967\n        }\n    }\n}"
    }
  }
}