Closed paula-yano closed 4 years ago
Are there any examples of how to use this API for a beginner like myself? I could really use the help!
As someone who's just gotten started with Trefle, there's not much to getting started: 1- create an account to get your "Access token" 2- then review the documentation to determine the url to use to get the information you want
For example:
Once you have your access token you can use it directly in your browser url bar like so: https://trefle.io/api/species?q=achillea%20borealis&token=YOUR-TOKEN-HERE
This will get you a JSON string of all results that match Achillea borealis.
To get more details on Achillea borealis, you have to look through the resulting string and find the specific plant id that you want. In this example, the id for the main_species is 101927 so you can then run the query:
https://trefle.io/api/plants/101927?token=YOUR-TOKEN-HERE
To get more detailed results specific for Achillea borealis.
I have a Chrome extension installed that makes it easier to view the resulting json string: https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc
To really use this data for a lot of plants you need to develop an app of some sort. I'm working in Javascript to loop through a number of plants, get the data I want and then store it on my side for future display (so I don't have to keep querying the api).
In my case of using javascript fetch rather than the browser, I have to run a terminal command every few hours so that Trefle will allow my app access to the data: curl -i -X POST "https://trefle.io/api/auth/claim?token=YOUR-TOKEN-HERE"
Then my fetch url (for Achillea borealis) becomes:
https://trefle.io/api/species?q=achillea%20borealis&token=TOKEN-RETRIEVED-FROM-CURL-QUERY
Hope that helps you get started. That's about all I've figured out so far.
I found that Trefle is really lacking of a Getting started guide for unexperimented developpers