Skip to main content
Leaf connects to AgLeader using OAuth 2.0 with public/private key pairs. Once connected, Leaf syncs machine files and field operations for the Leaf user.

Prerequisites

  1. An AgLeader developer account. Create an account.
  2. Your application’s publicKey and privateKey from AgLeader.
  3. A grower’s refreshToken obtained through the AgLeader OAuth consent flow.

Setup steps

  1. Complete the AgLeader OAuth flow to obtain a refreshToken for the grower’s account.
  2. POST the credentials to Leaf:
curl -X POST \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
      "refreshToken": "grower-refresh-token",
      "publicKey": "your-public-key",
      "privateKey": "your-private-key"
    }' \
    'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/ag-leader-credentials'
  1. Leaf validates the token and begins syncing. Check credential status with GET /users/{leafUserId}/ag-leader-credentials.

Credentials schema

Create request body:
FieldTypeRequiredDescription
refreshTokenstringYesThe grower’s refresh token
publicKeystringYesYour application’s public key from AgLeader
privateKeystringYesYour application’s private key from AgLeader
Response:
{
  "id": "uuid",
  "status": "str",
  "createdTime": "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'",
  "accessToken": "str",
  "refreshToken": "str",
  "publicKey": "str",
  "privateKey": "str"
}

Endpoints

Base URL: https://api.withleaf.io/services/usermanagement/api
ActionMethodPath
Get credentialsGET/users/{leafUserId}/ag-leader-credentials
Create credentialsPOST/users/{leafUserId}/ag-leader-credentials
Delete credentialsDELETE/users/{leafUserId}/ag-leader-credentials
Get credential eventsGET/users/{leafUserId}/ag-leader-credentials/events

Troubleshooting

Use the events endpoint to inspect credential health:
curl -X GET \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    'https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/ag-leader-credentials/events'
Event logs are retained for 30 days. Once the credential is deleted or disassociated from the Leaf user, the logs are no longer available.
Common issues:
  • Status changes to invalid: The grower may have revoked access or tokens expired. Have the grower re-authorize through the AgLeader OAuth flow.
  • Key mismatch: Verify that the publicKey and privateKey are from the same AgLeader application registration.

What to do next

Last modified on March 19, 2026