# Upload a new file.

`POST /station/{station_id}/files`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKey": []
  }
]
```

- ApiKey: apiKey, header X-API-Key

Parameters:

- `station_id` (path, unknown, required)
  Type: unknown
  
  anyOf:
    Type: integer, int64
  
    Type: string, string

Request body: application/json

Type: object

Schema: [Api_UploadFile](https://sourcey-azuracast.pages.dev/docs/api/models/api-uploadfile/index.md)

- `path` (required)
  Type: string
  
  The destination path of the uploaded file.
  
  Example:
  
  ```json
  "relative/path/to/file.mp3"
  ```

- `file` (required)
  Type: string
  
  The base64-encoded contents of the file to upload.
  
  Example:
  
  ```json
  ""
  ```

Responses:

- 200: Success

Content type: application/json

Type: object

Schema: [Api_StationMedia](https://sourcey-azuracast.pages.dev/docs/api/models/api-stationmedia/index.md)

allOf:
  Reference: [Api_HasSongFields](https://sourcey-azuracast.pages.dev/docs/api/models/api-hassongfields/index.md); Type: object

  Reference: [HasLinks](https://sourcey-azuracast.pages.dev/docs/api/models/haslinks/index.md); Type: object

  Type: object
  
  - `id` (optional)
    Type: integer
    
    The media's identifier.
    
    Example:
    
    ```json
    1
    ```
  
  - `unique_id` (optional)
    Type: string
    
    A unique identifier for this specific media item in the station's library. Each entry in the media table has a unique ID, even if it refers to a song that exists elsewhere.
    
    Example:
    
    ```json
    "69b536afc7ebbf16457b8645"
    ```
  
  - `song_id` (optional)
    Type: string
    
    The media file's 32-character unique song identifier hash. This hash is based on track metadata, so the same song uploaded multiple times will have the same `song_id`.
    
    Example:
    
    ```json
    "9f33bbc912c19603e51be8e0987d076b"
    ```
  
  - `art` (optional)
    Type: string
    
    URL to the album art.
    
    Example:
    
    ```json
    "https://picsum.photos/1200/1200"
    ```
  
  - `path` (optional)
    Type: string
    
    The relative path of the media file.
    
    Example:
    
    ```json
    "test.mp3"
    ```
  
  - `mtime` (optional)
    Type: integer
    
    The UNIX timestamp when the database was last modified.
    
    Example:
    
    ```json
    1609480800
    ```
  
  - `uploaded_at` (optional)
    Type: integer
    
    The UNIX timestamp when the item was first imported into the database.
    
    Example:
    
    ```json
    1609480800
    ```
  
  - `art_updated_at` (optional)
    Type: integer
    
    The latest time (UNIX timestamp) when album art was updated.
    
    Example:
    
    ```json
    1609480800
    ```
  
  - `length` (optional)
    Type: number, float
    
    The song duration in seconds.
    
    Example:
    
    ```json
    240
    ```
  
  - `length_text` (optional)
    Type: string
    
    The formatted song duration (in mm:ss format)
    
    Example:
    
    ```json
    "4:00"
    ```
  
  - `custom_fields` (optional)
    Reference: [HashMap](https://sourcey-azuracast.pages.dev/docs/api/models/hashmap/index.md); Type: object
    
    A hash-map array represented as an object.
  
  - `extra_metadata` (optional)
    Reference: [HashMap](https://sourcey-azuracast.pages.dev/docs/api/models/hashmap/index.md); Type: object
    
    A hash-map array represented as an object.
  
  - `playlists` (optional)
    Type: array
    
    Items:
      Type: unknown
      
      oneOf:
        Reference: [Api_StationMediaPlaylist](https://sourcey-azuracast.pages.dev/docs/api/models/api-stationmediaplaylist/index.md); Type: object
      
        Type: integer
        
        writeOnly: true

- 403: Access denied.

Content type: application/json

Type: object

Schema: [Api_Error](https://sourcey-azuracast.pages.dev/docs/api/models/api-error/index.md)

- `code` (required)
  Type: integer
  
  The numeric code of the error.
  
  Example:
  
  ```json
  500
  ```

- `type` (required)
  Type: string
  
  The programmatic class of error.
  
  Example:
  
  ```json
  "NotLoggedInException"
  ```

- `message` (required)
  Type: string
  
  The text description of the error.
  
  Example:
  
  ```json
  "Error description."
  ```

- `formatted_message` (required)
  Type: string; nullable
  
  The HTML-formatted text description of the error.
  
  Example:
  
  ```json
  "<b>Error description.</b><br>Detailed error text."
  ```

- `extra_data` (required)
  Type: array
  
  Stack traces and other supplemental data.
  
  Items:
    Type: any

- `success` (required)
  Type: boolean
  
  Used for API calls that expect an \Entity\Api\Status type response.
  
  Example:
  
  ```json
  false
  ```

- 500: A generic exception has occurred.

Content type: application/json

Type: object

Schema: [Api_Error](https://sourcey-azuracast.pages.dev/docs/api/models/api-error/index.md)

- `code` (required)
  Type: integer
  
  The numeric code of the error.
  
  Example:
  
  ```json
  500
  ```

- `type` (required)
  Type: string
  
  The programmatic class of error.
  
  Example:
  
  ```json
  "NotLoggedInException"
  ```

- `message` (required)
  Type: string
  
  The text description of the error.
  
  Example:
  
  ```json
  "Error description."
  ```

- `formatted_message` (required)
  Type: string; nullable
  
  The HTML-formatted text description of the error.
  
  Example:
  
  ```json
  "<b>Error description.</b><br>Detailed error text."
  ```

- `extra_data` (required)
  Type: array
  
  Stack traces and other supplemental data.
  
  Items:
    Type: any

- `success` (required)
  Type: boolean
  
  Used for API calls that expect an \Entity\Api\Status type response.
  
  Example:
  
  ```json
  false
  ```

## Examples

### cURL

```bash
curl -X POST 'https://demo.azuracast.com/api/station/0/files' \
  -H 'X-API-Key: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "path": "relative/path/to/file.mp3",
  "file": ""
}'
```

### JavaScript

```javascript
const body = `{
  "path": "relative/path/to/file.mp3",
  "file": ""
}`;

const response = await fetch('https://demo.azuracast.com/api/station/0/files', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "path": "relative/path/to/file.mp3",
  "file": ""
}'''

response = requests.post(
    'https://demo.azuracast.com/api/station/0/files',
    data=body.encode('utf-8'),
    headers={
        'X-API-Key': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
