PTx has two API platforms. This tutorial covers connecting FarmEngage without an existing Trimble Agriculture connection. If you already have Trimble Agriculture connections, use Migrate from Trimble to FarmEngage. Attaching
farm-engage-credentials beside trimble-credentials duplicates fields and files until you remove the Trimble credential. For the legacy Trimble API itself, see Connect Trimble.Before you start
- A Leaf account with a valid API token.
- An existing Leaf user.
- FarmEngage API access from PTx. Submit PTx’s API request form. PTx sends an AGCO Client ID and Client Secret after approval.
- Your FarmEngage application’s redirect URL registered with PTx. It must match
client_redirect_url/redirect_urlexactly, including trailing slashes. - PTx API docs for the data plane: api-docs.farmengage.com.
Step 1: Get the authorization URL
Leaf constructs the FarmEngage (AGCO ID) OAuth URL for you. The helper lives on the same host as the Trimble helper, under a/farmengage prefix:
{ "url": "..." }. That URL sends the grower to AGCO ID (onelogin.agcocorp.com) with the b2c_1a_signin_ptx policy.
The redirect URL must match what PTx authorized for your application. Trailing slashes can cause failures.
pass_through string and persist it with the grower session. Leaf uses it as the OAuth state value. If the returned state query parameter does not match, reject the callback. If you omit pass_through, the helper generates one and you cannot verify the callback.
Redirect the grower to the returned URL. That URL sends them to AGCO ID sign-in only. Organization access is a separate FarmEngage ThirdPartyAccess step, not part of the OAuth URL. After attaching credentials, always GET /users/{leafUserId}/organizations/FarmEngage. If connectedOrganizations is empty, send the grower the managementUri from that response — that is the required grant step. See provider organizations.
After authorization, FarmEngage redirects to your client_redirect_url with a code parameter.
Step 2: Exchange the code for tokens
code can be the raw authorization code or the full callback URL the grower landed on (the helper extracts code= from URLs that start with http).
You only need refresh_token for the next step. Leaf refreshes the access token itself.
Step 3: Attach credentials to the Leaf user
accessToken. Leaf confirms the credential by refreshing the token and calling the organization list in FarmEngage. After that, Leaf handles token refresh automatically.
Step 4: Confirm the credentials and organizations
connectedOrganizations is empty, send the grower the managementUri from that response so they can grant your app access.
What you built
You connected FarmEngage to a Leaf user. After at least one organization is authorized, Leaf syncs field boundaries, machine files, and field operations from PTx FarmEngage. Query fields, machine files, and field operations through the Leaf API and filter with?provider=FarmEngage. See How FarmEngage data appears in Leaf’s APIs and the field operations tutorial.
For the credentials schema and management endpoints, see the FarmEngage provider guide and the provider credentials API reference.
