Chilkat Online Tools

Swift / Cognite API v1 / Filter relationships

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": {
    //     "sourceExternalIds": [
    //       "culpa esse veniam nisi",
    //       "commodo repr"
    //     ],
    //     "sourceTypes": [
    //       "timeSeries",
    //       "sequence"
    //     ],
    //     "targetExternalIds": [
    //       "exercitation",
    //       "enim culpa"
    //     ],
    //     "targetTypes": [
    //       "sequence",
    //       "timeSeries"
    //     ],
    //     "dataSetIds": [
    //       {
    //         "id": 6853944784929184
    //       },
    //       {
    //         "externalId": "aliquip non"
    //       }
    //     ],
    //     "startTime": {
    //       "max": 15446345,
    //       "min": 52529591
    //     },
    //     "endTime": {
    //       "max": 94684273,
    //       "min": 31959617
    //     },
    //     "confidence": {
    //       "min": 62943472.11126715,
    //       "max": 33071678.92549883
    //     },
    //     "lastUpdatedTime": {
    //       "max": 64148230,
    //       "min": 15602664
    //     },
    //     "createdTime": {
    //       "max": 99622074,
    //       "min": 32696551
    //     },
    //     "activeAtTime": {
    //       "max": 99890540,
    //       "min": 14084932
    //     },
    //     "labels": {
    //       "containsAny": [
    //         {
    //           "externalId": "et Lorem cupidatat amet"
    //         },
    //         {
    //           "externalId": "aliqua"
    //         }
    //       ]
    //     },
    //     "sourcesOrTargets": [
    //       {
    //         "type": "sequence",
    //         "externalId": "consequat id"
    //       }
    //     ]
    //   },
    //   "limit": 100,
    //   "cursor": "non do Excepteur dolor",
    //   "fetchResources": false,
    //   "partition": "laborum id ad cupidatat et"
    // }

    let json = CkoJsonObject()
    json.UpdateString("filter.sourceExternalIds[0]", value: "culpa esse veniam nisi")
    json.UpdateString("filter.sourceExternalIds[1]", value: "commodo repr")
    json.UpdateString("filter.sourceTypes[0]", value: "timeSeries")
    json.UpdateString("filter.sourceTypes[1]", value: "sequence")
    json.UpdateString("filter.targetExternalIds[0]", value: "exercitation")
    json.UpdateString("filter.targetExternalIds[1]", value: "enim culpa")
    json.UpdateString("filter.targetTypes[0]", value: "sequence")
    json.UpdateString("filter.targetTypes[1]", value: "timeSeries")
    json.UpdateInt("filter.dataSetIds[0].id", value: 123)
    json.UpdateString("filter.dataSetIds[1].externalId", value: "aliquip non")
    json.UpdateInt("filter.startTime.max", value: 15446345)
    json.UpdateInt("filter.startTime.min", value: 52529591)
    json.UpdateInt("filter.endTime.max", value: 94684273)
    json.UpdateInt("filter.endTime.min", value: 31959617)
    json.UpdateNumber("filter.confidence.min", numericStr: "62943472.11126715")
    json.UpdateNumber("filter.confidence.max", numericStr: "33071678.92549883")
    json.UpdateInt("filter.lastUpdatedTime.max", value: 64148230)
    json.UpdateInt("filter.lastUpdatedTime.min", value: 15602664)
    json.UpdateInt("filter.createdTime.max", value: 99622074)
    json.UpdateInt("filter.createdTime.min", value: 32696551)
    json.UpdateInt("filter.activeAtTime.max", value: 99890540)
    json.UpdateInt("filter.activeAtTime.min", value: 14084932)
    json.UpdateString("filter.labels.containsAny[0].externalId", value: "et Lorem cupidatat amet")
    json.UpdateString("filter.labels.containsAny[1].externalId", value: "aliqua")
    json.UpdateString("filter.sourcesOrTargets[0].type", value: "sequence")
    json.UpdateString("filter.sourcesOrTargets[0].externalId", value: "consequat id")
    json.UpdateInt("limit", value: 100)
    json.UpdateString("cursor", value: "non do Excepteur dolor")
    json.UpdateBool("fetchResources", value: false)
    json.UpdateString("partition", value: "laborum id ad cupidatat et")

    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}}/relationships/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": {
        "sourceExternalIds": [
            "culpa esse veniam nisi",
            "commodo repr"
        ],
        "sourceTypes": [
            "timeSeries",
            "sequence"
        ],
        "targetExternalIds": [
            "exercitation",
            "enim culpa"
        ],
        "targetTypes": [
            "sequence",
            "timeSeries"
        ],
        "dataSetIds": [
            {
                "id": 6853944784929184
            },
            {
                "externalId": "aliquip non"
            }
        ],
        "startTime": {
            "max": 15446345,
            "min": 52529591
        },
        "endTime": {
            "max": 94684273,
            "min": 31959617
        },
        "confidence": {
            "min": 62943472.11126715,
            "max": 33071678.92549883
        },
        "lastUpdatedTime": {
            "max": 64148230,
            "min": 15602664
        },
        "createdTime": {
            "max": 99622074,
            "min": 32696551
        },
        "activeAtTime": {
            "max": 99890540,
            "min": 14084932
        },
        "labels": {
            "containsAny": [
                {
                    "externalId": "et Lorem cupidatat amet"
                },
                {
                    "externalId": "aliqua"
                }
            ]
        },
        "sourcesOrTargets": [
            {
                "type": "sequence",
                "externalId": "consequat id"
            }
        ]
    },
    "limit": 100,
    "cursor": "non do Excepteur dolor",
    "fetchResources": false,
    "partition": "laborum id ad cupidatat et"
}'
https://domain.com/api/v1/projects/{{project}}/relationships/list

