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

# Valley

> Connect to Valley irrigation systems to pull irrigation activity data through Leaf's provider credentials API.

Leaf connects to Valley irrigation systems using API credentials. Once connected, Leaf syncs irrigation activity data for the Leaf user.

## Prerequisites

1. A Valley account with API access.
2. Your Valley API credentials: `apid`, `initializationVector`, `key`, `username`, and `password`.

## Credentials schema

| Field                  | Type   | Required | Description                                   |
| ---------------------- | ------ | -------- | --------------------------------------------- |
| `apid`                 | string | Yes      | Your Valley application ID.                   |
| `initializationVector` | string | Yes      | Initialization vector for API authentication. |
| `key`                  | string | Yes      | API key.                                      |
| `username`             | string | Yes      | Valley account username.                      |
| `password`             | string | Yes      | Valley account password.                      |

## Endpoints

| Method | Path                                            | Description                                |
| ------ | ----------------------------------------------- | ------------------------------------------ |
| GET    | `/users/{leafUserId}/valley-credentials`        | Get stored credentials.                    |
| POST   | `/users/{leafUserId}/valley-credentials`        | Create credentials.                        |
| DELETE | `/users/{leafUserId}/valley-credentials`        | Delete credentials.                        |
| GET    | `/users/{leafUserId}/valley-credentials/events` | Get credential events for troubleshooting. |

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

### Create credentials

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
      "apid": "your-apid",
      "initializationVector": "your-iv",
      "key": "your-key",
      "username": "your-username",
      "password": "your-password"
    }' \
    'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/valley-credentials'
  ```

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

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

  payload = {
      "apid": "your-apid",
      "initializationVector": "your-iv",
      "key": "your-key",
      "username": "your-username",
      "password": "your-password",
  }

  response = requests.post(endpoint, headers=headers, json=payload)
  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}/valley-credentials";
  const headers = { Authorization: `Bearer ${TOKEN}` };

  const payload = {
    apid: "your-apid",
    initializationVector: "your-iv",
    key: "your-key",
    username: "your-username",
    password: "your-password",
  };

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

### Response

```json theme={null}
{
  "id": "uuid",
  "status": "OK",
  "createdTime": "2026-01-15T12:00:00.000000Z",
  "apid": "your-apid",
  "key": "your-key",
  "initializationVector": "your-iv",
  "username": "your-username"
}
```

## Troubleshooting

Use the events endpoint to check credential health. Events are retained for 30 days and are deleted when the credential is removed.

```
GET /users/{leafUserId}/valley-credentials/events
```

## What to do next

* [Irrigation Overview](/irrigation/overview) for details on Lindsay and Valley irrigation data.
* [API Reference: Providers](/api-reference/providers) for the full credential path matrix.
