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

# Unified Upload

> Upload a single ZIP containing machine data, field boundaries, or both. Leaf detects the contents, routes each part to the right service, and tracks everything under one upload ID.

The Unified Upload API is a single ingress point for file uploads. Send one `.zip`, and Leaf inspects it, routes each kind of content to the service that processes it, and reports the result under a single `uploadId`. You no longer need to know ahead of time whether a customer's archive contains monitor files, boundary shapefiles, or a mix.

Behind the scenes, detected content is fanned out to the same pipelines documented elsewhere:

| Detected content | Downstream service | Tracked as |
| - | - | - |
| Machine / operations data | [Batch upload](https://docs.withleaf.io/api-reference/files.md#batch-upload) | `MACHINE_FILE` artifact with a `batchId` |
| Field geometry (shapefile, GeoJSON, KML) | [Field boundary upload](https://docs.withleaf.io/api-reference/field-upload.md) | `FIELD_BOUNDARY` artifact with a `downstreamId` |

For conceptual background on preparing archives, see [Uploading Files](https://docs.withleaf.io/machine-data/uploading-files.md) and [Uploading Boundaries](https://docs.withleaf.io/fields/uploading-boundaries.md).

## Base URL

```
https://api-v2.withleaf.io/services/inbox/api
```

## Endpoints

| Method | Path | Description |
| - | - | - |
| POST | `/uploads` | [Upload a file](#upload-a-file) |
| GET | `/uploads/{uploadId}` | [Get an upload](#get-an-upload) |

***

## Archive requirements

* The file **must be a `.zip`**. Gzip archives (`.gz`, `.tar.gz`) are rejected with `400 Bad Request`, and so is any `.zip` that contains a `.gz` entry anywhere inside it, even alongside valid machine or boundary files. Remove or decompress `.gz` entries before zipping. macOS Finder sidecars (`__MACOSX/`, `._*`) are ignored.
* Maximum size is 3 GB.
* Keep the original folder structure from the monitor or export tool. The same [folder structure rules](https://docs.withleaf.io/machine-data/uploading-files.md#folder-structure-rules) that apply to batch uploads apply here.
* A single archive may mix content types. See [How content is routed](#how-content-is-routed) for what Leaf detects and in what order.

## How content is routed

Leaf inspects the archive once and decides which downstream services receive it:

1. **Machine data** is sent to the batch upload service first, unless the archive is boundary-only (field geometry present and no machine content). If this hand-off fails, the upload ends in `ROUTING_FAILED` and no further routing happens.
2. **Field geometry** is then sent to the field boundary upload service as a best-effort second route. A failure here is recorded on its own artifact and does not affect the machine-data batch.

Field geometry is detected when the archive contains any of:

* A `.geojson`, `.json` (other than `metadata.json`), or `.kml` file.
* A **complete polygon shapefile**: `.shp` with its `.shx` and `.dbf` companions at the same path, a polygon shape type, and at most 100 features.

Point and polyline shapefiles, shapefiles with more than 100 features (typically as-applied or yield coverage), and shapefiles missing `.shx`/`.dbf` are treated as machine data and stay on the batch upload path. `.kmz` is not detected by this endpoint; upload KMZ boundaries directly through [Field boundary upload](https://docs.withleaf.io/api-reference/field-upload.md). Leaf looks inside nested ZIPs up to two levels deep. Field geometry detection is skipped, and the upload stays on the machine-data path only, when the archive expands to more than 1 GiB uncompressed, or to more than 256 MiB at a ratio above 10:1.

Soil-sampling shapefiles are **not** sent to field boundary upload, even when they match the polygon-shapefile checks above.

## Upload statuses

`status` reports where the upload is in the intake and processing lifecycle.

| Status | Description |
| - | - |
| `RECEIVED` | The archive is stored and queued for content detection. |
| `DISPATCHED` | Contents were detected and routed to the downstream services. Processing is in progress. |
| `ROUTING_FAILED` | Leaf could not hand the archive to the machine-data service. See `artifacts[].error`. This is a dead end: the upload never advances, `completedTimestamp` stays `null`, and no alert fires. Stop polling and re-upload. |
| `COMPLETED` | Downstream processing finished and every part produced output. |
| `PARTIALLY_COMPLETED` | Downstream processing finished with output, but at least one part failed or was incomplete. |
| `FAILED` | Downstream processing finished and no part produced output. |
| `FILE_REJECTED` | The machine-data service could not open or read the archive at all (`File detection error`, `Files found but unable to read`, `Failed to open Zip file`) and extracted no files. An archive that opens but contains no recognizable monitor layout (`No operation discovered`) ends in `FAILED`, not `FILE_REJECTED`. |
| `TIMED_OUT` | Downstream processing did not reach a terminal state within 6 hours of `receivedTimestamp`. |

`RECEIVED` and `DISPATCHED` are in-progress states. `ROUTING_FAILED` is a terminal intake failure that does not set `completedTimestamp`. The remaining five are terminal and populate `completedTimestamp`.

> [!WARNING]
>
> **Use `artifacts[]` IDs as the source of truth for processing results.** The top-level terminal status (`COMPLETED` / `PARTIALLY_COMPLETED` / `FAILED` / `TIMED_OUT`) is currently derived from whether downstream *output artifacts* were generated, not from per-file conversion results. Output generation is an account-level feature that is not enabled by default. On accounts without it, a machine-data-only upload reports `FAILED` once conversion finishes even when every file converted successfully, and an upload that created field boundaries reports `TIMED_OUT` after 6 hours even though the boundaries were created. Treat the terminal status as "downstream processing has stopped," and always follow `artifacts[].batchId` into [Get batch files status](https://docs.withleaf.io/api-reference/files.md#get-batch-files-status) and `artifacts[].downstreamId` into [Get upload entries](https://docs.withleaf.io/api-reference/field-upload.md#get-upload-entries) to confirm what was actually processed.

***

## Upload a file

POST `/uploads`

Uploads a `.zip` archive on behalf of a Leaf user. The request returns `202 Accepted` immediately; detection and routing happen asynchronously. Use [Get an upload](#get-an-upload) to track progress.

### Parameters

Send the request as `multipart/form-data`.

| Parameter | Type | Description |
| - | - | - |
| `file` | form part (binary) | **Required.** The `.zip` archive. |
| `leafUserId` | form part (UUID) | **Required.** The Leaf user who will own the resulting data. |

### Request

```bash cURL theme={null}
curl -X POST \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -F 'file=@/path/to/your-data.zip' \
  -F 'leafUserId=UUID' \
  'https://api-v2.withleaf.io/services/inbox/api/uploads'
```

```python Python theme={null}
import requests

TOKEN = "YOUR_TOKEN"
endpoint = "https://api-v2.withleaf.io/services/inbox/api/uploads"
headers = {"Authorization": f"Bearer {TOKEN}"}

with open("/path/to/your-data.zip", "rb") as f:
    response = requests.post(
        endpoint,
        headers=headers,
        files={"file": f},
        data={"leafUserId": "UUID"},
    )
print(response.json())
```

```javascript JavaScript theme={null}
const axios = require('axios')
const FormData = require('form-data')
const fs = require('fs')

const TOKEN = 'YOUR_TOKEN'
const endpoint = 'https://api-v2.withleaf.io/services/inbox/api/uploads'

const form = new FormData()
form.append('file', fs.createReadStream('/path/to/your-data.zip'))
form.append('leafUserId', 'UUID')

axios.post(endpoint, form, {
  headers: { Authorization: `Bearer ${TOKEN}`, ...form.getHeaders() }
})
  .then(res => console.log(res.data))
  .catch(console.error)
```

### Response

`202 Accepted`

```json theme={null}
{
  "uploadId": "d1ec090c-c7f5-4954-ac89-a29a3a4e2d03",
  "leafUserId": "879dd843-59a4-4f6d-871c-ea244c1442ac",
  "fileName": "your-data.zip",
  "size": 8652951,
  "status": "RECEIVED",
  "receivedTimestamp": "2026-07-31T17:05:12.481Z"
}
```

| Field | Description |
| - | - |
| `uploadId` | The ID to use for all follow-up calls. |
| `size` | Archive size in bytes. |
| `status` | Always `RECEIVED` at this point. |

### Errors

| Status | Cause |
| - | - |
| `400 Bad Request` | The file is not a `.zip`, is a gzip archive, contains a `.gz` entry, has no content, or `leafUserId` is missing. |
| `401 Unauthorized` | Missing or invalid token. |

> [!WARNING]
>
> Only the `uploadId` is needed to follow the upload end to end. Leaf still creates the downstream batch and upload records, and their IDs are exposed in `artifacts[]`, but you do not need to poll those services separately.

***

## Get an upload

GET `/uploads/{uploadId}`

Returns the current status of an upload, what Leaf detected inside the archive, and where each part was routed. Uploads are scoped to the API owner that created them: an unknown ID and an ID owned by another account both return `404 Not Found`.

### Parameters

| Parameter | Type | Description |
| - | - | - |
| `uploadId` | path (UUID) | The upload ID. |

### Request

```bash cURL theme={null}
curl -X GET \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  'https://api-v2.withleaf.io/services/inbox/api/uploads/{uploadId}'
```

```python Python theme={null}
import requests

TOKEN = "YOUR_TOKEN"
endpoint = "https://api-v2.withleaf.io/services/inbox/api/uploads/{uploadId}"
headers = {"Authorization": f"Bearer {TOKEN}"}

response = requests.get(endpoint, headers=headers)
print(response.json())
```

```javascript JavaScript theme={null}
const axios = require('axios')
const TOKEN = 'YOUR_TOKEN'

const endpoint = 'https://api-v2.withleaf.io/services/inbox/api/uploads/{uploadId}'
const headers = { Authorization: `Bearer ${TOKEN}` }

axios.get(endpoint, { headers })
  .then(res => console.log(res.data))
  .catch(console.error)
```

### Response

```json theme={null}
{
  "uploadId": "d1ec090c-c7f5-4954-ac89-a29a3a4e2d03",
  "leafUserId": "879dd843-59a4-4f6d-871c-ea244c1442ac",
  "fileName": "your-data.zip",
  "size": 8652951,
  "status": "COMPLETED",
  "receivedTimestamp": "2026-07-31T17:05:12.481Z",
  "completedTimestamp": "2026-07-31T17:11:57.902Z",
  "summary": {
    "detected": 2,
    "routed": 2,
    "failed": 0
  },
  "artifacts": [
    {
      "detectedType": "MACHINE_FILE",
      "status": "DISPATCHED",
      "batchId": "b51b545d-08b7-44bb-b4f9-25885a83db63",
      "downstreamId": null,
      "error": null
    },
    {
      "detectedType": "FIELD_BOUNDARY",
      "status": "DISPATCHED",
      "batchId": null,
      "downstreamId": "938bb801-1a2b-4c3d-9e4f-5a6b7c8d9e0f",
      "error": null
    }
  ]
}
```

| Field | Description |
| - | - |
| `status` | Upload lifecycle. See [Upload statuses](#upload-statuses). |
| `completedTimestamp` | Set when `status` reaches `COMPLETED`, `PARTIALLY_COMPLETED`, `FAILED`, `FILE_REJECTED`, or `TIMED_OUT`; `null` until then and `null` permanently for `ROUTING_FAILED`. |
| `summary.detected` | Number of content types detected in the archive. |
| `summary.routed` | Number of artifacts successfully handed to a downstream service. |
| `summary.failed` | Number of artifacts whose routing failed. |
| `artifacts[].detectedType` | `MACHINE_FILE` or `FIELD_BOUNDARY`. |
| `artifacts[].status` | Routing outcome: `DISPATCHED` or `ROUTING_FAILED`. |
| `artifacts[].batchId` | The batch upload ID created in the operations service (`MACHINE_FILE` only). Usable with [Get a batch](https://docs.withleaf.io/api-reference/files.md#get-a-batch). |
| `artifacts[].downstreamId` | The field upload ID created downstream (`FIELD_BOUNDARY` only). `null` for `MACHINE_FILE`. |
| `artifacts[].error` | Reason when `status` is `ROUTING_FAILED`. |

> [!NOTE]
>
> The response may include additional fields (for example `packagingStatus` and `outputReady`) that support features not covered on this page. Ignore fields not documented here; they are not part of the public contract.

> [!TIP]
>
> Poll this endpoint every 30–60 seconds, and stop once `status` is `ROUTING_FAILED` or `completedTimestamp` is set. `artifacts[].status` tells you whether routing succeeded; the top-level `status` tells you whether downstream processing finished, not whether every file converted. For the per-file result, follow `batchId` into [Get batch files status](https://docs.withleaf.io/api-reference/files.md#get-batch-files-status) or `downstreamId` into [Get upload entries](https://docs.withleaf.io/api-reference/field-upload.md#get-upload-entries).

***

## Alerts

Instead of polling, you can subscribe to [alerts](https://docs.withleaf.io/alerts/overview.md) for the upload lifecycle:

| Event | Fired when |
| - | - |
| `inboxUploadProcessingFinished` | `status` reaches `COMPLETED` or `PARTIALLY_COMPLETED`. |
| `inboxUploadProcessingFailed` | `status` reaches `FAILED`, `FILE_REJECTED`, or `TIMED_OUT`. |

Both payloads carry `uploadId`, `leafUserId`, `type`, `timestamp`, and `status`. Branch on `payload.status`, not only on the event type: `inboxUploadProcessingFinished` with `status: PARTIALLY_COMPLETED` means part of the upload failed, and on accounts without output generation enabled you will only ever receive `inboxUploadProcessingFailed` (see the warning under [Upload statuses](#upload-statuses)). Use the alert as a "processing has stopped" signal and read the per-file result from the downstream IDs in `artifacts[]`.

No alert fires for `ROUTING_FAILED`. If you have not received either event within roughly 6 hours of upload, poll [Get an upload](#get-an-upload) as a backstop.

> [!NOTE]
>
> These two events are subscribed by name through the [Alerts API](https://docs.withleaf.io/api-reference/alerts.md) like any other event, but they are not yet listed on the [Events](https://docs.withleaf.io/alerts/events.md) catalog page.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.