Postman Collection Item JSON

{
  "id": "listRelationships",
  "name": "Filter relationships",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "relationships",
        "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": "Lists relationships matching the query filter in the request. You can retrieve a maximum of 1000 relationships per request.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"sourceExternalIds\": [\n            \"culpa esse veniam nisi\",\n            \"commodo repr\"\n        ],\n        \"sourceTypes\": [\n            \"timeSeries\",\n            \"sequence\"\n        ],\n        \"targetExternalIds\": [\n            \"exercitation\",\n            \"enim culpa\"\n        ],\n        \"targetTypes\": [\n            \"sequence\",\n            \"timeSeries\"\n        ],\n        \"dataSetIds\": [\n            {\n                \"id\": 6853944784929184\n            },\n            {\n                \"externalId\": \"aliquip non\"\n            }\n        ],\n        \"startTime\": {\n            \"max\": 15446345,\n            \"min\": 52529591\n        },\n        \"endTime\": {\n            \"max\": 94684273,\n            \"min\": 31959617\n        },\n        \"confidence\": {\n            \"min\": 62943472.11126715,\n            \"max\": 33071678.92549883\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 64148230,\n            \"min\": 15602664\n        },\n        \"createdTime\": {\n            \"max\": 99622074,\n            \"min\": 32696551\n        },\n        \"activeAtTime\": {\n            \"max\": 99890540,\n            \"min\": 14084932\n        },\n        \"labels\": {\n            \"containsAny\": [\n                {\n                    \"externalId\": \"et Lorem cupidatat amet\"\n                },\n                {\n                    \"externalId\": \"aliqua\"\n                }\n            ]\n        },\n        \"sourcesOrTargets\": [\n            {\n                \"type\": \"sequence\",\n                \"externalId\": \"consequat id\"\n            }\n        ]\n    },\n    \"limit\": 100,\n    \"cursor\": \"non do Excepteur dolor\",\n    \"fetchResources\": false,\n    \"partition\": \"laborum id ad cupidatat et\"\n}"
    }
  }
}