Skip to main content
This tutorial walks through connecting AgLeader’s AgFiniti platform to Leaf to sync machine files. You’ll get developer credentials, run the OAuth flow to obtain 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.

Before you start

AgLeader requires proof of liability insurance and a one-time fee before providing developer credentials.

Step 1: Get your AgLeader credentials

Log in to AgFiniti, navigate to the Consumer Keys tab, and note your:
  • Public Key
  • Private Key
Configure the Redirection URL(s) on the application page to include the callback URL that will receive the authorization code.

Step 2: Get the authorization code

Redirect the grower to the AgFiniti authorization URL. Replace {your_public_key} and {redirect_uri} with your values:
https://www.agfiniti.com/Account/Authorize?response_type=code&client_id={your_public_key}&redirect_uri={redirect_uri}&scope=read%20readwrite
This URL includes the read and readwrite scopes required for Leaf integration. If you plan to upload prescriptions, add the fileupload scope. After the grower authenticates, AgFiniti redirects to your redirect_uri with a code parameter.

Step 3: Exchange the code for tokens

POST the code to AgFiniti’s token endpoint. The Authorization header requires Base64-encoded publicKey:privateKey:
curl -X POST "https://www.agfiniti.com/api/token" \
  -H "Authorization: Basic $(echo -n 'yourPublicKey:yourPrivateKey' | base64)" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code&code=THE_CODE_FROM_REDIRECT&redirect_uri=https://your-app.com/callback"
Save the refresh_token.

Step 4: Attach credentials to the Leaf user

curl -X POST "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/ag-leader-credentials" \
  -H "Authorization: Bearer YOUR_LEAF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "publicKey": "your-agleader-public-key",
    "privateKey": "your-agleader-private-key",
    "refreshToken": "the-refresh-token-from-step-3"
  }'
Leaf manages token refresh and begins syncing machine files. AgLeader currently supports machine file data only (no direct field boundary sync).

Step 5: Confirm the credentials are attached

Check the stored credentials for the Leaf user:
cURL
curl "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/ag-leader-credentials" \
  -H "Authorization: Bearer YOUR_LEAF_TOKEN"
If this worked, Leaf returns the AgLeader credential object for that user.

What you built

You connected AgLeader AgFiniti to a Leaf user. Leaf now fetches and standardizes machine files from AgFiniti. Query the data through the machine files API and field operations quickstart. For the credentials schema and management endpoints, see the AgLeader provider guide and the provider credentials API reference.
Last modified on March 24, 2026