Skip to main content
This tutorial walks through connecting CNHI FieldOps to Leaf so you can sync field boundaries, machine files, and field operations from Case IH and New Holland equipment. You’ll create a developer application, run the OAuth flow to get user tokens, and attach provider credentials to a Leaf user.
Magic Link and Leaf Link handle the OAuth UI for you. This tutorial covers the manual flow for developers building it into their own application.
CNH Industrial has two API platforms. This tutorial covers CNHI FieldOps (the current platform). For the legacy AFS Connect API, see Connect CNHI (AFS Connect).

Before you start

  • A Leaf account with a valid API token.
  • A Leaf user created.
  • A CNH developer account registered with a company-domain email (Gmail, Hotmail, and other generic domains are not supported). Register at develop.cnh.com.

Step 1: Create a CNHI FieldOps application

  1. Sign in to the CNH developer portal (or create an account if you don’t have one).
  2. Navigate to Account, then select My Applications in the left-hand menu.
  3. Click Add New Application.
  4. Fill out the Application Information form:
    • Application Name — a label for your integration (e.g., “My Company - Leaf Integration”).
    • Portal — select FieldsOps Portal.
    • Region — select the region your growers operate in.
    • OAuth Callback URL(s) — enter the URL where CNHI should redirect growers after they authorize. If you’re using Magic Link or Leaf Link, enter https://widget.withleaf.io. If you’re building your own OAuth flow, enter your application’s callback URL (the same URL you’ll pass as client_redirect_url in Step 2).
    • Fill in the remaining required fields (description, icon, contact info) and click Submit.
  5. Once the application is created, go to My Applications, click your application name, then find your Client ID, Client Secret, and Subscription Key in the API Information section.
These credentials are specific to the FieldOps API. Existing CNHI (AFS Connect) credentials will not work. You must create a new application in the developer portal.

Step 2: Get the authorization URL

Leaf provides a helper that constructs the CNHI FieldOps authorization URL:
curl -X POST "https://cnhi-oauth2-helper.withleaf.io/fieldops/get_url" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "your-cnhi-client-id",
    "client_redirect_url": "https://your-app.com/callback",
    "production": false
  }'
Set production to false for the CNHI staging environment (the default for new apps). Set it to true once your app is promoted to production.
While in the CNHI staging environment, only staging test accounts work. Production customer accounts won’t authenticate. The reverse is true in production.
Redirect the grower to the returned URL. After authorization, CNHI redirects to your client_redirect_url with a code in the URL.

Step 3: Exchange the code for a refresh token

curl -X POST "https://cnhi-oauth2-helper.withleaf.io/fieldops/get_token" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "your-cnhi-client-id",
    "client_secret": "your-cnhi-client-secret",
    "response_url": "https://your-app.com/callback?code=abc123",
    "client_redirect_url": "https://your-app.com/callback"
  }'
The response_url is the full URL the grower was redirected to, including the code parameter that CNHI appended.

Step 4: Attach credentials to the Leaf user

curl -X POST "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/cnhi-field-ops-credentials" \
  -H "Authorization: Bearer YOUR_LEAF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "clientId": "your-cnhi-client-id",
    "clientSecret": "your-cnhi-client-secret",
    "subscriptionKey": "your-cnhi-subscription-key",
    "refreshToken": "the-refresh-token-from-step-3",
    "clientEnvironment": "STAGE"
  }'
Set clientEnvironment to PRODUCTION once your CNHI FieldOps application is promoted to production. Leaf handles token refresh automatically.

Step 5: Confirm the credentials are attached

curl "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/cnhi-field-ops-credentials" \
  -H "Authorization: Bearer YOUR_LEAF_TOKEN"
If this worked, Leaf returns the CNHI FieldOps credential object for the Leaf user.

What you built

You connected CNHI FieldOps to a Leaf user. Leaf now syncs field boundaries, machine files, and field operations from Case IH and New Holland equipment. Query the data through the field operations endpoints. For the credentials schema and management endpoints, see the CNHI FieldOps provider guide and the provider credentials API reference.
Last modified on April 13, 2026