Chilkat Online Tools

Swift / Cognite API v1 / Search within 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": 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
    // }

    let json = CkoJsonObject()
    json.UpdateInt("filter.startTime.max", value: 28954538)
    json.UpdateInt("filter.startTime.min", value: 46490486)
    json.UpdateBool("filter.endTime.isNull", value: false)
    json.UpdateInt("filter.activeAtTime.max", value: 27359549)
    json.UpdateInt("filter.activeAtTime.min", value: 32947272)
    json.UpdateNewObject("filter.metadata")
    json.UpdateInt("filter.assetIds[0]", value: 4883269954114660)
    json.UpdateInt("filter.assetIds[1]", value: 2578912121595962)
    json.UpdateString("filter.assetExternalIds[0]", value: "exercitation dolor do")
    json.UpdateString("filter.assetExternalIds[1]", value: "occaecat")
    json.UpdateInt("filter.rootAssetIds[0].id", value: 123)
    json.UpdateInt("filter.rootAssetIds[1].id", value: 123)
    json.UpdateString("filter.assetSubtreeIds[0].externalId", value: "laborum")
    json.UpdateString("filter.assetSubtreeIds[1].externalId", value: "velit Duis")
    json.UpdateString("filter.dataSetIds[0].externalId", value: "ad")
    json.UpdateString("filter.dataSetIds[1].externalId", value: "culpa")
    json.UpdateString("filter.source", value: "deserunt ut mollit anim l")
    json.UpdateString("filter.type", value: "sed nisi exercita")
    json.UpdateString("filter.subtype", value: "aliqua Ut")
    json.UpdateInt("filter.createdTime.max", value: 39562876)
    json.UpdateInt("filter.createdTime.min", value: 1881975)
    json.UpdateInt("filter.lastUpdatedTime.max", value: 69566439)
    json.UpdateInt("filter.lastUpdatedTime.min", value: 58702695)
    json.UpdateString("filter.externalIdPrefix", value: "in Excepteur")
    json.UpdateString("search.description", value: "proident ut")
    json.UpdateInt("limit", value: 100)

    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/search", 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": 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}"
    }
  }
}