Chilkat Online Tools

Objective-C / Cognite API v1 / Filter files

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// 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": "ex nostrud consectetur",
//     "directoryPrefix": "tempor laborum ad consectetur",
//     "mimeType": "aute dolor sit Duis",
//     "metadata": {},
//     "assetIds": [
//       467579989120294,
//       8421974867540202
//     ],
//     "assetExternalIds": [
//       "",
//       "sint minim aliqua "
//     ],
//     "rootAssetIds": [
//       {
//         "id": 1543391847125216
//       },
//       {
//         "id": 6483833221883084
//       }
//     ],
//     "dataSetIds": [
//       {
//         "externalId": "eu aliqua dolor ea"
//       },
//       {
//         "id": 954668826986822
//       }
//     ],
//     "assetSubtreeIds": [
//       {
//         "externalId": "nisi occaecat sunt enim Ut"
//       },
//       {
//         "externalId": "anim reprehenderit ex nostrud"
//       }
//     ],
//     "source": "nulla mollit exercita",
//     "createdTime": {
//       "max": 35775661,
//       "min": 68358871
//     },
//     "lastUpdatedTime": {
//       "max": 39458190,
//       "min": 53247476
//     },
//     "uploadedTime": {
//       "max": 20009824,
//       "min": 24281615
//     },
//     "sourceCreatedTime": {
//       "max": 94237198,
//       "min": 59856114
//     },
//     "sourceModifiedTime": {
//       "max": 74319204,
//       "min": 63072110
//     },
//     "externalIdPrefix": "et",
//     "uploaded": false,
//     "labels": {
//       "containsAll": [
//         {
//           "externalId": "Ut ipsum in"
//         },
//         {
//           "externalId": "amet reprehenderit velit"
//         }
//       ]
//     },
//     "geoLocation": {
//       "relation": "WITHIN",
//       "shape": {
//         "type": "LineString",
//         "coordinates": [
//         ]
//       }
//     }
//   },
//   "partition": "proident est Duis nisi et",
//   "limit": 100,
//   "cursor": "incididunt"
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"filter.name" value: @"ex nostrud consectetur"];
[json UpdateString: @"filter.directoryPrefix" value: @"tempor laborum ad consectetur"];
[json UpdateString: @"filter.mimeType" value: @"aute dolor sit Duis"];
[json UpdateNewObject: @"filter.metadata"];
[json UpdateInt: @"filter.assetIds[0]" value: [NSNumber numberWithInt: 467579989120294]];
[json UpdateInt: @"filter.assetIds[1]" value: [NSNumber numberWithInt: 8421974867540202]];
[json UpdateString: @"filter.assetExternalIds[0]" value: @""];
[json UpdateString: @"filter.assetExternalIds[1]" value: @"sint minim aliqua "];
[json UpdateInt: @"filter.rootAssetIds[0].id" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"filter.rootAssetIds[1].id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"filter.dataSetIds[0].externalId" value: @"eu aliqua dolor ea"];
[json UpdateInt: @"filter.dataSetIds[1].id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"filter.assetSubtreeIds[0].externalId" value: @"nisi occaecat sunt enim Ut"];
[json UpdateString: @"filter.assetSubtreeIds[1].externalId" value: @"anim reprehenderit ex nostrud"];
[json UpdateString: @"filter.source" value: @"nulla mollit exercita"];
[json UpdateInt: @"filter.createdTime.max" value: [NSNumber numberWithInt: 35775661]];
[json UpdateInt: @"filter.createdTime.min" value: [NSNumber numberWithInt: 68358871]];
[json UpdateInt: @"filter.lastUpdatedTime.max" value: [NSNumber numberWithInt: 39458190]];
[json UpdateInt: @"filter.lastUpdatedTime.min" value: [NSNumber numberWithInt: 53247476]];
[json UpdateInt: @"filter.uploadedTime.max" value: [NSNumber numberWithInt: 20009824]];
[json UpdateInt: @"filter.uploadedTime.min" value: [NSNumber numberWithInt: 24281615]];
[json UpdateInt: @"filter.sourceCreatedTime.max" value: [NSNumber numberWithInt: 94237198]];
[json UpdateInt: @"filter.sourceCreatedTime.min" value: [NSNumber numberWithInt: 59856114]];
[json UpdateInt: @"filter.sourceModifiedTime.max" value: [NSNumber numberWithInt: 74319204]];
[json UpdateInt: @"filter.sourceModifiedTime.min" value: [NSNumber numberWithInt: 63072110]];
[json UpdateString: @"filter.externalIdPrefix" value: @"et"];
[json UpdateBool: @"filter.uploaded" value: NO];
[json UpdateString: @"filter.labels.containsAll[0].externalId" value: @"Ut ipsum in"];
[json UpdateString: @"filter.labels.containsAll[1].externalId" value: @"amet reprehenderit velit"];
[json UpdateString: @"filter.geoLocation.relation" value: @"WITHIN"];
[json UpdateString: @"filter.geoLocation.shape.type" value: @"LineString"];
[json UpdateNewArray: @"filter.geoLocation.shape.coordinates"];
[json UpdateString: @"partition" value: @"proident est Duis nisi et"];
[json UpdateInt: @"limit" value: [NSNumber numberWithInt: 100]];
[json UpdateString: @"cursor" value: @"incididunt"];

[http SetRequestHeader: @"content-type" value: @"application/json"];
[http SetRequestHeader: @"api-key" value: @"{{api-key}}"];

CkoHttpResponse *resp = [http PostJson3: @"https://domain.com/api/v1/projects/{{project}}/files/list" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "filter": {
        "name": "ex nostrud consectetur",
        "directoryPrefix": "tempor laborum ad consectetur",
        "mimeType": "aute dolor sit Duis",
        "metadata": {},
        "assetIds": [
            467579989120294,
            8421974867540202
        ],
        "assetExternalIds": [
            "",
            "sint minim aliqua "
        ],
        "rootAssetIds": [
            {
                "id": 1543391847125216
            },
            {
                "id": 6483833221883084
            }
        ],
        "dataSetIds": [
            {
                "externalId": "eu aliqua dolor ea"
            },
            {
                "id": 954668826986822
            }
        ],
        "assetSubtreeIds": [
            {
                "externalId": "nisi occaecat sunt enim Ut"
            },
            {
                "externalId": "anim reprehenderit ex nostrud"
            }
        ],
        "source": "nulla mollit exercita",
        "createdTime": {
            "max": 35775661,
            "min": 68358871
        },
        "lastUpdatedTime": {
            "max": 39458190,
            "min": 53247476
        },
        "uploadedTime": {
            "max": 20009824,
            "min": 24281615
        },
        "sourceCreatedTime": {
            "max": 94237198,
            "min": 59856114
        },
        "sourceModifiedTime": {
            "max": 74319204,
            "min": 63072110
        },
        "externalIdPrefix": "et",
        "uploaded": false,
        "labels": {
            "containsAll": [
                {
                    "externalId": "Ut ipsum in"
                },
                {
                    "externalId": "amet reprehenderit velit"
                }
            ]
        },
        "geoLocation": {
            "relation": "WITHIN",
            "shape": {
                "type": "LineString",
                "coordinates": []
            }
        }
    },
    "partition": "proident est Duis nisi et",
    "limit": 100,
    "cursor": "incididunt"
}'
https://domain.com/api/v1/projects/{{project}}/files/list

Postman Collection Item JSON

{
  "id": "advancedListFiles",
  "name": "Filter files",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "files",
        "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": "Retrieves a list of all files in a project. Criteria can be supplied to select a subset of files. This operation supports pagination with cursors.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"ex nostrud consectetur\",\n        \"directoryPrefix\": \"tempor laborum ad consectetur\",\n        \"mimeType\": \"aute dolor sit Duis\",\n        \"metadata\": {},\n        \"assetIds\": [\n            467579989120294,\n            8421974867540202\n        ],\n        \"assetExternalIds\": [\n            \"\",\n            \"sint minim aliqua \"\n        ],\n        \"rootAssetIds\": [\n            {\n                \"id\": 1543391847125216\n            },\n            {\n                \"id\": 6483833221883084\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"eu aliqua dolor ea\"\n            },\n            {\n                \"id\": 954668826986822\n            }\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"externalId\": \"nisi occaecat sunt enim Ut\"\n            },\n            {\n                \"externalId\": \"anim reprehenderit ex nostrud\"\n            }\n        ],\n        \"source\": \"nulla mollit exercita\",\n        \"createdTime\": {\n            \"max\": 35775661,\n            \"min\": 68358871\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 39458190,\n            \"min\": 53247476\n        },\n        \"uploadedTime\": {\n            \"max\": 20009824,\n            \"min\": 24281615\n        },\n        \"sourceCreatedTime\": {\n            \"max\": 94237198,\n            \"min\": 59856114\n        },\n        \"sourceModifiedTime\": {\n            \"max\": 74319204,\n            \"min\": 63072110\n        },\n        \"externalIdPrefix\": \"et\",\n        \"uploaded\": false,\n        \"labels\": {\n            \"containsAll\": [\n                {\n                    \"externalId\": \"Ut ipsum in\"\n                },\n                {\n                    \"externalId\": \"amet reprehenderit velit\"\n                }\n            ]\n        },\n        \"geoLocation\": {\n            \"relation\": \"WITHIN\",\n            \"shape\": {\n                \"type\": \"LineString\",\n                \"coordinates\": []\n            }\n        }\n    },\n    \"partition\": \"proident est Duis nisi et\",\n    \"limit\": 100,\n    \"cursor\": \"incididunt\"\n}"
    }
  }
}