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

# Migrate from CNHI AFS Connect to CNHI FieldOps

> Move your existing CNHI (AFS Connect) integration to CNHI FieldOps. Covers what changed, new credentials setup, and running both providers in parallel.

This guide covers how to migrate an existing CNHI (AFS Connect) integration to CNHI FieldOps. You can migrate at your own pace — both providers run in parallel, and no growers are disrupted until you choose to switch them.

## What changed

CNHI FieldOps is CNH Industrial's current API platform. The data you receive through Leaf — field operations, machine files, boundaries — is the same. What changes is how the connection is established.

| Aspect                               | CNHI (AFS Connect)                 | CNHI FieldOps                               |
| ------------------------------------ | ---------------------------------- | ------------------------------------------- |
| Leaf credential path                 | `cnhi-credentials`                 | `cnhi-field-ops-credentials`                |
| Leaf OAuth helper                    | `/get_url`, `/get_token`           | `/fieldops/get_url`, `/fieldops/get_token`  |
| Magic Link / Leaf Link provider name | `CNHI`                             | `CNHIFieldOps`                              |
| Subscription keys                    | Legacy keys                        | New keys required (legacy keys do not work) |
| Change detection                     | Polling (Leaf checks periodically) | Webhooks (CNH pushes changes to Leaf)       |
| Token format                         | Opaque                             | JWT                                         |

The FieldOps API also supports webhook-based change notifications. Instead of Leaf polling CNH on a schedule, CNH pushes events to Leaf when new data is available. This reduces the delay between when a grower uploads data from their equipment and when Leaf processes it.

## What you need before migrating

* A CNH developer account at [develop.cnh.com](https://develop.cnh.com/) (company-domain email required — Gmail, Hotmail, and other generic domains are not supported).
* A new FieldOps application registered in the developer portal. This produces a new `clientId`, `clientSecret`, and `subscriptionKey`. Existing CNHI credentials cannot be reused.
* Each grower must re-authorize through the FieldOps OAuth flow. Existing refresh tokens do not carry over.
* Growers must have the **Farm Manager** title in their FieldOps account and must have [logged into the FieldOps portal](https://develop.cnh.com/get-started/fieldops-portal) at least once.

## Migration approach: run both in parallel

Leaf treats CNHI and CNHI FieldOps as separate providers. A single Leaf user can hold both `cnhi-credentials` and `cnhi-field-ops-credentials` at the same time. This means you can migrate growers one at a time without disrupting anyone.

The recommended approach:

1. Register your CNHI FieldOps app keys with Leaf:

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"clientId": "your-fieldops-client-id", "clientSecret": "your-fieldops-secret", "subscriptionKey": "your-fieldops-key"}' \
  "https://api.withleaf.io/services/usermanagement/api/app-keys/CNHIFieldOps/your-app-name/PRODUCTION"
```

2. For each grower you want to migrate:
   * Run the FieldOps OAuth flow (via the [Leaf helper](/guides/tutorials/connect-cnhi-fieldops) or [Magic Link](/components/magic-link))
   * Attach `cnhi-field-ops-credentials` to the Leaf user
   * Verify data syncs correctly
   * Once confirmed, delete the old `cnhi-credentials` from the Leaf user

3. Growers you haven't migrated yet continue working on the legacy CNHI provider with no disruption.

<Warning>
  While both credentials are attached, Leaf syncs from both providers. This may produce duplicate fields or files until you remove the old credential. We recommend verifying the FieldOps connection, then promptly deleting the legacy credential.
</Warning>

### Identifying FieldOps data in the API

Data from CNHI FieldOps appears in the same Leaf endpoints (fields, files, operations) as legacy CNHI data. The `provider` field distinguishes the source:

* Legacy CNHI: `"provider": "CNHI"`
* CNHI FieldOps: `"provider": "CNHIFieldOps"`

You can filter queries by provider (e.g., `?provider=CNHIFieldOps`) to see only FieldOps data. During the parallel-run period, the same physical field may appear twice with different `provider` values.

## Abbreviated setup steps

For the full walkthrough with code examples in cURL, Python, and JavaScript, see [Connect CNHI FieldOps](/guides/tutorials/connect-cnhi-fieldops). The key steps:

1. **Get the authorization URL** — `POST https://cnhi-oauth2-helper.withleaf.io/fieldops/get_url` with `client_id`, `client_redirect_url`, and `production` flag.
2. **Redirect the grower** — they log in and consent.
3. **Exchange the code for a refresh token** — `POST https://cnhi-oauth2-helper.withleaf.io/fieldops/get_token` with `client_id`, `client_secret`, `client_redirect_url`, and `response_url`.
4. **Attach credentials to the Leaf user** — `POST /users/{leafUserId}/cnhi-field-ops-credentials` with `clientId`, `clientSecret`, `subscriptionKey`, `refreshToken`, and `clientEnvironment`.
5. **Confirm** — `GET /users/{leafUserId}/cnhi-field-ops-credentials`.

## Updating Magic Link and Leaf Link

If you use Magic Link or Leaf Link widgets to onboard growers:

1. Register your FieldOps app keys with Leaf:

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"clientId": "your-fieldops-client-id", "clientSecret": "your-fieldops-secret", "subscriptionKey": "your-fieldops-key"}' \
  "https://api.withleaf.io/services/usermanagement/api/app-keys/CNHIFieldOps/your-app-name/PRODUCTION"
```

2. Add `https://widget.withleaf.io` as a callback URL in your CNHI FieldOps application on the [CNH developer portal](https://develop.cnh.com/).

3. Update your `allowedProviders` to include `"CNHIFieldOps"`. During the transition, you can include both `"CNHI"` and `"CNHIFieldOps"` so growers can connect through either provider.

## What to do next

* [CNHI FieldOps provider guide](/providers/cnhi-fieldops) — Credentials schema, endpoints, and troubleshooting.
* [Connect CNHI FieldOps tutorial](/guides/tutorials/connect-cnhi-fieldops) — Full step-by-step with code examples.
* [Provider credentials API reference](/api-reference/providers) — Endpoint reference for all providers.
