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

# CLAAS

> Connect to CLAAS to pull machine files and field operations through Leaf's provider credentials API.

Leaf connects to the CLAAS partner API using OAuth 2.0. Once connected, Leaf syncs equipment outbox files (ISO 11783 / ISOXML format) and processes them through the standard operations pipeline.

## Prerequisites

1. OAuth client credentials (`clientKey` and `clientSecret`) for the CLAAS partner/OFT API.
2. A grower's `refreshToken` obtained through the CLAAS OAuth 2.0 consent flow.

## Setup steps

1. Complete the CLAAS 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 '{
        "clientKey": "your-client-key",
        "clientSecret": "your-client-secret",
        "refreshToken": "grower-refresh-token",
        "clientEnvironment": "PRODUCTION"
      }' \
      'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/claas-credentials'
  ```

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

  TOKEN = 'YOUR_TOKEN'

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

  data = {
      "clientKey": "your-client-key",
      "clientSecret": "your-client-secret",
      "refreshToken": "grower-refresh-token",
      "clientEnvironment": "PRODUCTION"
  }

  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}/claas-credentials'
  const headers = { 'Authorization': `Bearer ${TOKEN}` }

  const data = {
      "clientKey": "your-client-key",
      "clientSecret": "your-client-secret",
      "refreshToken": "grower-refresh-token",
      "clientEnvironment": "PRODUCTION"
  }

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

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

## Credentials schema

**Create request body:**

| Field               | Type   | Required | Description                                             |
| ------------------- | ------ | -------- | ------------------------------------------------------- |
| `clientKey`         | string | Yes      | Your application's client key from CLAAS                |
| `clientSecret`      | string | Yes      | Your application's client secret                        |
| `refreshToken`      | string | Yes      | The grower's OAuth refresh token                        |
| `clientEnvironment` | string | No       | `STAGE` or `PRODUCTION`. Defaults to `STAGE` if omitted |

**Response:**

```json theme={null}
{
  "id": "uuid",
  "status": "str",
  "createdTime": "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'",
  "clientKey": "str",
  "clientSecret": "str",
  "refreshToken": "str",
  "clientEnvironment": "PRODUCTION"
}
```

## Endpoints

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

| Action                | Method | Path                                           |
| --------------------- | ------ | ---------------------------------------------- |
| Get credentials       | GET    | `/users/{leafUserId}/claas-credentials`        |
| Create credentials    | POST   | `/users/{leafUserId}/claas-credentials`        |
| Delete credentials    | DELETE | `/users/{leafUserId}/claas-credentials`        |
| Get credential events | GET    | `/users/{leafUserId}/claas-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}/claas-credentials/events'
  ```

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

  TOKEN = 'YOUR_TOKEN'
  endpoint = 'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/claas-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}/claas-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 or the refresh token expired. Have the grower re-authorize through the CLAAS OAuth flow.
* **STAGE vs. PRODUCTION mismatch**: Make sure `clientEnvironment` matches the environment your CLAAS app is registered in. If omitted, Leaf defaults to `STAGE`.

## What to do next

* [Provider Authentication Overview](/providers/overview) — How provider credentials work across all providers.
* [API Reference: Providers](/api-reference/providers) — Full endpoint reference for provider credentials.
