# Zapini API — Media

**Version:** 1.2.0
**Base URL:** `https://zapini.app/api/v1`

---

## Authentication

All endpoints require a Bearer Token:

```
Authorization: Bearer {your_token}
Accept: application/json
Content-Type: application/json
```

Generate API tokens in your admin panel under **API Docs → Manage Tokens**.

---

## Media

### POST /media/upload

Upload a file.

**Parameters (multipart/form-data):**

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| file | file | Yes | File to upload |
| type | string | Yes | Type (image, video, audio, document) |

**Limits:**

| Type | Max Size | Accepted Formats |
|------|----------|------------------|
| image | 16 MB | JPEG, PNG, GIF, WebP |
| video | 64 MB | MP4, 3GPP, QuickTime |
| audio | 16 MB | MP3, OGG, Opus, WAV, AAC |
| document | 100 MB | PDF, DOC(X), XLS(X), PPT(X), TXT, CSV |

**Example:**

```bash
curl -X POST https://zapini.app/api/v1/media/upload \
  -H "Authorization: Bearer {token}" \
  -F "file=@/path/to/image.jpg" \
  -F "type=image"
```

---

### GET /media/{id}

Returns file details.

---

### DELETE /media/{id}

Delete a file.

---

## Code Examples

### PHP (Guzzle)

```php
<?php
use GuzzleHttp\Client;

$client = new Client([
    'base_uri' => 'https://zapini.app/api/v1/',
    'headers' => [
        'Authorization' => 'Bearer ' . $token,
        'Accept' => 'application/json',
    ]
]);

// Send message
$response = $client->post('messages/send', [
    'json' => [
        'instance_id' => '550e8400-e29b-41d4-a716-446655440000',
        'recipient' => '+15551234567',
        'message' => 'Hello from PHP!'
    ]
]);

$result = json_decode($response->getBody(), true);
echo "Message sent! UUID: " . $result['data']['uuid'];
```

### Python (Requests)

```python
import requests

BASE_URL = 'https://zapini.app/api/v1'

headers = {
    'Authorization': f'Bearer {token}',
    'Accept': 'application/json'
}

# Upload file
with open('image.jpg', 'rb') as f:
    response = requests.post(
        f'{BASE_URL}/media/upload',
        headers={'Authorization': f'Bearer {token}'},
        files={'file': f},
        data={'type': 'image'}
    )

result = response.json()
print(f"File URL: {result['data']['url']}")
```

### JavaScript (Fetch)

```javascript
const BASE_URL = 'https://zapini.app/api/v1';

// Upload file
async function uploadFile(token, file, type) {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('type', type);

    const response = await fetch(`${BASE_URL}/media/upload`, {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${token}`,
            'Accept': 'application/json'
        },
        body: formData
    });
    return await response.json();
}
```

### Node.js (Axios)

```javascript
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

const api = axios.create({
    baseURL: 'https://zapini.app/api/v1',
    headers: {
        'Authorization': `Bearer ${token}`,
        'Accept': 'application/json'
    }
});

// Upload file
async function uploadFile(filePath, type) {
    const form = new FormData();
    form.append('file', fs.createReadStream(filePath));
    form.append('type', type);

    const { data } = await api.post('/media/upload', form, {
        headers: form.getHeaders()
    });
    return data;
}
```

---

*Generated by Zapini — https://zapini.app*
