Introduction: Difference between revisions

From Biolovision Help
Jump to navigation Jump to search
(API introduction)
 
(Update pictures)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Introduction ==
==Introduction==


Biolovision API is a RESTful HTTP-based API that can be used to get data such as observations, places, species, grids or other information related to the host website.
Biolovision API is a RESTful HTTP-based API that can be used to get data such as observations, places, species, grids or other information related to the host website.
Line 6: Line 6:
Before starting to do any of the tests please ensure you have the 4 following information: a working '''login/password''' for the website you will use, a '''consumer''' and '''secret key''' for oauth autentification.
Before starting to do any of the tests please ensure you have the 4 following information: a working '''login/password''' for the website you will use, a '''consumer''' and '''secret key''' for oauth autentification.


=== Examples ===
===Examples===


==== Taxonomics groups ====
====Taxonomics groups====
Each website has different taxonomic groups activated or not. This query will give a list of taxonomic groups and if they are active or not. It is a short example, that is a good starting point to test because data is small and can be quickly obtained.
Each website has different taxonomic groups activated or not. This query will give a list of taxonomic groups and if they are active or not. It is a short example, that is a good starting point to test because data is small and can be quickly obtained.


Inside a new Postman query you need to:
Inside a new Postman query you need to:
# Choose the method GET
 
# Write the query ''' ''HOSTNAME''/api/taxo_groups?'''
#Choose the method GET
# Enter the GET params, that will be used for the query. In this case '''user_email''' and '''user_pw''' with the corresponding values.
#Write the query ''' ''HOSTNAME''/api/taxo_groups?'''
# In the Authorization tab choose '''OAuth 1.0'''
#Enter the GET params, that will be used for the query. In this case '''user_email''' and '''user_pw''' with the corresponding values.
# Enter the consumer key and consumer secret key
#In the Authorization tab choose '''OAuth 1.0'''
# Enter the Token line which will be ''' ''HOSTNAME''/index.php?m_id=1200&cmd=request_token'''
#Enter the consumer key and consumer secret key
# Choose the method signature '''HMAC-SHA1'''
#Enter the Token line which will be ''' ''HOSTNAME''/index.php?m_id=1200&cmd=request_token'''
# Tick "Add params to header"
#Choose the method signature '''HMAC-SHA1'''
# Tick "Auto add parameters"
#Tick "Add params to header"
#Tick "Auto add parameters"


At the end it should look like this:
At the end it should look like this:
 
[[File:Taxo group.png|Printscreen from Postman - API query: GET taxo_groups|frame|none]]
[[Fichier:Taxo group.png|none|900px|vignette|left|Printscreen from Postman - API query : GET taxo_groups]]




The response is displayed below, and should look like that:
The response is displayed below, and should look like that:


[[Fichier:Taxo group response.png|none|900px|vignette|left|Printscreen from Postman - API query : result from GET taxo_groups]]
[[File:1350px-Taxo group response.png|Printscreen from Postman - API query: result from GET taxo_groups|frame|none]]




We will now assume OAuth1 is configured and that email and password are set. So we will not mention them anymore, for simplicity, you can reuse the first example as reference.
We will now assume OAuth1 is configured and that email and password are set. So we will not mention them anymore, for simplicity, you can reuse the first example as reference.


==== Places and communes ====
====Places and municipalities (local_admin_units)====


Places can be located at any position and each observation is linked to the nearest place (it can also be directly on the place itself for the ones that are not using precise location). Places are inside communes. We will assume we are looking for all places in one commune. We will use api/places and api/local_admin_units. Communes are represented by the local_admin_units and the county (or any other name depending on country) are territorial_units.
Places can be located at any position and each observation is linked to the nearest place (it can also be directly on the place itself for the ones that are not using precise location). Places are inside communes. We will assume we are looking for all places in one commune. We will use api/places and api/local_admin_units. Communes are represented by the local_admin_units and the county (or any other name depending on country) are territorial_units.


Using the example above, copy it inside a new tab and change a few things:
Using the example above, copy it inside a new tab and change a few things:
# change API query to '''api/local_admin_units'''
 
# add a GET param '''"name"''' next to the user_email and user_pw. Enter the "name" value you want
#change API query to '''api/local_admin_units'''
#add a GET param '''"name"''' next to the user_email and user_pw. Enter the "name" value you want


for this exemple we will be searching for a commune containing the name "Vevey"
for this exemple we will be searching for a commune containing the name "Vevey"
Line 46: Line 47:
You can see the result here:
You can see the result here:


[[Fichier:Local units results.jpg|none|600px|vignette|left|Printscreen from Postman - API query : GET local_admin_units results]]
[[File:Local units results.jpg|Printscreen from Postman - API query: GET local_admin_units results|frame|none]]




Line 52: Line 53:


Again copy query from the initial taxo_groups query to a new postman tab and change the following data:
Again copy query from the initial taxo_groups query to a new postman tab and change the following data:
# The query should now be '''api/places'''
 
# Add a GET param, '''"id_commune"''' with the value that you have retrieved in last query (966)
#The query should now be '''api/places'''
#Add a GET param, '''"id_commune"''' with the value that you have retrieved in last query (966)


The query should look like this:
The query should look like this:


[[Fichier:Get places.png|none|900px|vignette|left|Printscreen from Postman - API query : GET places query]]
[[File:Get places.png|Printscreen from Postman - API query: GET places query|frame|none]]




