BCI Json Service

Note that this service is still experimental.

This is a simple service to provide access to BCI data as Javascript Object Notation (JSON). The endpoint for the service is: http://biocol.org/json

Please raise issues and suggestions on the Google Group.

There are two methods you can call on this service

Fetch

Simply pass this script between 1 and 100 BCI LSIDs as a space delimited list in the 'lsid' parameter and the script will return an array of JavaScript objects each of which represents a collections community record in the database. Each object will have around 30 properties with self explanatory names. The list of properties is given in the table below. Your code should handle nulls and missing properties as the list may change. Guaranteed properties are 'lsid', 'name' and 'url' (which is the human readable page for the collection on BCI).

The LSIDs can be passed as part of the URL path, in the query string of the URL or as a POST variable.

e.g. http://biocol.org/json/fetch/lsid/urn:lsid:biocol.org:col:15670 will return the record for the Royal Botanic Garden Edinburgh.

http://biocol.org/json/fetch?lsid=urn:lsid:biocol.org:col:15670 is equivalent

http://biocol.org/json/fetch?lsid=urn:lsid:biocol.org:col:15670+urn:lsid:biocol.org:col:15763 will return Edinburgh and Paris.

To pass larger numbers of LSIDs (up to 100) it would obviously be better to use a POST request.

By default the results are wrapped in a callback call: "callback([...])". You can change the name of this call by passing the callback parameter. e.g.

http://biocol.org/json/fetch/callback/mycallback/lsid/urn:lsid:biocol.org:col:15670

http://biocol.org/json/fetch?callback=mycallback&lsid=urn:lsid:biocol.org:col:15670

Search

The JSON search method allows the construction of complex searches. The parameter encoding and return type are the same as for the Fetch method above.

Simple Queries

To search for records that have a particular value in a particular field simply pass that field in the query parameter e.g. http://biocol.org/json/search?code=CAS will return the community records where the code field contains 'CAS'. For string fields these comparisons are case insensitive.

Multiple parameters are ANDed together so http://biocol.org/json/search?code=CAS&kind=herbarium will return community records for collections that have the code = 'CAS' AND kind = 'herbarium'.

Like Queries

For fields of type string you can include % signs in the parameter value and an SQL LIKE comparison will be carried out rather than an equals. So http://biocol.org/json/search?code=CA%&kind=herbarium will return the community records of kind = herbarium and codes that start with CA. Like queries are not carried out on fields of type number or date

Negating String Queries

Both Like and Equality string comparisons can be negated by starting the value with a '-' (minus sign). So http://biocol.org/json/search?code=CA%&kind=-herbarium will return community records for collections that have codes that start with CA but are not of kind = herbarium.

Greater-Than / Less-Than Numeric and Date Queries

For fields of type number or date you can start the parameter value with a < or >. So http://biocol.org/json/search?founded_year=<1900 will return the community records with a founding year less than 1900

Repeating Parameters

You can repeat the same parameter in a search but you must append square brackets to the end of the parameter name if you do so (PHP style). So http://biocol.org/json/search?founded_year[]=<1900&founded_year[]=>1890 will return community records for collections founded after 1890 but before 1900. A similar technique could be used for lat/long bounding boxes.

Limit and Offset = Paging

The maximum number of results returned is 50. If there are more than 50 you will get the first 50 and no warning that there are more. You can limit the results to less that 50 by specifying the parameter limit= as a number less than 50. You can specify and offset to say what index you would like your results to start. So http://biocol.org/json/search?founded_year[]=<1900&founded_year[]=>1890&limit=10&offset=10 will return the second 'page' of ten results.

Ordering

Paging is pretty useless unless the results can be guaranteed to come in a particular order so we have the ability to specify an order-by parameter so http://biocol.org/json/search?founded_year[]=<1900&founded_year[]=>1890&limit=10&offset=10&order-by=founded_year,name will order the results by founded_year then name. Prepending the field name with a '-' (minus sign) will cause the order to be descending. Ordering depends on the data type of the field. Strings are alphabetical, numbers numeric and dates by date!

Data Source

By default all queries are run against the community records as these are often the most complete in terms of BCI data and every collection has a community editable record. If you would like to query collection records from a particular source you can specify a 'source' parameter with one of the following values: ih for Index Herbariorum, iscw for Insect and Spider Collections of the World or Bioreposit for BioRepositories.org records. So http://biocol.org/json/search?code=CAS&source=ih will return only records from Index Herbariorum with code CAS

Table of Properties

