# Advanced API File Search

You can get an overview on how to search for files/folders in a container in the [Search](https://docs.libnova.com/LIBSAFE%20Go/get-started/search) section, but there are some cases in which you may need to perform advanced searches. For these cases, LIBSAFE Advanced provides a wide range of search options:

## How Advanced File Search works <a href="#how-advanced-file-search-works" id="how-advanced-file-search-works"></a>

You can use the following properties for searching for files (remember that you can also search for user-defined metadata):

* **id:** To get files/folders matching a certain file id
* **container\_id:** To get files/folders that are in a certain data container
* **parent:** To get files that are in a certain folder (parent folder)
* **filename:** To get files matching the file name (e.g.: mydoc.txt)
* **fullpath**: To get files matching the full path to the file (e.g.: /myfolder/mysubfolder/mydoc.txt)
* **deleted**: 0 or 1
* **size**: In Bytes, to get files larger than or smaller than a certain size
* **type**: FILE or FOLDER, to get only files or folders in your query
* **structure**: If the file is considered structured or unstructured content
* **format**: The PRONOM format for the file
* **mime**: The MIME TYPE for the file
* **date\_update:** Last update datetime for the file (E.g.: "2021-06-08 11:01:00.089657")
* **date\_create**: File creation date
* **storage\_class\_id**: The storage class id associated to the file. See [Storage](advanced-api-file-search).

And you can use the following operators:

* **like:** like in the SQL syntax, supporting the `%` character only
* **starts\_with:** The value starts with
* **ends\_with:** The value ends with
* **eq:** Equal
* **!eq:** Not equal
* **in:** Value for the file/folder is one of the provided values
* **not\_in:** Not one of the provided values
* **gt:** Greater than
* **lt:** Lower than
* **gte:** Greater or equal than
* **lte:** Lower or equal than.

You can combine them, for instance, if you would like to get all the files in the container 185 with a size larger than 702 bytes (703 and larger), you can use:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
       --header "Content-Type: application/json" \
       --header "authorization: Bearer $your_platform_api_key" \
       --data '{
          "conditions": [
              {
                  "container_id": 185
              },
              {
                  "size": {
                      "operator": "gt",
                      "value": 702
                  }
              },
              {
                  "type": "FILE"
              }
          ],
          "limit": 100,
          "offset": 0
      }'
```

If you want to refine even more, listing only the PDF 1.5 files (fmt/19), you can use:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
       --header "Content-Type: application/json" \
       --header "authorization: Bearer $your_platform_api_key" \
       --data '{
          "conditions": [
              {
                  "container_id": 185
              },
              {
                  "size": {
                      "operator": "gt",
                      "value": 702
                  }
              },
              {
                  "type": "FILE"
              },
              {
                  "format": "fmt\/19"
              }
          ],
          "limit": 100,
          "offset": 0
      }'
```

## Examples <a href="#examples" id="examples"></a>

### Finding by file extension <a href="#finding-by-file-extension" id="finding-by-file-extension"></a>

If you want to search by file extension, you can use the `ends_with` condition. For instance:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
     --header "Content-Type: application/json" \
     --header "authorization: Bearer $your_platform_api_key" \
     --data '{
    "conditions": [
            {
                "container_id": 40
            },
            {
                "fullpath": {
                    "operator": "ends_with",
                    "value": ".jpg"
                }
            }
        ],
        "limit": 100,
        "offset": 0
    }'
```

You can achieve the same using the `like` condition, for instance:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
     --header "Content-Type: application/json" \
     --header "authorization: Bearer $your_platform_api_key" \
     --data '{
        "conditions": [
            {
                "container_id": 40
            },
            {
                "fullpath": {
                    "operator": "like",
                    "value": "%.jpg"
                }
            }
        ],
        "limit": 100,
        "offset": 0
    }'
```

​

### Finding files with a certain string in the file name <a href="#finding-files-with-a-certain-string-in-the-file-name" id="finding-files-with-a-certain-string-in-the-file-name"></a>

If you are looking for files in which its full path contains "validator", you could use:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
     --header "Content-Type: application/json" \
     --header "authorization: Bearer $your_platform_api_key" \
     --data '{
        "conditions": [
            {
                "container_id": 40
            },
            {
                "fullpath": {
                    "operator": "like",
                    "value": "%validator%"
                }
            }
        ],
        "limit": 100,
        "offset": 0
    }'
```

This will find:

* /validator/myfile.txt
* /validator.txt
* /my-validator-results/myfile.txt.

### Finding files created after a certain date <a href="#finding-files-created-after-a-certain-date" id="finding-files-created-after-a-certain-date"></a>

If you are looking for the files created after a given date, you can use:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
       --header "Content-Type: application/json" \
       --header "authorization: Bearer $your_platform_api_key" \
       --data '{
          "conditions": [
              {
                  "container_id": 185
              },
              {
                  "date_create": {
                      "operator": "gt",
                      "value": "2021-07-05"
                  }
              },
              {
                  "type": "FILE"
}

          ],
          "limit": 100,
          "offset": 0
      }'
```

### Finding files created before a certain date <a href="#finding-files-created-before-a-certain-date" id="finding-files-created-before-a-certain-date"></a>

If you are looking for the files created before a given date, you can use:

```bash
curl --request GET  --url "$your_platform_url/api/file" \
       --header "Content-Type: application/json" \
       --header "authorization: Bearer $your_platform_api_key" \
       --data '{
          "conditions": [
              {
                  "container_id": 185
              },
              {
                  "date_create": {
                      "operator": "lt",
                      "value": "2021-07-05"
                  }
              },
              {
                  "type": "FILE"
}

          ],
          "limit": 100,
          "offset": 0
      }'
```

## &#x20;<a href="#undefined" id="undefined"></a>