So now we have all the places that are on the commune choosed.
So now we have all the places that are on the commune choosed.


==== Species ====
====Species====


Another quick example searching all the species that are from taxonomic group 1 (birds) that are used on the website and that have a rarity "unusual"
Another quick example searching all the species that are from taxonomic group 1 (birds) that are used on the website and that have a rarity "unusual"


[[Fichier:Species unusual.png|none|900px|vignette|left|Printscreen from Postman - API query : GET species query]]
[[File:Species unusual.png|Printscreen from Postman - API query: GET species query|frame|none]]
 
====Observations====
 
==== Observations ====


We can get observations using hostname/api/observations but it would generally get to much data for Postman to handle, so you need to search for a smaller dataset here is an example:
We can get observations using hostname/api/observations but it would generally get to much data for Postman to handle, so you need to search for a smaller dataset here is an example:
Line 75: Line 75:
Search all observations between 2 dates for all species
Search all observations between 2 dates for all species


# Change method to '''POST''' (not GET)
#Change method to '''POST''' (not GET)
# Query '''api/observations/search'''
#Query '''api/observations/search'''
# Inside the body tab you can provide a json wich contains all the search parameters like this '''{"period_choice":"range","date_from":"3.11.2015","date_to":"4.11.2015","species_choice":"all"}'''
#Inside the body tab you can provide a json wich contains all the search parameters like this '''{"period_choice":"range","date_from":"3.11.2015","date_to":"4.11.2015","species_choice":"all"}'''
 
[[Fichier:Observations 4 nov 2015.png|none|900px|vignette|left|Printscreen from Postman - API query : GET observation during a period]]


[[File:Observations 4 nov 2015.png|Printscreen from Postman - API query: GET observation during a period|frame|none]]


To get more details on the parameters you can use in the search you can use the Api documentation below. (or do a query on api/help/observations)
To get more details on the parameters you can use in the search you can use the Api documentation below. (or do a query on api/help/observations)

Latest revision as of 05:57, 31 May 2022

Introduction

Biolovision API is a RESTful HTTP-based API that can be used to get data such as observations, places, species, grids or other information related to the host website. Searching observations on any parameter (location,species,date, ...) can be done just as it is done on the website and uses the rights of the observer for providing the data that can be accessed. To provide examples we will work with a tool named Postman, which is a plugin that can be installed through Chrome plugin center. Before starting to do any of the tests please ensure you have the 4 following information: a working login/password for the website you will use, a consumer and secret key for oauth autentification.

Examples

Taxonomics groups

Each website has different taxonomic groups activated or not. This query will give a list of taxonomic groups and if they are active or not. It is a short example, that is a good starting point to test because data is small and can be quickly obtained.

Inside a new Postman query you need to:

  1. Choose the method GET
  2. Write the query HOSTNAME/api/taxo_groups?
  3. Enter the GET params, that will be used for the query. In this case user_email and user_pw with the corresponding values.
  4. In the Authorization tab choose OAuth 1.0
  5. Enter the consumer key and consumer secret key
  6. Enter the Token line which will be HOSTNAME/index.php?m_id=1200&cmd=request_token
  7. Choose the method signature HMAC-SHA1
  8. Tick "Add params to header"
  9. Tick "Auto add parameters"

At the end it should look like this:

Printscreen from Postman - API query: GET taxo_groups


The response is displayed below, and should look like that:

Printscreen from Postman - API query: result from GET taxo_groups


We will now assume OAuth1 is configured and that email and password are set. So we will not mention them anymore, for simplicity, you can reuse the first example as reference.

Places and municipalities (local_admin_units)

Places can be located at any position and each observation is linked to the nearest place (it can also be directly on the place itself for the ones that are not using precise location). Places are inside communes. We will assume we are looking for all places in one commune. We will use api/places and api/local_admin_units. Communes are represented by the local_admin_units and the county (or any other name depending on country) are territorial_units.

Using the example above, copy it inside a new tab and change a few things:

  1. change API query to api/local_admin_units
  2. add a GET param "name" next to the user_email and user_pw. Enter the "name" value you want

for this exemple we will be searching for a commune containing the name "Vevey"

You can see the result here:

Printscreen from Postman - API query: GET local_admin_units results


As you can see there is a few communes having the same name. For our example I will use the last one which has id 966.

Again copy query from the initial taxo_groups query to a new postman tab and change the following data:

  1. The query should now be api/places
  2. Add a GET param, "id_commune" with the value that you have retrieved in last query (966)

The query should look like this:

Printscreen from Postman - API query: GET places query


So now we have all the places that are on the commune choosed.

Species

Another quick example searching all the species that are from taxonomic group 1 (birds) that are used on the website and that have a rarity "unusual"

Printscreen from Postman - API query: GET species query

Observations

We can get observations using hostname/api/observations but it would generally get to much data for Postman to handle, so you need to search for a smaller dataset here is an example:

Search all observations between 2 dates for all species

  1. Change method to POST (not GET)
  2. Query api/observations/search
  3. Inside the body tab you can provide a json wich contains all the search parameters like this {"period_choice":"range","date_from":"3.11.2015","date_to":"4.11.2015","species_choice":"all"}
Printscreen from Postman - API query: GET observation during a period

To get more details on the parameters you can use in the search you can use the Api documentation below. (or do a query on api/help/observations)