Name Type Documentation
addressdisplay-stringYou can not query this. It is provided as a convenience concatenation of location fields
codestringPreferred code for the collection
contact_emailstringContact email to use for the collection.
contact_faxstringFax number to use for the collection.
contact_personstringName of the contact person.
contact_phonestringPhone number to call for the collection.
contact_positionstringJob title of the person to contact
createddateCreated date time MySQL format. Value treated the same as numbers for greater-than and less-than
description_pubstringA accessible description of the collection using words a 10 year old would understand.
description_techstringA technical description of the collection (using long words and bio-jargon).
founded_yearnumberThe founding year as an integer. Supports less-than, greater-than
geo_scopestringGeographic scope in words
institution_namestringThe name of the host institution.
institution_typestringThe kind of institution the host institution is.
institution_uristringThe URL of the host institutions website.
kindstringThe kind of collection.
location_altnumberThe altitude about sea level in metres of the collection. Supports less-than, greater-than
location_citystringThe name of the city the collection is located in.
location_country_isostringThe two letter ISO code for the country the collection is located in.
location_country_namestringThe name of the country the collection is located in.
location_departmentstringThe name of the department to use in an address label.
location_latnumberThe decimal lat (WGS84) of the collection. Supports less-than, greater-than
location_longnumberThe decimal longitude (WGS84) of the collection. Supports less-than, greater-than
location_notesstringSome notes about the location.
location_post_boxstringThe PO Box to send things to.
location_postcodestringThe postal code or zip code of the collection.
location_statestringThe name of the state the collection is located in.
location_streetstringThe street address including building name/number.
lsiddisplay-stringYou can not query this. Use the fetch method to get collections by LSID
modifieddateModified date time MySQL format. Value treated the same as numbers for greater-than and less-than
namestringThe name of the collection.
notesstringNotes field for the collection.
record_idstringThe id of the record not the collection. Collections can have more than one record.
sizestringThe size of the collection in words
size_approx_intnumberThe approximate size of the collection as a number. Supports less-than, greater-than
taxon_scopestringTaxonomic scope in words.
urldisplay-stringYou can not query this. It is provided as a convenience link to the collection page on the BCI website
web_service_typestringThe kind of web service e.g. TAPIR or DiGIR. This is a hint. Call the web_service_uri to identify it for real.
web_service_uristringThe URL of a web service end point that covers this collection.
web_sitestringThe URL of the website for the collection.

BCILinks

BCI Links is an example of the use of the JSON service to provide dynamic linking. By including a very small amount of script in their web pages system administrators can automatically link occurrences of collection codes, LSIDs and names to actual collection resources.

How it Works

System administrators or web developers include the following code in their pages.

In the header section they include:

        <script type="text/javascript" charset="utf-8" src="http://biocol.org/js/BCILinks.js"></script>
    

In the body tag they include a call to the BCILinks.parseLinks() method. This may be combined with other method calls already in the onload event.

        <body onload="BCILinks.parseLinks()">
    

In the text of the page they can now surround the code, LSID or names of collections with 'a' tags that have any one of three classes.

        <a class="BCI-Code-Link">E</a>
        <a class="BCI-Name-Link">Royal Botanic Garden Edinburgh Herbarium</a>
        <a class="BCI-LSID-Link">urn:lsid:biocol.org:col:15670</a>
    

When the page loads the parseLinks method works through the document, finds the 'a' tags with any of these three classes and turns them into the appropriate links. It does this by calling the BCI JSON service to search for the contents of the tag. The calls to BCI are made asynchronously so the generation of the links should not effect the overall page load time. Failure is graceful. If JavaScript is not enabled or the BCI site can not be reached then the link text is left as it is.

Link Behaviour

The kind of links that are generated depend on the link class and the results of the search. The behaviour is described here but is probably easier to understand by doing some worked examples with your own data.

Examples

This page uses the BCILinks JavaScript as described above.

Description Data HTML Demo
A code which (at time of writing) returns a single collection. E <a class="BCI-Code-Link">E</a> E
An ambiguous code which returns multiple collections. CAS <a class="BCI-Code-Link">CAS</a> CAS
A code which (at time of writing) returns no collections. DHDHDHD <a class="BCI-Code-Link">DHDHDHD</a> DHDHDHD
An LSID for a collection which (at time of writing) has a web page URL. urn:lsid:biocol.org:col:15670 <a class="BCI-LSID-Link">urn:lsid:biocol.org:col:15670</a> urn:lsid:biocol.org:col:15670
An LSID for a collection which (at time of writing) does not have a web page URL. urn:lsid:biocol.org:col:27074 <a class="BCI-LSID-Link">urn:lsid:biocol.org:col:27074</a> urn:lsid:biocol.org:col:27074
A valid but non-existent LSID. urn:lsid:biocol.org:col:0 <a class="BCI-LSID-Link">urn:lsid:biocol.org:col:0</a> urn:lsid:biocol.org:col:0
A name that matches a collections name (at time of writing) urn:lsid:biocol.org:col:0 <a class="BCI-Name-Link">Royal Botanic Garden Edinburgh Herbarium</a> Royal Botanic Garden Edinburgh Herbarium
A name that does not matche a collections name (at time of writing) urn:lsid:biocol.org:col:0 <a class="BCI-Name-Link">Royal Botanic Gardens Edinburgh</a> Royal Botanic Gardens Edinburgh

Debug Behaviour

If you set BCILinks.debug to true like this:

        <body onload="BCILinks.debug = true; BCILinks.parseLinks()">
    

Then alert messages will be displayed when BCILinks fails to turn the 'a' tag into a link.