Tutorial

John Deere authentication with Leaf

How to connect with John Deere via Leaf's API



Leaf’s API is the easiest way to build with farm 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.

Here is a link to Leaf’s website

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.

In this post, we are going to show you how to easily go through John Deere authorization flow with Leaf, that is, get authorized to access your users’ John Deere data with Leaf. We’ll be making some calls to Leaf, all endpoints can be found in our docs and Postman collection. Let's get to it!

Summary

  • Step 0: Create a developer account with John Deere
  • Step 1: Get your John Deere developer credentials
  • Step 2: Get permission from John Deere to access the endpoints 
  • Step 3: Get your users’ John Deere tokens with Leaf
  • Step 4: Get permission to access your user’s data
  • Step 5: Add John Deere 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 John Deere

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

Creating a John Deere 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: Get your John Deere developer credentials

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

  • your App ID and Shared Secret

Retrieve your John Deere App ID and Shared Secret

First, you have to login in your John Deere developer account. To do this, go to https://developer.deere.com/, and click Sign In (top right corner) and log in. 

https://developer.deere.com/

Click in “My Applications” in the horizontal bar:

Then, click "Add Application" and create a new application.

Once it’s created, click on “View Details”:

Finally, get an App ID and Secret:

Awesome! Now you have your John Deere App ID and Shared Secret. You will use them in the next step.

Step 2: Get permission from John Deere to access the endpoints

By default, John Deere gives your application access to a limited set of endpoints. Before Leaf is able to fetch operations data, you have to ask John Deere permission to access the endpoints. On John Deere’s landing page, https://developer.deere.com/, click “Contact Us”, in the bottom corner. There, select “API Access Request”, and a form will appear.

Fill the required information in the form, and submit it to John Deere. In the Available APIs field, enter Field Operations. On Description, also ask permission to access Machines, and POST to Fields and Boundaries as well.

John Deere will contact you soon so you can have access to the required endpoints.

Step 3: Get your users’ John Deere tokens with Leaf

To get your users' tokens to access their John Deere data, your application must go through John Deere OAuth flow. First, you need to redirect the user to a custom URL that is the John Deere page that will present the user the choice of authorizing your app to access their data.

To get the URL for this authentication step, just send a POST to

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

with the following JSON:

Leaf will return you a URL that you can send your user to, so they can authorize access to their data and be redirected to your app. Note that John Deere will redirect your user to the "client_redirect_url" and also send a code that you will need to make a final request and get your users' tokens. The client_redirect_url must be set in your app’s configuration.

Get the user’s tokens

Now, the last thing needed is to get the user’s tokens. Once users log in on John Deere's website link you created, they will authorize your application to access their data and they will be redirected back to the "client_redirect_url" you set. Then, your application will use the response URL to get the user’s tokens. Just send a POST to

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

with the following JSON:

 

A JSON containing the tokens ("access_token" and"refresh_token") will be returned, and you can add them to Leaf as John Deere credentials.

note: Leaf will manage each and every token, making sure they are always refreshed and valid.

Step 4: Get permission to access your user’s data

Now that the user is connected to your application, the user must allow you to access the data. To do so, redirect your user to the following URL:

https://connections.deere.com/connections/yourJohnDeereAppId/select-organizations?redirect_uri=yourRedirectUrl

Replace the required URL fields with your John Deere Application ID and the redirect url of your application. The redirect URL does not need to be the same as the one used in the previous step, as long as it is also registered in your app’s configuration. Your user will be redirected to the following screen:

In this screen the users will select the organizations they want to share data with you, toggle the button so it’s green, and save. Leaf will only be able to fetch data from allowed organizations. After that, the users will be redirected to the specified redirect URL.

Step 5: Add John Deere credentials to Leaf

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. John Deere Operations Center or Climate Field View platform).

Leaf’s API must then be initiated with John Deere credentials in order to access and standardize John Deere 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/john-deere-credentials

with the following Header


and with the following JSON

Excellent!

Now Leaf will start fetching your farm data from John Deere. You can now query Leaf for your standardized data.

See ya!

Similar posts

Stay in the loop with all of Leaf's future insights, technical updates and latest case studies.

Subscribe to receive our monthly newsletter and newest blog posts with industry leading insights, company updates and more.