> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Files

> Access files downloaded from migrations, such as CSVs, PDFs, and more

# Files API

The Files API allows you to **list** and **retrieve** files associated with migrations.

## Authentication

All API requests require authentication using an API key. For details on API keys and authentication, see the [API Authorization](/v1/guides/auth) guide.

## File Data Structure

File data is returned in a structured JSON format that includes:

```json theme={"system"}
{
  "object": "file",
  "id": "file-123",
  "created": "2023-05-19T10:30:00Z",
  "name": "Employee Roster",
  "type": "EmployeeRoster",
  "url": "https://storage.example.com/files/employee_roster.json",
  "size": 545024,
  "content_type": "application/json",
  "migration_id": "migration-456"
}
```

### File Fields

The file object contains the following fields:

| Field          | Description                                                      |
| -------------- | ---------------------------------------------------------------- |
| `object`       | The type of object, always `file`                                |
| `id`           | The unique identifier for the file                               |
| `created`      | The date and time the file was created                           |
| `name`         | The name of the file, unmodified from the original file          |
| `type`         | The type of file (e.g., EmployeeRoster)                          |
| `content_type` | The MIME type of the file                                        |
| `url`          | The signed URL for the file                                      |
| `size`         | The size of the file in bytes                                    |
| `migration_id` | The unique identifier for the migration that the file belongs to |

### File Types

Each file is downloaded from a specific source on the source system's website.

The "source" of each file can be inferred by the `type` field. Here is a subset of all possible file types:

* `CompanyInfo-EntityType-Screenshot`
* `CompanyInfo-EntityType-HTML`
* `ContractorInfo-Details-CSV`
* `ContractorPayments-Report-CSV`
* `Deductions-Benefits-Screenshot`
* `Deductions-Benefits-HTML`
* `Deductions-Pay-HTML`
* `Deductions-Report-CSV`
* `Deductions-Report-HTML`
* `DirectDeposit-Report-CSV`
* `EmployeeData-Report-CSV`
* `FederalTax-Setup-Screenshot`
* `FederalTax-Setup-HTML`
* `FederalTax-Document-PDF`
* `Location-Screenshot`
* `Location-HTML`
* `PayrollJournal-Report-CSV`
* `PTOData-Policy-Screenshot`
* `PTOData-Policy-HTML`
* `PTOData-Policy-XLSX`
* `SignatoryData-Screenshot`
* `SignatoryData-HTML`
* `StateTax-Setup-Screenshot`
* `StateTax-Setup-HTML`
* `StateTax-Document-PDF`
* `TimeOffBalances-Report-CSV`

## API Endpoints

### List Files

To list all files for a specific migration:

<CodeGroup>
  ```javascript listFiles.js theme={"system"}
  async function listFiles(migrationId) {
    const response = await fetch(`https://worker.anon.com/api/v1/files?migration_id=${migrationId}`, {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${ANON_API_KEY}`,
        'Content-Type': 'application/json'
      }
    });
    
    if (!response.ok) {
      throw new Error(`Error: ${response.status}`);
    }
    
    return await response.json();
  }
  ```

  ```shell listFiles.sh theme={"system"}
  curl -X GET "https://worker.anon.com/api/v1/files?migration_id=${MIGRATION_ID}" \
    -H "Authorization: Bearer ${ANON_API_KEY}" \
    -H "Content-Type: application/json"
  ```
</CodeGroup>

### Get File Details

To retrieve details for a specific file:

<CodeGroup>
  ```javascript getFile.js theme={"system"}
  async function getFile(fileId) {
    const response = await fetch(`https://worker.anon.com/api/v1/files/${fileId}`, {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${ANON_API_KEY}`,
        'Content-Type': 'application/json'
      }
    });
    
    if (!response.ok) {
      throw new Error(`Error: ${response.status}`);
    }
    
    return await response.json();
  }
  ```

  ```shell getFile.sh theme={"system"}
  curl -X GET "https://worker.anon.com/api/v1/files/${FILE_ID}" \
    -H "Authorization: Bearer ${ANON_API_KEY}" \
    -H "Content-Type: application/json"
  ```
</CodeGroup>

## Best Practices

* Cache file metadata to minimize API calls
* Implement proper error handling for API requests
