# Prepare image uploads

URL: https://api-docs.vestta.io/properties/uploads

Get temporary PUT URLs for original image uploads.

Send file metadata to reserve an upload session. Upload each accepted file's bytes directly to `upload_url` with HTTP `PUT` and the declared `Content-Type`. Do not send your Vestta API key to the storage URL.

Files must be JPEG, PNG or WebP, at most 10 MiB each. A property can contain at most 15 images. `file_id` is your correlation ID and must be unique within the session.

The original goes into private storage. An upload URL is temporary, permits upload only and is not a public photo URL. Inspect `rejected` before continuing; complete only accepted uploads.

### POST /v1/properties/{property_id}/images/uploads

Returns short-lived PUT URLs into private storage. Upload each file, then complete the session. No original download URL is returned. Requires the `properties:write` scope.

Required scope: `properties:write`

Path parameters:
- `property_id` (integer, required, ≥ 1)

Request body (ImageUploadRequest, required, application/json):
- `files` (array of objects, required)
  - `file_id` (string, required, 1–100 chars)
  - `filename` (string, required, 1–255 chars)
  - `content_type` (string, required, values: `image/jpeg` | `image/png` | `image/webp`)
  - `size` (integer, required, > 0, ≤ 10485760)

Response 201: Successful response.
- `session_id` (string, required)
- `accepted` (array of objects, required)
  - `file_id` (string, required)
  - `upload_id` (string, required)
  - `upload_url` (string, required)
- `rejected` (array of objects, required)
  - `file_id` (string, required)
  - `filename` (string, required)
  - `reason` (string, required)

```json
{
  "session_id": "upl_21_example",
  "accepted": [
    {
      "file_id": "photo-1",
      "upload_id": "1234567890ABCDEF",
      "upload_url": "https://private-storage.example/upload?signed=temporary"
    }
  ],
  "rejected": []
}
```

Response 401: The API key is missing, malformed, unknown, revoked or expired.

Response 403: The API key lacks the required scope, or the business plan does not include API access.

Response 404: The resource does not exist in this business.

Response 409: Duplicate contact or idempotency key reused with a different payload.

Response 422: A path parameter, query parameter or body field is invalid.

Response 429: The API key reached its request limit. Wait for the number of seconds in `Retry-After` before retrying.

Response 500: Unexpected server error while processing the request.

### Example requests

#### cURL

```bash
curl -X POST "https://api.vestta.io/v1/properties/1/images/uploads" \
  -H "X-Api-Key: $VESTTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "files": [
    {
      "file_id": "photo-1",
      "filename": "living-room.jpg",
      "content_type": "image/jpeg",
      "size": 125000
    }
  ]
}'
```

#### JavaScript

```javascript
const response = await fetch('https://api.vestta.io/v1/properties/1/images/uploads', {
  method: 'POST',
  headers: {
    'X-Api-Key': process.env.VESTTA_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "files": [
      {
        "file_id": "photo-1",
        "filename": "living-room.jpg",
        "content_type": "image/jpeg",
        "size": 125000
      }
    ]
  }),
})

const data = await response.json()
```

#### Python

```python
import os

import requests

response = requests.post(
    "https://api.vestta.io/v1/properties/1/images/uploads",
    headers={"X-Api-Key": os.environ["VESTTA_API_KEY"]},
    json={
        "files": [
            {
                "file_id": "photo-1",
                "filename": "living-room.jpg",
                "content_type": "image/jpeg",
                "size": 125000,
            },
        ],
    },
)
response.raise_for_status()
data = response.json()
```
