> ## 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.

# Beta Layers

> Retrieve aerial imagery layers (tassel count, stand count, NDVI, RGB) from the Sentera integration and upload layers to Climate FieldView.

Use these endpoints to retrieve aerial imagery layers (tassel count, stand count, NDVI, RGB) from Sentera and upload RGB layers to Climate FieldView.

For conceptual background, see [Layers](/beta/layers).

<Warning>The Layers API is currently in **beta**. Endpoints, request/response schemas, and behavior may change without notice.</Warning>

## Base URL

```
https://api.withleaf.io/services/beta/api
```

## Endpoints

| Endpoint                                                                    | Method                                                           | Path                                          |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------- |
| [Get all layers for a Leaf user](#get-all-layers-for-a-leaf-user)           | <span style={{fontWeight: 'bold', color: '#16a34a'}}>GET</span>  | `/users/{leafUserId}/layers`                  |
| [Upload a layer to Climate FieldView](#upload-a-layer-to-climate-fieldview) | <span style={{fontWeight: 'bold', color: '#e5a00d'}}>POST</span> | `/users/{leafUserId}/layers/climateFieldView` |

***

### Get all layers for a Leaf user

<span style={{fontWeight: 'bold', color: '#16a34a'}}>GET</span> `/users/{leafUserId}/layers`

Returns a paginated list of layers that belong to a Leaf user. Layers are sourced from the Sentera integration and include tassel count, stand count, NDVI, and RGB imagery.

#### Parameters

| Parameter | Type    | Description                                                            |
| --------- | ------- | ---------------------------------------------------------------------- |
| `type`    | string  | Filter by layer type: `TASSEL_COUNT`, `STAND_COUNT`, `NVDI`, or `RGB`. |
| `page`    | integer | Page number (default `0`).                                             |
| `size`    | integer | Page size (default `20`, max `100`).                                   |

<Info>The default page size is 20 when `page` and `size` are not set.</Info>

#### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    'https://api.withleaf.io/services/beta/api/users/{leafUserId}/layers'
  ```

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

  TOKEN = "YOUR_TOKEN"
  endpoint = "https://api.withleaf.io/services/beta/api/users/{leafUserId}/layers"
  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.withleaf.io/services/beta/api/users/{leafUserId}/layers'
  const headers = { Authorization: `Bearer ${TOKEN}` }

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

#### Response

```json theme={null}
[
  {
    "id": "96a098e0-f1d0-47e8-968d-9d55d54da114",
    "leafUserId": "055c4d61-b1e2-4fa9-873c-23433a11c271",
    "apiOwnerUsername": "yourUsername",
    "type": "RGB",
    "origin": "PROVIDER_POOLED",
    "provider": "Sentera",
    "providerLayerId": "vnoyi6a_FI_edovSouthernM_CV_prod_82f9b3d6_211018_151052",
    "providerFieldId": "ycof8zg_AS_edovSouthernM_CV_prod_a025df2d_211015_200456",
    "name": "QuickTile RGB",
    "size": 159135298,
    "md5": "7ff746c6f5f06fc25b46420328402bed",
    "contentS3": "URL",
    "downloadContentS3": "URL",
    "createdTime": "2022-02-16T21:40:20.257Z",
    "leafFieldIds": [
      "f43ca7cc-c73a-43b9-8685-070b03876475",
      "edcf7b8b-913e-4e53-a0b5-91aa16699dfc"
    ]
  }
]
```

***

### Upload a layer to Climate FieldView

<span style={{fontWeight: 'bold', color: '#e5a00d'}}>POST</span> `/users/{leafUserId}/layers/climateFieldView`

Sends a layer file to Climate FieldView using the Leaf user's Climate FieldView credentials.

Currently only true-color image (RGB) files are supported. The file must meet the following Climate FieldView requirements:

* Multi-band GeoTIFF with 24-bit composite values (3 bands: Red, Green, Blue)
* Coordinate Reference System must be UTM with WGS84 datum
* Required GDAL\_METADATA entries embedded in the GeoTIFF:
  * `acquisitionStartDate` — ISO 8601 date
  * `acquisitionEndDate` — ISO 8601 date
  * `isCalibrated` — boolean

<Info>Although Climate FieldView supports files up to 500 MB, this endpoint currently accepts files up to 5 MB.</Info>

<Info>Uploaded layers are not stored on the Leaf side and are only available directly in Climate FieldView.</Info>

#### Parameters

| Parameter    | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| `uploadType` | string | **Required.** Must be `RGB`. |

#### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -F 'file=@rgb.tif' \
    'https://api.withleaf.io/services/beta/api/users/{leafUserId}/layers/climateFieldView?uploadType=RGB'
  ```

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

  TOKEN = "YOUR_TOKEN"
  endpoint = "https://api.withleaf.io/services/beta/api/users/{leafUserId}/layers/climateFieldView"
  headers = {"Authorization": f"Bearer {TOKEN}"}
  params = {"uploadType": "RGB"}

  files = {"file": open("rgb.tif", "rb")}

  response = requests.post(endpoint, headers=headers, files=files, params=params)
  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.withleaf.io/services/beta/api/users/{leafUserId}/layers/climateFieldView'

  const form = new FormData()
  form.append('file', fs.createReadStream('rgb.tif'))

  const headers = {
    Authorization: `Bearer ${TOKEN}`,
    ...form.getHeaders()
  }

  axios.post(endpoint, form, { headers, params: { uploadType: 'RGB' } })
    .then(res => console.log(res.data))
    .catch(console.error)
  ```
</CodeGroup>

#### Response

```json theme={null}
{
  "id": "86fb8bea-1670-48ea-a85d-fbdf6feefb35",
  "name": "LayerName"
}
```
