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

# Climate FieldView

> Connect to Climate FieldView to pull field boundaries, machine files, and field operations through Leaf's provider credentials API.

Leaf connects to Climate FieldView using OAuth 2.0. Once connected, Leaf syncs farms, fields, machine files, and field operations for the Leaf user. Climate FieldView does not have a grower-level hierarchy, so data syncs at the farm and field level.

## Prerequisites

1. A Climate FieldView developer account. [Become a partner](https://dev.fieldview.com/join-us/).
2. Your application's `clientId`, `clientSecret`, and `apiKey` from Climate FieldView.
3. A grower's `refreshToken` obtained through the Climate FieldView OAuth 2.0 consent flow.

## Setup steps

1. Complete the Climate FieldView OAuth 2.0 flow to obtain a `refreshToken` for the grower's account.
2. POST the credentials to Leaf:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
      -H 'Authorization: Bearer YOUR_TOKEN' \
      -H 'Content-Type: application/json' \
      -d '{
        "clientId": "your-client-id",
        "clientSecret": "your-client-secret",
        "apiKey": "your-api-key",
        "refreshToken": "grower-refresh-token"
      }' \
      'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials'
  ```

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

  TOKEN = 'YOUR_TOKEN'

  endpoint = 'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials'
  headers = {'Authorization': f'Bearer {TOKEN}'}

  data = {
      "clientId": "your-client-id",
      "clientSecret": "your-client-secret",
      "apiKey": "your-api-key",
      "refreshToken": "grower-refresh-token"
  }

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

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

  const endpoint = 'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials'
  const headers = { 'Authorization': `Bearer ${TOKEN}` }

  const data = {
      "clientId": "your-client-id",
      "clientSecret": "your-client-secret",
      "apiKey": "your-api-key",
      "refreshToken": "grower-refresh-token"
  }

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

3. Leaf validates the token and begins syncing. Check credential status with `GET /users/{leafUserId}/climate-field-view-credentials`.

## Credentials schema

**Create request body:**

| Field          | Type   | Required | Description                                         |
| -------------- | ------ | -------- | --------------------------------------------------- |
| `clientId`     | string | Yes      | Your application's client ID from Climate FieldView |
| `clientSecret` | string | Yes      | Your application's client secret                    |
| `apiKey`       | string | Yes      | Your application's API key                          |
| `refreshToken` | string | Yes      | The grower's OAuth refresh token                    |

**Response:**

```json theme={null}
{
  "id": "uuid",
  "status": "str",
  "createdTime": "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'",
  "tokenMetadata": {"scopes": ["str"]},
  "clientId": "str",
  "clientSecret": "str",
  "apiKey": "str",
  "refreshToken": "str",
  "accessToken": "str"
}
```

## Endpoints

Base URL: `https://api.withleaf.io/services/usermanagement/api`

| Action                | Method | Path                                                        |
| --------------------- | ------ | ----------------------------------------------------------- |
| Get credentials       | GET    | `/users/{leafUserId}/climate-field-view-credentials`        |
| Create credentials    | POST   | `/users/{leafUserId}/climate-field-view-credentials`        |
| Delete credentials    | DELETE | `/users/{leafUserId}/climate-field-view-credentials`        |
| Get credential events | GET    | `/users/{leafUserId}/climate-field-view-credentials/events` |

## Troubleshooting

Use the events endpoint to inspect credential health:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET \
      -H 'Authorization: Bearer YOUR_TOKEN' \
      'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials/events'
  ```

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

  TOKEN = 'YOUR_TOKEN'
  endpoint = 'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials/events'
  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/usermanagement/api/users/{leafUserId}/climate-field-view-credentials/events'
  const headers = { 'Authorization': `Bearer ${TOKEN}` }

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

<Warning>
  Event logs are retained for 30 days. Once the credential is deleted or disassociated from the Leaf user, the logs are no longer available.
</Warning>

Common issues:

* **Status changes to invalid**: The grower may have revoked access in Climate FieldView, or the refresh token expired. Have the grower re-authorize.
* **No grower hierarchy**: Climate FieldView does not expose a grower level in its FMIS structure. Data is organized by farms and fields only.

## What to do next

* [Connect Climate FieldView Tutorial](/guides/tutorials/connect-climate-fieldview) — Step-by-step walkthrough.
* [Provider Authentication Overview](/providers/overview) — How provider credentials work across all providers.
* [API Reference: Providers](/api-reference/providers) — Full endpoint reference for provider credentials.
