# Get List of Files/Folders

GET https://services.leadconnectorhq.com/medias/files

Fetches list of files and folders from the media storage

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `medias.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `offset` | string | No | Number of files to skip in listing |
| `limit` | string | No | Number of files to show in the listing |
| `sortBy` | string | Yes | Field to sorting the file listing by (e.g. updatedAt, name) |
| `sortOrder` | string | Yes | Direction in which file needs to be sorted |
| `type` | string | Yes | Type |
| `query` | string | No | Query text |
| `altType` | string | Yes | AltType |
| `altId` | string | Yes | location Id |
| `parentId` | string | No | parent id or folder id |
| `fetchAll` | string | No | Fetch all files or folders |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/medias/files": {
      "get": {
        "summary": "Get List of Files/Folders",
        "operationId": "getListOfFilesfolders",
        "description": "Fetches list of files and folders from the media storage",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "offset",
            "required": false,
            "in": "query",
            "description": "Number of files to skip in listing",
            "example": "5",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": false,
            "in": "query",
            "description": "Number of files to show in the listing",
            "example": "10",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sortBy",
            "required": true,
            "in": "query",
            "description": "Field to sorting the file listing by (e.g. updatedAt, name)",
            "example": "updatedAt",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sortOrder",
            "required": true,
            "in": "query",
            "description": "Direction in which file needs to be sorted",
            "example": "asc",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": true,
            "in": "query",
            "description": "Type",
            "example": "file",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "query",
            "required": false,
            "in": "query",
            "description": "Query text",
            "example": "Test file",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "altType",
            "required": true,
            "in": "query",
            "description": "AltType",
            "example": "location",
            "schema": {
              "type": "string",
              "enum": [
                "location"
              ]
            }
          },
          {
            "name": "altId",
            "required": true,
            "in": "query",
            "description": "location Id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "parentId",
            "in": "query",
            "description": "parent id or folder id",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "fetchAll",
            "required": false,
            "description": "Fetch all files or folders",
            "example": "false",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetFilesResponseDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "medias.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "GetFilesResponseDTO": {
        "type": "object",
        "properties": {
          "files": {
            "description": "Array of File Objects",
            "example": {
              "altId": "locationId",
              "altType": "location",
              "name": "file name",
              "parentId": "parent folder id",
              "url": "file url",
              "path": "file path"
            },
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "files"
        ],
        "title": "GetFilesResponseDTO"
      }
    }
  }
}
```

## HighLevel SDK Examples

**Node.js** (`@gohighlevel/api-client`)

```javascript
import HighLevel from '@gohighlevel/api-client';

const ghl = new HighLevel({
  privateIntegrationToken: '<PRIVATE_INTEGRATION_TOKEN>'
});

const response = await ghl.medias.getListOfFilesfolders({ sortBy: '<SORTBY>', sortOrder: '<SORTORDER>', type: '<TYPE>', altType: '<ALTTYPE>', altId: '<ALTID>' });
console.log(response);
```

**Python** (`gohighlevel-api-client`)

```python
from highlevel import HighLevel

client = HighLevel(
    private_integration_token='<PRIVATE_INTEGRATION_TOKEN>'
)

response = await client.medias.get_list_of_filesfolders(sortBy='<SORTBY>', sortOrder='<SORTORDER>', type='<TYPE>', altType='<ALTTYPE>', altId='<ALTID>')
print(response)
```

**PHP** (`gohighlevel/api-client`)

```php
<?php
require_once 'vendor/autoload.php';

use HighLevel\HighLevel;
use HighLevel\HighLevelConfig;

$config = new HighLevelConfig([
    'privateIntegrationToken' => '<PRIVATE_INTEGRATION_TOKEN>'
]);
$ghl = new HighLevel($config);

$response = $ghl->medias->getListOfFilesfolders(['sortBy' => '<SORTBY>', 'sortOrder' => '<SORTORDER>', 'type' => '<TYPE>', 'altType' => '<ALTTYPE>', 'altId' => '<ALTID>']);
echo json_encode($response, JSON_PRETTY_PRINT);
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/medias/files"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "sortBy": "<SORTBY>",
    "sortOrder": "<SORTORDER>",
    "type": "<TYPE>",
    "altType": "<ALTTYPE>",
    "altId": "<ALTID>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/medias/files?sortBy=<SORTBY>&sortOrder=<SORTORDER>&type=<TYPE>&altType=<ALTTYPE>&altId=<ALTID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
