This tutorial walks through connecting Climate FieldView to Leaf so you can sync field boundaries, machine files, and field operations. You’ll obtain developer credentials, run the OAuth flow, and attach the resulting provider credentials to a Leaf user.
Magic Link and Leaf Link handle the OAuth UI for you. This tutorial is for developers building the flow into their own application.
Before you start
- A Leaf account with a valid API token.
- A Leaf user created.
- A Climate FieldView developer account. Register at dev.fieldview.com.
- After approval, you’ll receive a
clientId, clientSecret, and apiKey.
Before proceeding, email developer@climate.com to verify you have the correct scopes: asHarvested:read, asPlanted:read, asApplied:read, fields:read, resourceOwners:read, farmOrganizations:read.
Step 1: Get the authorization URL
Leaf constructs the OAuth URL for you. Send a POST to the Climate FieldView credentials endpoint:
curl -X POST "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials" \
-H "Authorization: Bearer YOUR_LEAF_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"client_id": "your-cfv-client-id",
"redirect_uri": "https://your-app.com/callback"
}'
Leaf returns a URL with the minimum required scopes. If you need write access (for prescriptions, soil data, or imagery upload), add a scope array to the request body:
{
"client_id": "your-cfv-client-id",
"scope": [
"asHarvested:read", "asPlanted:read", "asApplied:read",
"fields:read", "resourceOwners:read", "farmOrganizations:read",
"fields:write", "rx:write", "soil:write", "imagery:write"
],
"redirect_uri": "https://your-app.com/callback"
}
The write scopes (fields:write, rx:write, soil:write, imagery:write) may require additional permissions from Climate FieldView. Confirm you’re allowed to request them before generating a URL with them.
Redirect the grower to the returned URL. After authorization, Climate FieldView redirects back to your redirect_uri with a code parameter.
Step 2: Exchange the code for tokens
POST to Climate FieldView’s token endpoint with the code from the redirect:
curl -X POST "https://api.climate.com/api/oauth/token" \
-H "Authorization: Basic $(echo -n 'clientId:clientSecret' | base64)" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=THE_CODE_FROM_REDIRECT&redirect_uri=https://your-app.com/callback&grant_type=authorization_code"
Save the refresh_token.
Step 3: Attach credentials to the Leaf user
curl -X POST "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials" \
-H "Authorization: Bearer YOUR_LEAF_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"clientId": "your-cfv-client-id",
"clientSecret": "your-cfv-client-secret",
"apiKey": "your-cfv-api-key",
"refreshToken": "the-refresh-token-from-step-2"
}'
Leaf manages token refresh automatically from this point.
Step 4: Confirm the credentials are attached
curl "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/climate-field-view-credentials" \
-H "Authorization: Bearer YOUR_LEAF_TOKEN"
If this worked, Leaf returns the Climate FieldView credential object for the Leaf user.
What you built
You connected Climate FieldView to a Leaf user through the OAuth flow. Leaf now syncs field boundaries, machine files, and field operations from Climate FieldView. Query the data through the field operations quickstart or the machine files API.
For the credentials schema and management endpoints, see the Climate FieldView provider guide and the provider credentials API reference.