Chilkat Online Tools

SQL Server / Cognite API v1 / Search files

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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"
    --   }
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.name', 'labore'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.directoryPrefix', 'non'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.mimeType', 'amet'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[0]', 2806482587450292
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[1]', 5885270784918610
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[0]', 'cillum quis laborum eu in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[1]', 'pariatur aute incididunt minim nulla'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.rootAssetIds[1].externalId', 'dolor nostrud sint tempor'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.dataSetIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[1].externalId', 'incidid'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.source', 'in ullamco in qu'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 52776204
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 19590899
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 2447871
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 62024320
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.uploadedTime.max', 88446108
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.uploadedTime.min', 12715733
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.sourceCreatedTime.max', 6470658
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.sourceCreatedTime.min', 75552038
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.sourceModifiedTime.max', 56421116
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.sourceModifiedTime.min', 98065077
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'incididunt occaecat eiusmod ut'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.uploaded', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAll[0].externalId', 'pariatur'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAll[1].externalId', 'adipisicing occaecat'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.geoLocation.relation', 'INTERSECTS'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.geoLocation.shape.type', 'Point'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'filter.geoLocation.shape.coordinates[0]', '-28013106.93372789'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'filter.geoLocation.shape.coordinates[1]', '67047806.90769461'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'search.name', 'qui'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'api-key', '{{api-key}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/projects/{{project}}/files/search', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

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}"
    }
  }
}