Trimble Authentication with Leaf

How to connect with Trimble via Leaf

Trimble Authentication with Leaf

In this post, we are going to show you how to easily go through Trimble’s authorization flow with Leaf, that is, get authorized to access your users’ Trimble data with Leaf. All endpoints can be found in our docs and Postman collection.

Summary

  • Step 0: Create a developer account with Trimble
  • Step 1: Create Application and get your credentials
  • Step 2: Get the authentication code
  • Step 3: Get your users’ Trimble tokens with Leaf
  • Step 4: Add Trimble credentials to Leaf

Keep in mind that this tutorial is a full walkthrough. Most of the steps presented will be done only once, meaning that subsequent calls will be much easier and faster.

Step 0: Create a developer account with Trimble

(if you already have a developer account in Trimble, you can skip this step)

Creating a Trimble developer account is a very simple and automatic process, just register with this link.

After that, you will have created your developer account and can go to the next step of this tutorial.

Step 1: Create Application and get your credentials

At the end of this step, you want to have retrieved:

  • Your Application Name
  • Client ID
  • Client Redirect URL

You need to send an email to ag_api@trimble.com requesting API credentials for your application. Your email should include your application name and a brief description of what users do in your application. More info here.

Trimble will send you the Client ID and Client Secret after the approval process.

Step 2: Get the authentication code

Leaf’s API uses an abstraction called Leaf User to store credentials and organize data for each individual data owner. In most cases, the Leaf User will be the farmer or consultant that has access to the source data inside the machinery company’s FMIS (e.g. Trimble Connected Farm).

Leaf’s API must then be initiated with Trimble credentials in order to access and standardize Trimble data. To send your credentials to Leaf, you will need your access token from Leaf, and have already created a Leaf User. If you don’t know how to do that, here is how you get your access token, and here is how you create a Leaf User.

Note: the same Leaf User can be attached to many providers, so you can query data for that Leaf User from all the providers they have data at the same time.

To get your users' tokens to access their Trimble data, your application must go through Trimble OAuth flow. First, you need to make a POST to

https://trimble-oauth2-helper.withleaf.io/get_url

with the following Header:

When performing this POST, you will have the return of a URL. Open this link and you will be taken to the Trimble API if you are not already logged in. Otherwise, you will be automatically redirected to the Leaf blog home page. At this point, it is necessary to save the code contained in the page link. Something similar to this:

https://withleaf.io/?code=us_421860e1feed4be3a557323c2c8001fd&state=8tdWXu2pWGdwMYY26DTm-w

Step 3: Get your users’ Trimble tokens with Leaf

You will now get the access token and refresh token, which you can add to the Leaf as Trimble credentials.

This will be done through the link POST to

https://trimble-oauth2-helper.withleaf.io/get_token

with the following Header:

Step 4: Add Trimble credentials to Leaf

Leaf’s API must then be initiated with Trimble credentials in order to access and standardize Trimble data. To send your credentials to Leaf, you will need your access token from Leaf, and have already created a Leaf User. If you don’t know how to do that, here is how you get your access token, and here is how you create a Leaf User.

Note: the same Leaf User can be attached to many providers, so you can query data for that Leaf User from all the providers they have data at the same time.

Now, attach your credentials to the Leaf User you created. Send a POST to

https://api.withleaf.io/services/usermanagement/api/users/yourLeafUserId/trimble-credentials

with the following Header:

Great!

Leaf will now begin fetching your farm data from Trimble. You can now query Leaf for your standardized data.

Software developers use Leaf’s API to build and scale a wide range of products including farm optimization tools, lending products, outcome-based financing, land and input marketplaces, agronomic recommendations, traceability applications, equipment maintenance forecasting, and more.

At Leaf, we’re empowering developers working on food and farm problems. It begins with API access to field boundaries, precision agriculture data, and advanced satellite imagery.

Ready to begin?

Get API Keys and Start Building Today!

Sign up for free account

Questions? Get in touch