Objective-C / Cognite API v1 / Search 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": "labore",
// "directoryPrefix": "non",
// "mimeType": "amet",
// "metadata": {},
// "assetIds": [
// 2806482587450292,
// 5885270784918610
// ],
// "assetExternalIds": [
// "cillum quis laborum eu in",
// "pariatur aute incididunt minim nulla"
// ],
// "rootAssetIds": [
// {
// "id": 3434712602792354
// },
// {
// "externalId": "dolor nostrud sint tempor"
// }
// ],
// "dataSetIds": [
// {
// "id": 6643919081009120
// },
// {
// "externalId": "incidid"
// }
// ],
// "assetSubtreeIds": [
// {
// "id": 1381446255269154
// },
// {
// "id": 6877534894841850
// }
// ],
// "source": "in ullamco in qu",
// "createdTime": {
// "max": 52776204,
// "min": 19590899
// },
// "lastUpdatedTime": {
// "max": 2447871,
// "min": 62024320
// },
// "uploadedTime": {
// "max": 88446108,
// "min": 12715733
// },
// "sourceCreatedTime": {
// "max": 6470658,
// "min": 75552038
// },
// "sourceModifiedTime": {
// "max": 56421116,
// "min": 98065077
// },
// "externalIdPrefix": "incididunt occaecat eiusmod ut",
// "uploaded": true,
// "labels": {
// "containsAll": [
// {
// "externalId": "pariatur"
// },
// {
// "externalId": "adipisicing occaecat"
// }
// ]
// },
// "geoLocation": {
// "relation": "INTERSECTS",
// "shape": {
// "type": "Point",
// "coordinates": [
// -28013106.93372789,
// 67047806.90769461
// ]
// }
// }
// },
// "search": {
// "name": "qui"
// }
// }
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"filter.name" value: @"labore"];
[json UpdateString: @"filter.directoryPrefix" value: @"non"];
[json UpdateString: @"filter.mimeType" value: @"amet"];
[json UpdateNewObject: @"filter.metadata"];
[json UpdateInt: @"filter.assetIds[0]" value: [NSNumber numberWithInt: 2806482587450292]];
[json UpdateInt: @"filter.assetIds[1]" value: [NSNumber numberWithInt: 5885270784918610]];
[json UpdateString: @"filter.assetExternalIds[0]" value: @"cillum quis laborum eu in"];
[json UpdateString: @"filter.assetExternalIds[1]" value: @"pariatur aute incididunt minim nulla"];
[json UpdateInt: @"filter.rootAssetIds[0].id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"filter.rootAssetIds[1].externalId" value: @"dolor nostrud sint tempor"];
[json UpdateInt: @"filter.dataSetIds[0].id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"filter.dataSetIds[1].externalId" value: @"incidid"];
[json UpdateInt: @"filter.assetSubtreeIds[0].id" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"filter.assetSubtreeIds[1].id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"filter.source" value: @"in ullamco in qu"];
[json UpdateInt: @"filter.createdTime.max" value: [NSNumber numberWithInt: 52776204]];
[json UpdateInt: @"filter.createdTime.min" value: [NSNumber numberWithInt: 19590899]];
[json UpdateInt: @"filter.lastUpdatedTime.max" value: [NSNumber numberWithInt: 2447871]];
[json UpdateInt: @"filter.lastUpdatedTime.min" value: [NSNumber numberWithInt: 62024320]];
[json UpdateInt: @"filter.uploadedTime.max" value: [NSNumber numberWithInt: 88446108]];
[json UpdateInt: @"filter.uploadedTime.min" value: [NSNumber numberWithInt: 12715733]];
[json UpdateInt: @"filter.sourceCreatedTime.max" value: [NSNumber numberWithInt: 6470658]];
[json UpdateInt: @"filter.sourceCreatedTime.min" value: [NSNumber numberWithInt: 75552038]];
[json UpdateInt: @"filter.sourceModifiedTime.max" value: [NSNumber numberWithInt: 56421116]];
[json UpdateInt: @"filter.sourceModifiedTime.min" value: [NSNumber numberWithInt: 98065077]];
[json UpdateString: @"filter.externalIdPrefix" value: @"incididunt occaecat eiusmod ut"];
[json UpdateBool: @"filter.uploaded" value: YES];
[json UpdateString: @"filter.labels.containsAll[0].externalId" value: @"pariatur"];
[json UpdateString: @"filter.labels.containsAll[1].externalId" value: @"adipisicing occaecat"];
[json UpdateString: @"filter.geoLocation.relation" value: @"INTERSECTS"];
[json UpdateString: @"filter.geoLocation.shape.type" value: @"Point"];
[json UpdateNumber: @"filter.geoLocation.shape.coordinates[0]" numericStr: @"-28013106.93372789"];
[json UpdateNumber: @"filter.geoLocation.shape.coordinates[1]" numericStr: @"67047806.90769461"];
[json UpdateString: @"search.name" value: @"qui"];
[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/search" 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": "labore",
"directoryPrefix": "non",
"mimeType": "amet",
"metadata": {},
"assetIds": [
2806482587450292,
5885270784918610
],
"assetExternalIds": [
"cillum quis laborum eu in",
"pariatur aute incididunt minim nulla"
],
"rootAssetIds": [
{
"id": 3434712602792354
},
{
"externalId": "dolor nostrud sint tempor"
}
],
"dataSetIds": [
{
"id": 6643919081009120
},
{
"externalId": "incidid"
}
],
"assetSubtreeIds": [
{
"id": 1381446255269154
},
{
"id": 6877534894841850
}
],
"source": "in ullamco in qu",
"createdTime": {
"max": 52776204,
"min": 19590899
},
"lastUpdatedTime": {
"max": 2447871,
"min": 62024320
},
"uploadedTime": {
"max": 88446108,
"min": 12715733
},
"sourceCreatedTime": {
"max": 6470658,
"min": 75552038
},
"sourceModifiedTime": {
"max": 56421116,
"min": 98065077
},
"externalIdPrefix": "incididunt occaecat eiusmod ut",
"uploaded": true,
"labels": {
"containsAll": [
{
"externalId": "pariatur"
},
{
"externalId": "adipisicing occaecat"
}
]
},
"geoLocation": {
"relation": "INTERSECTS",
"shape": {
"type": "Point",
"coordinates": [
-28013106.93372789,
67047806.90769461
]
}
}
},
"search": {
"name": "qui"
}
}'
https://domain.com/api/v1/projects/{{project}}/files/search
Postman Collection Item JSON
{
"id": "searchFiles",
"name": "Search files",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"files",
"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"
}
],
"description": "Search for files based on relevance. You can also supply a strict match filter as in Filter files, and search in the results from the filter. Returns first 1000 results based on relevance. This operation does not support pagination.",
"body": {
"mode": "raw",
"raw": "{\n \"filter\": {\n \"name\": \"labore\",\n \"directoryPrefix\": \"non\",\n \"mimeType\": \"amet\",\n \"metadata\": {},\n \"assetIds\": [\n 2806482587450292,\n 5885270784918610\n ],\n \"assetExternalIds\": [\n \"cillum quis laborum eu in\",\n \"pariatur aute incididunt minim nulla\"\n ],\n \"rootAssetIds\": [\n {\n \"id\": 3434712602792354\n },\n {\n \"externalId\": \"dolor nostrud sint tempor\"\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 6643919081009120\n },\n {\n \"externalId\": \"incidid\"\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 1381446255269154\n },\n {\n \"id\": 6877534894841850\n }\n ],\n \"source\": \"in ullamco in qu\",\n \"createdTime\": {\n \"max\": 52776204,\n \"min\": 19590899\n },\n \"lastUpdatedTime\": {\n \"max\": 2447871,\n \"min\": 62024320\n },\n \"uploadedTime\": {\n \"max\": 88446108,\n \"min\": 12715733\n },\n \"sourceCreatedTime\": {\n \"max\": 6470658,\n \"min\": 75552038\n },\n \"sourceModifiedTime\": {\n \"max\": 56421116,\n \"min\": 98065077\n },\n \"externalIdPrefix\": \"incididunt occaecat eiusmod ut\",\n \"uploaded\": true,\n \"labels\": {\n \"containsAll\": [\n {\n \"externalId\": \"pariatur\"\n },\n {\n \"externalId\": \"adipisicing occaecat\"\n }\n ]\n },\n \"geoLocation\": {\n \"relation\": \"INTERSECTS\",\n \"shape\": {\n \"type\": \"Point\",\n \"coordinates\": [\n -28013106.93372789,\n 67047806.90769461\n ]\n }\n }\n },\n \"search\": {\n \"name\": \"qui\"\n }\n}"
}
}
}