Snippets
Here is some request samples
The node, ruby and python snippets require third-party libraries:
- node: node-fetch library.
- python: request library.
- ruby: HTTParty library.
Genus
Get all genus
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/genus?token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/genus?token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/genus?token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/genus',
query: {
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Plants & Species
In all the following samples, /plants can be switched to /species and /species can be switched to /plants.
The only difference is that /species API calls will return matching species, subspecies, varieties etc..., and /plants API calls will only return main species (without all the children species).
Get all plants
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/plants?token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/plants?token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/plants?token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/plants',
query: {
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get all species
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/species?token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/species?token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/species?token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/species',
query: {
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get only edible plants
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/plants?filter_not%5Bedible_part%5D=null&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/plants?filter_not%5Bedible_part%5D=null&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/plants?filter_not%5Bedible_part%5D=null&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/plants',
query: {
"filter_not": {
"edible_part": "null"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get tallest trees
- Get all plants
- With tree ligneous type
filter[ligneous_type]=tree - Without plants with no maximum height
filter_not[maximum_height_cm]=null - Ordered by maximum height descending (highest first)
order[maximum_height_cm]=desc
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/plants?filter_not%5Bmaximum_height_cm%5D=null&filter%5Bligneous_type%5D=tree&order%5Bmaximum_height_cm%5D=desc&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/plants?filter_not%5Bmaximum_height_cm%5D=null&filter%5Bligneous_type%5D=tree&order%5Bmaximum_height_cm%5D=desc&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/plants?filter_not%5Bmaximum_height_cm%5D=null&filter%5Bligneous_type%5D=tree&order%5Bmaximum_height_cm%5D=desc&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/plants',
query: {
"filter_not": {
"maximum_height_cm": "null"
},
"filter": {
"ligneous_type": "tree"
},
"order": {
"maximum_height_cm": "desc"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get plants recorded in France
Zone slugs are the lowercased WGSRPD codes:
frais France. See Distributions to learn more about distribution zones.
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions/fra/plants?token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions/fra/plants?token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions/fra/plants?token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions/fra/plants',
query: {
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get plants introduced in Marion-Prince Edward
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions/mpe/plants?filter%5Bestablishment%5D=introduced&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions/mpe/plants?filter%5Bestablishment%5D=introduced&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions/mpe/plants?filter%5Bestablishment%5D=introduced&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions/mpe/plants',
query: {
"filter": {
"establishment": "introduced"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get plants native to Tibet
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions/cht/plants?filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions/cht/plants?filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions/cht/plants?filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions/cht/plants',
query: {
"filter": {
"establishment": "native"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get species with a maximum height between 5 cm and 20 cm
On this endpoint the upper bound is excluded (5 ≤ height < 20). See how the bounds are read.
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/species?range%5Bmaximum_height_cm%5D=5%2C20&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/species?range%5Bmaximum_height_cm%5D=5%2C20&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/species?range%5Bmaximum_height_cm%5D=5%2C20&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/species',
query: {
"range": {
"maximum_height_cm": "5,20"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get full-sun species under one metre, native to France
lightis an Ellenberg class from 1 to 9;range[light]=7keeps classes 7 to 9. Explained step by step in the filtering guide.
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions/fra/species?range%5Blight%5D=7&range%5Bmaximum_height_cm%5D=%2C100&filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions/fra/species?range%5Blight%5D=7&range%5Bmaximum_height_cm%5D=%2C100&filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions/fra/species?range%5Blight%5D=7&range%5Bmaximum_height_cm%5D=%2C100&filter%5Bestablishment%5D=native&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions/fra/species',
query: {
"range": {
"light": "7",
"maximum_height_cm": ",100"
},
"filter": {
"establishment": "native"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get species with red flowers
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/species?filter%5Bflower_color%5D=red&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/species?filter%5Bflower_color%5D=red&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/species?filter%5Bflower_color%5D=red&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/species',
query: {
"filter": {
"flower_color": "red"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get search for coconut species
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/species/search?q=coconut&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/species/search?q=coconut&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/species/search?q=coconut&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/species/search',
query: {
"q": "coconut",
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get species with oldest discoveries first
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/species?order%5Byear%5D=asc&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/species?order%5Byear%5D=asc&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/species?order%5Byear%5D=asc&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/species',
query: {
"order": {
"year": "asc"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Zones & Distributions
See Distributions to learn more about distributions zones.
Get all countries / zones
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions?token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions?token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions?token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions',
query: {
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response
Get countries / zones with less than 10 species
- CURL
- Browser
- NodeJS
- Python
- Ruby
curl -X GET "https://trefle.io/api/v1/distributions?range%5Bspecies_count%5D=%2C10&token=YOUR_TREFLE_TOKEN"
const fetch = require('node-fetch');
(async () => {
const response = await fetch('https://trefle.io/api/v1/distributions?range%5Bspecies_count%5D=%2C10&token=YOUR_TREFLE_TOKEN');
const json = await response.json();
console.log(json);
})();
import requests
r = requests.get('https://trefle.io/api/v1/distributions?range%5Bspecies_count%5D=%2C10&token=YOUR_TREFLE_TOKEN')
r.json()
require 'httparty'
r = HTTParty.get(
'https://trefle.io/api/v1/distributions',
query: {
"range": {
"species_count": ",10"
},
"token": "YOUR_TREFLE_TOKEN"
}
)
r.parsed_response