Chilkat Online Tools

Swift / Cognite API v1 / Filter all events

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": {
    //     "startTime": {
    //       "max": 96423541,
    //       "min": 708508
    //     },
    //     "endTime": {
    //       "isNull": false
    //     },
    //     "activeAtTime": {
    //       "max": 42601793,
    //       "min": 6545191
    //     },
    //     "metadata": {},
    //     "assetIds": [
    //       5846331094676668,
    //       3408965310215146
    //     ],
    //     "assetExternalIds": [
    //       "deserunt aliquip Ut occaecat in",
    //       "non o"
    //     ],
    //     "rootAssetIds": [
    //       {
    //         "externalId": "veniam commodo minim Duis ut"
    //       },
    //       {
    //         "id": 2472341704760768
    //       }
    //     ],
    //     "assetSubtreeIds": [
    //       {
    //         "id": 6194248735806298
    //       },
    //       {
    //         "externalId": "adipisicing"
    //       }
    //     ],
    //     "dataSetIds": [
    //       {
    //         "externalId": "commodo nisi"
    //       },
    //       {
    //         "id": 4778982098206896
    //       }
    //     ],
    //     "source": "incididunt",
    //     "type": "in occaecat",
    //     "subtype": "dolore minim ipsum",
    //     "createdTime": {
    //       "max": 75538890,
    //       "min": 51111895
    //     },
    //     "lastUpdatedTime": {
    //       "max": 31243942,
    //       "min": 56817666
    //     },
    //     "externalIdPrefix": "cillum"
    //   },
    //   "limit": 100,
    //   "sort": [
    //   ],
    //   "cursor": "laborum officia ullamco e",
    //   "partition": "elit velit"
    // }

    let json = CkoJsonObject()
    json.UpdateInt("filter.startTime.max", value: 96423541)
    json.UpdateInt("filter.startTime.min", value: 708508)
    json.UpdateBool("filter.endTime.isNull", value: false)
    json.UpdateInt("filter.activeAtTime.max", value: 42601793)
    json.UpdateInt("filter.activeAtTime.min", value: 6545191)
    json.UpdateNewObject("filter.metadata")
    json.UpdateInt("filter.assetIds[0]", value: 5846331094676668)
    json.UpdateInt("filter.assetIds[1]", value: 3408965310215146)
    json.UpdateString("filter.assetExternalIds[0]", value: "deserunt aliquip Ut occaecat in")
    json.UpdateString("filter.assetExternalIds[1]", value: "non o")
    json.UpdateString("filter.rootAssetIds[0].externalId", value: "veniam commodo minim Duis ut")
    json.UpdateInt("filter.rootAssetIds[1].id", value: 123)
    json.UpdateInt("filter.assetSubtreeIds[0].id", value: 123)
    json.UpdateString("filter.assetSubtreeIds[1].externalId", value: "adipisicing")
    json.UpdateString("filter.dataSetIds[0].externalId", value: "commodo nisi")
    json.UpdateInt("filter.dataSetIds[1].id", value: 123)
    json.UpdateString("filter.source", value: "incididunt")
    json.UpdateString("filter.type", value: "in occaecat")
    json.UpdateString("filter.subtype", value: "dolore minim ipsum")
    json.UpdateInt("filter.createdTime.max", value: 75538890)
    json.UpdateInt("filter.createdTime.min", value: 51111895)
    json.UpdateInt("filter.lastUpdatedTime.max", value: 31243942)
    json.UpdateInt("filter.lastUpdatedTime.min", value: 56817666)
    json.UpdateString("filter.externalIdPrefix", value: "cillum")
    json.UpdateInt("limit", value: 100)
    json.UpdateNewArray("sort")
    json.UpdateString("cursor", value: "laborum officia ullamco e")
    json.UpdateString("partition", value: "elit velit")

    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}}/events/list", 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": {
        "startTime": {
            "max": 96423541,
            "min": 708508
        },
        "endTime": {
            "isNull": false
        },
        "activeAtTime": {
            "max": 42601793,
            "min": 6545191
        },
        "metadata": {},
        "assetIds": [
            5846331094676668,
            3408965310215146
        ],
        "assetExternalIds": [
            "deserunt aliquip Ut occaecat in",
            "non o"
        ],
        "rootAssetIds": [
            {
                "externalId": "veniam commodo minim Duis ut"
            },
            {
                "id": 2472341704760768
            }
        ],
        "assetSubtreeIds": [
            {
                "id": 6194248735806298
            },
            {
                "externalId": "adipisicing"
            }
        ],
        "dataSetIds": [
            {
                "externalId": "commodo nisi"
            },
            {
                "id": 4778982098206896
            }
        ],
        "source": "incididunt",
        "type": "in occaecat",
        "subtype": "dolore minim ipsum",
        "createdTime": {
            "max": 75538890,
            "min": 51111895
        },
        "lastUpdatedTime": {
            "max": 31243942,
            "min": 56817666
        },
        "externalIdPrefix": "cillum"
    },
    "limit": 100,
    "sort": [],
    "cursor": "laborum officia ullamco e",
    "partition": "elit velit"
}'
https://domain.com/api/v1/projects/{{project}}/events/list

Postman Collection Item JSON

{
  "id": "advancedListEvents",
  "name": "Filter all events",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "events",
        "list"
      ],
      "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": "Retrieve a list of all events in the same project. This operation supports pagination by cursor. Criteria can be applied to select a subset of events.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"startTime\": {\n            \"max\": 96423541,\n            \"min\": 708508\n        },\n        \"endTime\": {\n            \"isNull\": false\n        },\n        \"activeAtTime\": {\n            \"max\": 42601793,\n            \"min\": 6545191\n        },\n        \"metadata\": {},\n        \"assetIds\": [\n            5846331094676668,\n            3408965310215146\n        ],\n        \"assetExternalIds\": [\n            \"deserunt aliquip Ut occaecat in\",\n            \"non o\"\n        ],\n        \"rootAssetIds\": [\n            {\n                \"externalId\": \"veniam commodo minim Duis ut\"\n            },\n            {\n                \"id\": 2472341704760768\n            }\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 6194248735806298\n            },\n            {\n                \"externalId\": \"adipisicing\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"commodo nisi\"\n            },\n            {\n                \"id\": 4778982098206896\n            }\n        ],\n        \"source\": \"incididunt\",\n        \"type\": \"in occaecat\",\n        \"subtype\": \"dolore minim ipsum\",\n        \"createdTime\": {\n            \"max\": 75538890,\n            \"min\": 51111895\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 31243942,\n            \"min\": 56817666\n        },\n        \"externalIdPrefix\": \"cillum\"\n    },\n    \"limit\": 100,\n    \"sort\": [],\n    \"cursor\": \"laborum officia ullamco e\",\n    \"partition\": \"elit velit\"\n}"
    }
  }
}