# Start an attachment upload

> Use this first to attach a file: it answers an upload URL.

Source: https://docs.clouduxe.com/api/reference/support/create-attachment/

`POST /attachments`

Use this first to attach a file: it answers an upload URL. PUT the bytes there with the given headers, then call completeAttachment, then pass the id in attachmentIds. At most 10 MiB.

Token scope: `tickets:write`.

### Headers

- `Clouduxe-Version` (string): The API version to use, such as 2026-12-01. Omit it to use your token's version. pattern ^[0-9]{4}-[0-9]{2}-[0-9]{2}$.
- `Idempotency-Key` (string, required): A unique key for this logical request, 1 to 128 characters of letters, digits, underscore, dot, colon or hyphen; a UUID is best. Retrying with the same key is safe: the change happens once and the retry gets the same answer. Keys are kept 48 hours. pattern ^[A-Za-z0-9_.:-]{1,128}$.

### Body (required)

- `filename` (string, required): The file name, 1 to 255 characters. min length 1, max length 255.
- `size` (integer, required): The exact size in bytes, at most 10 MiB. min 1, max 10485760.
- `contentType` (string, required): The file's media type. The stored type is sniffed from the bytes: PNG, JPEG, GIF, WebP, PDF, ZIP, gzip or plain text.

### Responses

- `201`: Where to upload.
- `400`: The request is not valid. Codes: version_invalid, idempotency_key_required, idempotency_key_invalid, invalid_json, parameter_missing, parameter_invalid, parameter_unknown.
- `401`: Authentication failed. Codes: token_missing, token_invalid, token_expired, token_revoked.
- `403`: The token is not allowed to do this. Codes: forbidden, ip_not_allowed, api_access_disabled, scope_missing.
- `409`: The request conflicts with the object's current state. Codes: idempotency_in_progress.
- `413`: The request body is too large. Codes: request_too_large.
- `415`: Unsupported media type. Codes: unsupported_media_type.
- `422`: The request is well formed but cannot be carried out. Codes: idempotency_mismatch.
- `429`: A rate limit was reached. Codes: rate_limited.
- `500`: Unexpected error. Codes: internal_error.
- `503`: Temporarily unavailable. Codes: maintenance, files_unavailable, unavailable, outcome_unknown, limits_unavailable.

### Request

curl:
```bash
curl -X POST https://api.clouduxe.com/v1/attachments \
  -H "Authorization: Bearer $CLOUDUXE_API_KEY" \
  -H "Idempotency-Key: 6f1c2e9a-4b7d-4e3a-9c8f-1a2b3c4d5e6f" \
  -H "Content-Type: application/json" \
  -d '{"filename":"mtr-ipv6.txt","size":2048,"contentType":"text/plain"}'
```

Node SDK:
```javascript
import { Clouduxe } from "@clouduxe/sdk";

const cx = new Clouduxe({ apiKey: process.env.CLOUDUXE_API_KEY });

const attachmentUpload = await cx.attachments.create({ filename: "mtr-ipv6.txt", size: 2048, contentType: "text/plain" });
```

Python:
```python
import os
import requests

res = requests.post(
    "https://api.clouduxe.com/v1/attachments",
    headers={
        "Authorization": f"Bearer {os.environ['CLOUDUXE_API_KEY']}",
        "Idempotency-Key": "6f1c2e9a-4b7d-4e3a-9c8f-1a2b3c4d5e6f",
    },
    json={
        "filename": "mtr-ipv6.txt",
        "size": 2048,
        "contentType": "text/plain",
    },
)
attachmentUpload = res.json()
```

PHP SDK:
```php
<?php
require 'vendor/autoload.php';

$cx = new \Clouduxe\Clouduxe(['apiKey' => getenv('CLOUDUXE_API_KEY')]);

$attachmentUpload = $cx->attachments->create(['filename' => 'mtr-ipv6.txt', 'size' => 2048, 'contentType' => 'text/plain']);
```

fetch:
```javascript
const res = await fetch("https://api.clouduxe.com/v1/attachments", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CLOUDUXE_API_KEY}`,
    "Idempotency-Key": "6f1c2e9a-4b7d-4e3a-9c8f-1a2b3c4d5e6f",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    filename: "mtr-ipv6.txt",
    size: 2048,
    contentType: "text/plain"
  }),
});
const attachmentUpload = await res.json();
```

### Response (`201`)

```json
{
  "object": "attachment_upload",
  "attachmentId": "6e1d9b4a-3c7f-4a2e-b8d6-0f5c2a9e1b7d",
  "upload": {
    "url": "https://files.example.net/uploads/6e1d9b4a?sig=Qm3vT8xK2pLd7Rw4",
    "method": "PUT",
    "headers": {
      "content-length": "2048",
      "content-type": "application/octet-stream"
    },
    "expiresAt": "2026-12-04T09:45:00Z"
  }
}
```
