Technical API Docs
What you need to know before you start
The FarmTree Tool is a tool that can be used to predict the outcomes of farming scenarios, by creating projections for a wide range of metrics. With the API you can send scenarios to the Tool (and receive projections in return) without using our FarmTree Tool interface. That way you can integrate the Tool functionality in your own platform.
The system follows a secure authentication workflow and provides multiple endpoints for managing agricultural data. Users require a license for the FarmTree platform that includes API access. The license is connected to a team, and a team has access to specific collections of agricultural components and default parameters.
The base-URL for the endpoints is: https://tool.farmtree.earth, and the endpoints are well documented using Swagger: https://tool.farmtree.earth/swagger/index.html.
Basic experience with the FarmTree Tool is assumed, it will help you understand what a farming scenario consists of. In the bottom section of this documentation, there are some notes on how to collect the data for a scenario, as well as Python code examples.
Authentication
Initial Login
Users authenticate to the system using the /Api/Login endpoint (POST method). This endpoint requires sending a username and password as credentials. Upon successful authentication, the system returns two critical tokens:
- Access Token: A short-lived token valid for 15 minutes used for all subsequent API calls
- Refresh Token: A longer-lived token valid for 3 days used to obtain new access tokens without re-entering credentials
Token Management
To maintain continuous access to the system, users can refresh their authentication using the /Api/RefreshToken endpoint (POST method). This endpoint requires the user's email address and the refresh token obtained during initial login. The system responds with a new set of tokens, extending the user's access.
Session Termination
Users can explicitly log out using the /Api/Logout endpoint (DELETE method), which invalidates the current session.
Data Access
Dataset Management
The system organizes agricultural data into datasets accessible through the /Api/Datasets endpoint (GET method). Datasets contain collections of agricultural components including trees, crops, and farming inputs that users can incorporate into their scenarios. As mentioned above, your license is connected to a team (or organization), and a team has access to one or more datasets.
Team and Region Configuration
Users can access team information via /Api/Teams (GET method) and retrieve regional data specific to a team using /Api/Teams/Regions (GET method). This hierarchical structure allows organizations to manage regional pricing data.
Detailed documentation on the end points and schemas is available on https://tool.farmtree.earth/swagger/index.html.
Scenario Planning
Available parameters
Before creating agricultural scenarios, users can retrieve available planning parameters using /Api/Tool (GET method). This endpoint provides information about available agricultural components (trees, crops, inputs) of a dataset, and default settings for a specific team and pricing region combination.
Scenario data includes:
- Selected agricultural components (trees, crops, inputs)
- Plot characteristics (location, soil properties, climate settings)
- Financial parameters (wages, subsidies, interest rates)
- Project timeline and management settings
Detailed documentation is available on https://tool.farmtree.earth/swagger/index.html under the 'PlotScenario' schema.
Another way to compose a scenario, and this may be easier the first time, is to create a scenario in the FarmTree Tool on the platform (https://tool.farmtree.earth/Tool), and use the export management section to download it as a JSON scenario for the API. Be sure to add at least one coordinate for the plot location of the scenario, though.
Further notes on how to collect data for a farming scenario can be found in the bottom section of this documentation.
Scenario Execution
The core functionality involves running agricultural simulations through the /Api/Tool (POST method) endpoint. Users submit a scenario in the body of the POST request.
The system processes this information and returns detailed analysis results including time-series data on performance metrics and economic projections. Detailed documentation on the result is available on https://tool.farmtree.earth/swagger/index.html under the 'ToolModelDto' schema.
Security Requirements
All API endpoints except the login endpoints require bearer token authentication using the short-lived access token obtained during login. The token must be included in the Authorization header of each request as "Bearer [token]".
API Response Handling
The system provides standardized error responses for authentication failures (403 Forbidden) and validation errors (400 Bad Request). Successful operations return relevant data structures containing the requested information or analysis results. See also https://tool.farmtree.earth/swagger/index.html under the 'ToolModelDto' schema.
Notes on collecting data for a FarmTree Scenario
In the PlotScenario schema on https://tool.farmtree.earth/swagger/index.html, you can see that a scenario is defined by many parameters. Some values you will have collected yourself, but on some others you may not have any information. Therefore, for many of the parameters our database provides default values you can use. Default values can be customized for your organization, and if you wish to do so, please contact our support team.
Let's consider the three types of parameters:
Plot settings
The plot settings are location specific settings, such as the size, slope and altitude, but also data on the climate or soil fertility. They define the "bare" plot.
Note on the climate data:
Make sure to add at least one GPS point to the PlotCoordinates, because the location will be used to collect climate data from our database. We have stored one of the CMIP6 climate data models available from the European Copernicus project. Unfortunately no climate model is accurate for all locations in the world, so we added options to correct or add your own precipitation and temperature data in the plot settings.
Note on the soil data:
Apart from the coordinates, for all other plot settings we provide default values. But of course the more specific and accurate the settings are, the better the resulting projections from the Tool. You can use a GPS point to retrieve other data such as the soil or terrain data.
In the Python code examples below, an API call to SoilGrids is included. This code not only retrieves the soil data that a scenario needs, it also converts the SoilGrids data into the units that we use in our Tool. If you have worked with our Tool interface on the FarmTree platform, you may have noticed that we make this API call to SoilGrids when you select a location. However, the SoilGrids API is not always available and (like for the climate) the data is not always accurate. That is why we do not try to retrieve the soil data for you when you call our API. You should fetch it, and if possible assess its accuracy yourself.
Agricultural components
By using the GET method on the Tool endpoint, you can collect the data on all available agricultural components, including their default values for planting and application practices. Examples of planting parameters are the 'planting density' or the 'planting month'. You can copy these default planting and application values when you add components to the scenario you wish to add in the POST request to the Tool. Planting and application parameters are required.
Apart from those parameters, we also provide many more options for a component (such as harvesting practices) under the so called 'modifications'. Values for modification do not need to be set unless you want to set them. In a scenario any modification parameter can be null, meaning you do not wish to override the default value.
Other settings
All other settings are more general project settings, such as the time span of the projections, the interest rate, or the CO2e price. If you do not provide these values, default values are used.
We hope this information helps you with the complex business of collecting enough data for a PlotScenario. But of course, do not hesitate to ask for support if you need any help.