The Database API: Difference between revisions

From University Map Wiki
Jump to navigationJump to search
 
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Please read [[Terms and conditions, Copyright, Fair Use, etc.]] if you are going to use this API.
Please read [[Terms and conditions, Copyright, Fair Use, etc.]] if you are going to use this API.
This page describes version 6 of the API, made live on February 20, 2013.
Version 5 ([[The_Database_API_v5|old documentation]]) has been withdrawn. You can see a [[The_Database_API_v6_changes|summary of changes from version 5]].
There is an experimental [[Python Database API interface]] if you want to work with this API from Python.


==Introduction==
==Introduction==
Line 5: Line 11:
The same information as provided by the [[The Map URL API]] is provided in machine readable form using URLs like this:
The same information as provided by the [[The Map URL API]] is provided in machine readable form using URLs like this:


   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>q=''search''[&amp;partial=yes]
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>q=''search''[&amp;partial=yes]
   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>bb=''boundingbox''&amp;z=''zoom''
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>bb=''boundingbox''
   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>ref=''ref''
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>ref=''ref''
   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>inst=''inst''
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>inst=''inst''


with the same interpretation as in [[The Map URL API]] (note that one=list is not relevant in the q= and bb= variants, and the simple&nbsp;<em>name </em>variant is not available to the API - just use <strong><nowiki>http://map.cam.ac.uk/v5.json?</nowiki>q=<em>name</em></strong>).
with the same interpretation as in [[The Map URL API]] (note that one=list is not relevant in the q= and bb= variants, and the simple&nbsp;<em>name </em>variant is not available to the API - just use <strong><nowiki>http://map.cam.ac.uk/v6.json?</nowiki>q=<em>name</em></strong>).
<p>
<p>
An additional option <strong>?limit=<em>limit</em></strong> is also available on the ?q and ?bb forms which limits the number of results returned to the number given. For example</p>
An additional option <strong>?limit=<em>limit</em></strong> is also available on the ?q and ?bb forms which limits the number of results returned to the number given. For example</p>


   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>q=saint&amp;limit=15
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>q=saint&amp;limit=15


Values of query parameters, such as <strong>?q=</strong> are limited to 2,000 characters. For <strong>?inst=</strong> and <strong>?ref=</strong> queries, a maximum of 25 may be requested at once (separating the requested codes with '|').
Values of query parameters, such as <strong>?q=</strong> are limited to 2,000 characters. For <strong>?inst=</strong> and <strong>?ref=</strong> queries, a maximum of 25 may be requested at once (separating the requested codes with '|').


<p>Also, there is another query type available to the database API not available when using a consumer URL. <strong>?alpha=<em>letter</em></strong> will provide an alphabetically ordered listing of the entire index for that letter. This is used as the basis for the directory page and other alphabetic listings. Please cache the results of this search so that it does not place an unwarranted load on the database. You can also filter by type, for example:</p>
<p>Also, there is another query type available to the database API not available when using a consumer URL. <strong>?alpha=<em>letter</em></strong> will provide an alphabetically ordered listing of the entire institution database for that letter. This is used as the basis for the directory page and other alphabetic listings. Please cache the results of this search so that it does not place an unwarranted load on the database. You can also filter by type, for example:</p>


   <nowiki>http://map.cam.ac.uk/v5.json?</nowiki>alpha=s&amp;filter=college
   <nowiki>https://map.cam.ac.uk/v6.json?</nowiki>alpha=s&amp;filter=college
 
<p>The version 6 API also supports discovery and navigation around the reference hierarchy. See [[The Database API reference discovery]] for more details. In addition, the [https://map.cam.ac.uk/refbrowser/ interactive browser] (also linked from the 'More...' menu) can be useful when exploring the data available and when identifying the various codes used.</p>


<p>
<p>
The &#39;v5&#39; is a version number, allowing for potential backward compatibility if we change the spec at some point in the future. Only v5 is recognised for now.</p>
The &#39;v6&#39; is a version number, allowing for potential backward compatibility if we change the spec at some point in the future. Only v6 is useful for now. v5 was deprecated in January 2013 and backward compatibility was not provided.</p>
<p>
<p>
The &#39;json&#39; part indicates the results are provided in JSON format. We may produce other formats in future, in which case URLs such as&nbsp;<strong><nowiki>http://map.cam.ac.uk/v5.xml?</nowiki>...</strong> would be introduced, but for the time being, only JSON is supported.</p>
The &#39;json&#39; part indicates the results are provided in JSON format. We may produce other formats in future, in which case URLs such as&nbsp;<strong><nowiki>https://map.cam.ac.uk/v6.xml?</nowiki>...</strong> would be introduced, but for the time being, only JSON is supported.</p>
<p>
<p>
The result is a JSON array:</p>
The result is a JSON array:</p>
Line 31: Line 39:
[ { &quot;type&quot;: <em>type0</em>, ... }, { &quot;type&quot;:&nbsp;<em>type1</em>, ...<em>&nbsp;</em>}, ... ]</p>
[ { &quot;type&quot;: <em>type0</em>, ... }, { &quot;type&quot;:&nbsp;<em>type1</em>, ...<em>&nbsp;</em>}, ... ]</p>
<p>
<p>
where each object in the array is an entity matching the request.&nbsp;If there are <strong>no results</strong>, an empty array is produced. If there is <strong>only one result</strong>, it is still provided as an array (of one object), not as just the object. Note also that requests by inst and ref may also yield more than one result. For inst, this reflects an institution&#39;s multiple locations and for entrances this reflects an alternate entrance (for example, some residence staircases have access on both sides of a building).</p>
where each object in the array is an entity matching the request.&nbsp;If there are <strong>no results</strong>, an empty array is produced. If there is <strong>only one result</strong>, it is still provided as an array (of one object), not as just the object. Note also that requests by inst and ref may occasionally also yield more than one result. </p>
<p>
<p>
The content of the rest of each object depends on:</p>
The content of the rest of each object depends on:</p>
Line 52: Line 60:
entrance</strong><br />
entrance</strong><br />
<strong>nonuniversity</strong><br />
<strong>nonuniversity</strong><br />
        <strong>virtualsite</strong><br />
<strong>street</strong><br />
<strong>street</strong><br />
<strong>more</strong></p>
<strong>more</strong></p>
Line 60: Line 69:
If <em>type</em> is <strong>error</strong>, then the http request will also return an appropriate status code, typically 400 indicating the request is malformed (wrong combination of query parameters, for example) or 404 (api version or format not implemented for example). The consumer should also be prepared to handle other HTTP errors generated by the server which will not provide JSON data (500 for example). Apart from these, all correctly formed requests will generate status 200. Note that this includes requests with no results (which produce an empty array).</p>
If <em>type</em> is <strong>error</strong>, then the http request will also return an appropriate status code, typically 400 indicating the request is malformed (wrong combination of query parameters, for example) or 404 (api version or format not implemented for example). The consumer should also be prepared to handle other HTTP errors generated by the server which will not provide JSON data (500 for example). Apart from these, all correctly formed requests will generate status 200. Note that this includes requests with no results (which produce an empty array).</p>
<p>
<p>
Note also that if you mis-spell &#39;v5.json&#39; (for example, say you incorrectly use a capital V), then the URL may be interpreted as the end-user form M:/<em>name</em> so you would get a stream of HTML!</p>
Note also that if you mis-spell &#39;v6.json&#39; (for example, say you incorrectly use a capital V), then the URL may be interpreted as the end-user form M:/<em>name</em> so you would get a stream of HTML!</p>
 
<p>v5.json, the now deprecated API, will always produce an error like this (actually an HTTP 410 error).</p>


==Entity structure==
==Entity structure==
Line 185: Line 196:
library<br />
library<br />
museum<br />
museum<br />
cafe<br />
lecture</td>
lecture</td>
<td>
<td>
Line 223: Line 235:
parent*</td>
parent*</td>
<td>
<td>
when the entity is subsidiary to another, this is the name of the parent entity</td>
when the entity is subsidiary to another, this is the institution code of the parent institution</td>
<td>
<td>
entity</td>
entity</td>
<td>
<td>
for example the faculty of a department</td>
for example the faculty of a department</td>
</tr>
<tr>
<td>
locations*</td>
<td>
information about the geographical buildings or sites associated with the institution</td>
<td>
array of building/site/college objects</td>
<td>
<p>
Each location is a further object of the appropriate type, but with a subset of the information (for example, it doesn&#39;t contain institutions - see note above).<br />
For example [ { &quot;lat&quot;: 52.2103, &quot;lon&quot;: 0.1234, &quot;ref&quot;: &quot;SEL&quot;, &quot;name&quot;: &quot;Selwyn College&quot;, &quot;primitive&quot;: &quot;w&quot;, &quot;id&quot;: 1234567 } ]</p>
</td>
</tr>
<tr>
<td>
entrances*</td>
<td>
information about the entrances (to site and buildings) associated with the institution</td>
<td>
array of entrance objects</td>
<td>
similar to locations</td>
</tr>
<tr>
<td>
zoom</td>
<td>
suggested zoom level at which the entity would be best presented (on its own)</td>
<td>
int</td>
<td>
&nbsp;</td>
</tr>
</tr>
<tr>
<tr>
Line 293: Line 272:
for example:</p>
for example:</p>
<p>
<p>
[<br />
&nbsp;&nbsp;"info":&nbsp;[<br/>
&nbsp; { &quot;type&quot;: &quot;address&quot;, &quot;address&quot;: [<br />
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"founded",&nbsp;"founded":&nbsp;"1505"&nbsp;},<br/>
&nbsp; &nbsp; {&quot;type&quot;: &quot;street&quot;, &quot;street&quot;: &quot;St Andrew&#39;s Street&quot;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"address",&nbsp;"address":&nbsp;[<br/>
&nbsp; &nbsp; {&quot;type&quot;: &quot;place&quot;, &quot;place&quot;: &quot;Cambridge&quot;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"street",&nbsp;"street":&nbsp;"St&nbsp;Andrew's&nbsp;Street"&nbsp;},<br/>
&nbsp; &nbsp; {&quot;type&quot;: &quot;postcode&quot;, &quot;postcode&quot;: &quot;CB2 3BU&quot;}],<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"place",&nbsp;"place":&nbsp;"Cambridge"&nbsp;},<br/>
&nbsp; { &quot;type&quot;: &quot;phone&quot;, &quot;phone&quot;: &quot;+44 1223 334900&quot; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"postcode",&nbsp;"postcode":&nbsp;"CB2&nbsp;3BU"&nbsp;},<br/>
&nbsp; &quot;type&quot;&quot;fax&quot;, &quot;fax&quot;: &quot;+44 1223 334901&quot; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"type":&nbsp;"location",&nbsp;"location":&nbsp;{<br/>
&nbsp; { &quot;type&quot;: &quot;phone&quot;, &quot;phone&quot;: &quot;+44 1223 334902&quot;, &quot;role&quot;: &quot;Porter&#39;s Lodge&quot;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"college",&nbsp;"ref":&nbsp;"CHRISTS",&nbsp;"name":&nbsp;"Christ's&nbsp;College",<br/>
&nbsp; { &quot;type&quot;: &quot;email&quot;, &quot;email&quot;: &quot;admissions@christs.cam.ac.uk&quot; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.206145,&nbsp;"lon":&nbsp;0.122944,&nbsp;"primitive":&nbsp;"w",&nbsp;"id":&nbsp;147488000<br/>
&nbsp; {&quot;type&quot;: &quot;url&quot;, &quot;url&quot;: "<nowiki>http://www.christs.cam.ac.uk/</nowiki>" },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp; {&quot;type&quot;: &quot;url&quot;, &quot;url&quot;: "<nowiki>http://www.cam.ac.uk/admissions/undergraduate/colleges/christs/</nowiki>", &quot;role&quot;: &quot;Undergraduate Prospectus Entry&quot; },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp; {&quot;type&quot;: &quot;founded&quot;, &quot;founded&quot;: &quot;1870&quot; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br/>
]</p>
&nbsp;&nbsp;]</p>
<p>
Note that all this contact information relates to the entity concerned. Subordinate entities will have their own contact information if relevant.</p>
<p>Note that all this contact information relates to the entity concerned. Subordinate entities will have their own contact information if relevant.</p>
</td>
</td>
</tr>
</tr>
Line 320: Line 299:
<td></td>
<td></td>
</tr>
</tr>
</table>
===virtualsite===
'virtualsite' entities are '''''only''''' returned as part of [[The Database API reference discovery]] process in response to a search with 'ref=*' or 'ref=''SITE''/*'. These are just like sites and subsites except that they have no location information associated with them. They exist only so that the complete set of prefix letters (including those for buildings not on any real site) is available as a starting point for reference discovery (see the documentation for details). Looking up their ref verbatim will yield no result.
<table class="wikitable">
<tr>
<td>
<strong>key</strong></td>
<td>
<strong>value</strong></td>
<td>
&nbsp;</td>
<td>
<strong>notes</strong></td>
</tr>
                <tr>
                        <td>type</td>
                        <td><strong>virtualsite</strong></td>
                        <td></td>
                        <td></td>
                </tr>
                <tr>
                        <td>ref</td>
                        <td>the reference of the entity</td>
                        <td>string</td>
                        <td>e.g. "K", "EXT/BEAUFORT"<br />
                            See [[The Database API reference discovery]] for a discussion of reference formats</td>
                </tr>
                <tr>
                        <td>name</td>
                        <td>the name of the entity (assuming it has one)</td>
                        <td>string</td>
                        <td>"north city"</td>
                </tr>
                <tr>
                        <td>nonuniversity</td>
                        <td>key only present if the virtual site is not part of the university estate but where we want to refer to it in the map</td>
                        <td>boolean</td>
                        <td>always '''true''' if present. Currently the only virtual non-university site has reference 'EXT', along with some virtual sub-sites of 'EXT'</td>
                </tr>
</table>
</table>


Line 355: Line 378:
string</td>
string</td>
<td>
<td>
e.g. &quot;H/FORVIE&quot;</td>
e.g. &quot;H/FORVIE&quot;<br />
See [[The Database API reference discovery]] for a discussion of reference formats,
</td>
</tr>
</tr>
<tr>
<tr>
Line 384: Line 409:
<td>
<td>
float</td>
float</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
zoom</td>
<td>
suggested zoom level at which the entity would be best presented (on its own)</td>
<td>
int</td>
<td>
<td>
&nbsp;</td>
&nbsp;</td>
Line 401: Line 416:
primitive</td>
primitive</td>
<td>
<td>
whether the building was dericved from an OSM way (&quot;w&quot;) or node (&quot;n&quot;)</td>
whether the building was derived from an OSM way (&quot;w&quot;) or node (&quot;n&quot;)</td>
<td>
<td>
string (either &quot;w&quot; or &quot;n&quot;)</td>
string (either &quot;w&quot; or &quot;n&quot;)</td>
Line 411: Line 426:
id</td>
id</td>
<td>
<td>
the OSM id of the node from which the entrance was derived</td>
the OSM id of the node or way from which the entity was derived</td>
<td>
<td>
int</td>
int</td>
<td>
<td>
sites are always areas (ways) in OSM<br />
sites, colleges and buildings are usually areas (ways) in OSM, though there are a few "buildings" which represent an office in larger, possibly non-university premises, represented just as a node. Complex buildings, e.g. one containing 'holes', are represented as OSM 'multipologon relations'. In these cases the referenced way will be the one corresponding to the outside of the building - the holes can be accessed via the relation containing this way and OSM tags relating to the building will be associated with the outer way or the relation (but not both).<br/>&nbsp;</td>
&nbsp;</td>
</tr>
</tr>
</table>
</table>
Line 442: Line 456:
<td>
<td>
&nbsp;</td>
&nbsp;</td>
</tr>
<tr>
<td>
nonuniversity</td>
<td>
<strong>true</strong></td>
<td>
boolean</td>
<td>
present to distinguish non-university sites from university sites (currently the only non-virtual, non-university site is 'H', the Cambridge Biomedical Campus)</td>
</tr>
</tr>
<tr>
<tr>
Line 461: Line 485:
array of entrance objects</td>
array of entrance objects</td>
<td>
<td>
see above</td>
see below</td>
</tr>
</tr>
</table>
</table>
Line 502: Line 526:
entrances*</td>
entrances*</td>
<td>
<td>
as for inst</td>
as for site</td>
<td>
<td>
array of entrance objects</td>
array of entrance objects</td>
<td>
<td>
see above<br />
see below</td>
&nbsp;</td>
</tr>
</tr>
<tr>
<tr>
Line 562: Line 585:
array of entrance objects</td>
array of entrance objects</td>
<td>
<td>
see above</td>
see below</td>
</tr>
</tr>
<tr>
<tr>
Line 613: Line 636:
occupants*</td>
occupants*</td>
<td>
<td>
institution codes of the institutions that gain access by this entrance</td>
  the institutions that gain access by this entrance</td>
<td>
<td>
array of string</td>
array of institution objects</td>
<td>
<td>
e.g. [&quot;met&quot;, &quot;cs&quot;]. OK, you don&#39;t exactly &quot;occupy&quot; an entrance, but consistent with buildings</td>
OK, you don&#39;t exactly &quot;occupy&quot; an entrance, but consistent with buildings</td>
</tr>
</tr>
<tr>
<tr>
Line 647: Line 670:
boolean</td>
boolean</td>
<td>
<td>
whether this entrance is the door to a buiulding (true) or a gate to a site (false)</td>
whether this entrance is the door to a building (true) or a gate to a site (false)</td>
</tr>
</tr>
</table>
</table>
Line 653: Line 676:
===nonuniversity===
===nonuniversity===


Non-university objects are only provided no reference is available. Where they have a University reference they are included in the general scheme of sites and buildings, with the '''nonuniversity''' element set to '''true'''.


<table class="wikitable">
<table class="wikitable">
Line 756: Line 780:
<td>
<td>
<p>
<p>
what the address is for, assumed to be the primary address if not described.</p>
postal address (assumed to be the primary address if not described otherwise by the role attribute - see below).</p>
</td>
</td>
</tr>
</tr>
Line 813: Line 837:
string</td>
string</td>
<td>
<td>
&nbsp;</td>
twitter handle including the @, e.g. @camgeog</td>
</tr>
</tr>
<tr>
<tr>
Line 834: Line 858:


<p>Additionally when a ?q returns a result via a match on an AKA, the top level structure contains 'viaaka', the index of the info element which it matched against. This is so that you can tell the user if you want to why their search matched when it doesn't appear to match the main entry name.</p></td>
<p>Additionally when a ?q returns a result via a match on an AKA, the top level structure contains 'viaaka', the index of the info element which it matched against. This is so that you can tell the user if you want to why their search matched when it doesn't appear to match the main entry name.</p></td>
</tr>
<tr>
<td>
subsection</td>
<td>
string</td>
<td>
indicates that all the entries that follow up to a subsection-end entry or another subsection entry or the end of the info array are grouped together. This would typically be used where an institution lists contact details for a well-defined part or function of the institution - for example, the phone, fax and email for the Box Office part of the ADC Theatre. A consumer would typically render the subsection string as a subheading of some kind and possibly indent its contents or separate them out in some suitable way. (note: this supersedes the version 5 method of grouping, where repeated roles indicated subsections, which was rather clumsy and prevented the individual elements having their own roles).</td>
</tr>
<tr>
<td>
subsection-end</td>
<td>
string (unused)</td>
<td>
explicitly terminates a group of subsection elements.</td>
</tr>
</tr>
</table>
</table>
Line 878: Line 918:
===Addresses===
===Addresses===


Addresses are further subdivided so that they can be presented linearly, in &quot;label&quot; form or as a VCARD etc, by combining the elements with suitable punctuation and markup, and also cross-linked where appropriate - for example the <strong>street</strong>&nbsp;element could be linked with the URL <strong><nowiki>http://www.cam.ac.uk/</nowiki><em>streetname</em></strong> to jump to the map for the street name. These should be used in order when presenting an address.  
Addresses are further subdivided so that they can be presented linearly, in &quot;label&quot; form or as a VCARD etc, by combining the elements with suitable punctuation and markup, and also cross-linked where appropriate - for example the <strong>street</strong>&nbsp;element could be linked with the URL <strong><nowiki>http://www.cam.ac.uk/</nowiki><em>streetname</em></strong> to jump to the map for the street name. These should be used in order when presenting an address.
 
Addresses may also be associated with geographical locations (sites, colleges and buildings) and their entrances. This supersedes the amorphous list of locations and entrances provided in version 5. An address may be
<ul>
<li>just a postal address for correspondence, in which no location or entrances will be included in the address data</li>
<li>a postal address with a corresponding location on the ground (possibly with entrances)</li>
<li>just a location (and possibly its entrances), where the intention is to show the location on a map, but to direct post to a central address in a second address element, or occasionally that a postal address is not available for the location.</li>
</ul>


Each element contains a <strong>type</strong> field whose value is one of the keys in the following table, and then a key/value pair according to the type, as follows:
Each element contains a <strong>type</strong> field whose value is one of the keys in the following table, and then a key/value pair according to the type, as follows:
Line 890: Line 937:
<td>
<td>
&nbsp;</td>
&nbsp;</td>
</tr>
<tr>
<td>
location</td>
<td>
int</td>
<td>
a number indicating that this address refers to the corresponding location in the list of locations. Not all addresses need refer to a location (e.g. a PO Box), and not all locations need have a corresponding address. But when they do, the correspondence may be used to disambiguate locations occupied by the institution. Numbering starts at 1, not zero!</td>
</tr>
</tr>
<tr>
<tr>
Line 981: Line 1,020:
<tr>
<tr>
<td>
<td>
address</td>
location</td>
<td>
location object</td>
<td>
see [[#Fields_common_to_all_geographical_objects|above]]. This is an excerpted geographical location object. There will only be at most one location object per address.</td>
</tr>
<tr>
<td>
entrance</td>
<td>
<td>
string</td>
entrance object</td>
<td>
<td>
the complete address laid out linearly, only provided in the absence of all of the other fields to allow for addresses which have not been structured yet&nbsp;</td>
see [[#entrance|above]]. This is an excerpted geographical entrance object. There may be multiple entrance elements per address, but there will never be an entrance object in an address if there is no location object preceding it for the same address. Conversely, location elements do not have any entrance elements preceding them.</td>
</tr>
</tr>
</table>
</table>
Line 996: Line 1,043:
<li>
<li>
Division of Anaesthesia<br />
Division of Anaesthesia<br />
[ {&quot;type&quot;: &quot;maildrop&quot;, &quot;maildrop&quot;: &quot;Box 93&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;maildrop&quot;, &quot;maildrop&quot;: &quot;Level 4&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;site&quot;, &quot;site&quot;: &quot;Addenbrooke&#39;s Hospital&quot;},<br/>&nbsp;{&quot;type: &quot;street, &quot;street: &quot;Hills Road&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;place&quot;, &quot;place&quot;: &quot;Cambridge&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;postcode&quot;, &quot;postcode&quot;: &quot;CB2 2QQ&quot;} ]</li>
[<br/>
<li>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"maildrop",&nbsp;"maildrop":&nbsp;"Box&nbsp;93"&nbsp;},<br/>
Department of Anglo-Saxon, Norse and Celtic<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"maildrop",&nbsp;"maildrop":&nbsp;"Level&nbsp;4"&nbsp;},<br/>
[ {&quot;type&quot;: &quot;number&quot;, &quot;number&quot;: &quot;9&quot;},<br/>&nbsp;{&quot;type: &quot;street, &quot;street: &quot;West Road&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;place&quot;, &quot;place&quot;: &quot;Cambridge&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;postcode&quot;, &quot;postcode&quot;: &quot;CB3 9DP&quot;} ]</li>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"site",&nbsp;"site":&nbsp;"Addenbrooke's&nbsp;Hospital"&nbsp;},<br/>
<li>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"street",&nbsp;"street":&nbsp;"Hills&nbsp;Road"&nbsp;},<br/>
Cambridge Centre for Brain Repair<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"place",&nbsp;"place":&nbsp;"Cambridge"&nbsp;},<br/>
[ {&quot;type&quot;: &quot;building&quot;, &quot;building&quot;: &quot;E. D. Adrian Building&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;site&quot;, &quot;site&quot;: &quot;Forvie Site&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;street&quot;, &quot;street&quot;: &quot;Robinson Way&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;place&quot;, &quot;place&quot;: &quot;Cambridge&quot;},<br/>&nbsp;{&quot;type&quot;: &quot;postcode&quot;, &quot;postcode&quot;: &quot;CB2 0PY&quot;} ]</li>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"postcode",&nbsp;"postcode":&nbsp;"CB2&nbsp;2QQ"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"location",&nbsp;"location":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"building",&nbsp;"ref":&nbsp;"H132",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.17525,&nbsp;"lon":&nbsp;0.141464,&nbsp;"id":&nbsp;1643255315&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"entrance",&nbsp;"entrance":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance",&nbsp;"ref":&nbsp;"H131-A",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name":&nbsp;"Addenbrooke's&nbsp;Hospital&nbsp;Main&nbsp;Entrance",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.175206,&nbsp;"lon":&nbsp;0.140538,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"direction":&nbsp;104,&nbsp;"user":&nbsp;"f",&nbsp;"primitive":&nbsp;"n",&nbsp;"id":&nbsp;1643254795,&nbsp;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"entrance":&nbsp;"main",&nbsp;"door":&nbsp;true&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance",&nbsp;"entrance":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance","ref":&nbsp;"H-A",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.176241,&nbsp;"lon":&nbsp;0.144354,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"direction":&nbsp;15,&nbsp;"user":&nbsp;"fbv",&nbsp;"primitive":&nbsp;"n",&nbsp;"id":&nbsp;664530277,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"entrance":&nbsp;"main",&nbsp;"door":&nbsp;false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;...<br/>
]</li>
</ul>
</ul>
Here is a complete example record (for the Department of Anglo-Saxon, Norse and Celtic). Remember that all result records will be presented in an array, even if there is only one of them.
&nbsp;&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"institution",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"inst":&nbsp;"asnc",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"prefix":&nbsp;"Department&nbsp;of",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"name":&nbsp;"Anglo-Saxon,&nbsp;Norse&nbsp;and&nbsp;Celtic",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"sd":&nbsp;"asnc",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"role":&nbsp;"academic",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;"info":&nbsp;[<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"address",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"address":&nbsp;[<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"number",&nbsp;"number":&nbsp;"9"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"street",&nbsp;"street":&nbsp;"West&nbsp;Road"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"place",&nbsp;"place":&nbsp;"Cambridge"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"postcode",&nbsp;"postcode":&nbsp;"CB3&nbsp;9DP"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"location",&nbsp;"location":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"building",&nbsp;"ref":&nbsp;"S040",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name":&nbsp;"Faculty&nbsp;of&nbsp;English",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.20246,&nbsp;"lon":&nbsp;0.108541,&nbsp;"id":&nbsp;26378099&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"entrance",&nbsp;"entrance":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance",&nbsp;"ref":&nbsp;"S040-A",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.202422,&nbsp;"lon":&nbsp;0.108616,&nbsp;"direction":&nbsp;-169,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"user":&nbsp;"f",&nbsp;"primitive":&nbsp;"n",&nbsp;"id":&nbsp;1487638771,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"entrance":&nbsp;"main",&nbsp;"door":&nbsp;true&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"entrance",&nbsp;"entrance":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance",&nbsp;"ref":&nbsp;"S-C",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.202752,&nbsp;"lon":&nbsp;0.108839,&nbsp;"direction":&nbsp;94,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"user":&nbsp;"fb",&nbsp;"primitive":&nbsp;"n",&nbsp;"id":&nbsp;961417125,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"entrance":&nbsp;"main",&nbsp;"door":&nbsp;false<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"entrance",&nbsp;"entrance":&nbsp;{<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type":&nbsp;"entrance",&nbsp;"ref":&nbsp;"S-E",<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"lat":&nbsp;52.202702,&nbsp;"lon":&nbsp;0.108056,&nbsp;"direction":&nbsp;94,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"user":&nbsp;"fbv",&nbsp;"primitive":&nbsp;"n",&nbsp;"id":&nbsp;961417126,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"entrance":&nbsp;"main",&nbsp;"door":&nbsp;false&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"phone",&nbsp;"phone":&nbsp;"+44&nbsp;1223&nbsp;335079"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"fax",&nbsp;"fax":&nbsp;"+44&nbsp;1223&nbsp;335092"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"email",&nbsp;"email":&nbsp;"asnc@hermes.cam.ac.uk"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"url",&nbsp;"url":&nbsp;"http:\/\/www.asnc.cam.ac.uk\/"&nbsp;},<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;"type":&nbsp;"url",&nbsp;"url":&nbsp;"http:\/\/www.asnc.cam.ac.uk\/people\/index.htm",&nbsp;"role":&nbsp;"Contacts"&nbsp;}<br/>
&nbsp;&nbsp;&nbsp;&nbsp;]<br/>
&nbsp;&nbsp;}<br/>


==Coordinates==
==Coordinates==


There are very few real-world coordinates in the database (it doesn't, for example, include building outlines). But this information is available from the OSM API by reference to the OSM id in the 'id' field of all geographic entities.
There are very few real-world coordinates in the database (it doesn't, for example, include building outlines). But this information is available from the [http://wiki.openstreetmap.org/wiki/API OSM API] by reference to the OSM id in the 'id' field of all geographic entities.


For building outlines, the OSM API supports:
For building outlines, the OSM API supports:


   http://osm.org/api/0.6/way/<ID>
   <nowiki>http://osm.org/api/0.6/way/<ID></nowiki>
   http://osm.org/api/0.6/way/<ID>/full
   <nowiki>http://osm.org/api/0.6/way/<ID>/full</nowiki>
   http://osm.org/api/0.6/way/<ID>/relations
   <nowiki>http://osm.org/api/0.6/way/<ID>/relations</nowiki>


Note however that a building doesn't have to be just a single closed way, since it can have have holes in the area. These are handled as OSM "[http://wiki.openstreetmap.org/wiki/Relation:multipolygon multipolygons]". In essence, there is an outer way plus a number of inner ways  
Note however that a building doesn't have to be just a single closed way, since it can have have holes in the area. These are handled as OSM "[http://wiki.openstreetmap.org/wiki/Relation:multipolygon multipolygons]". In essence, there is an outer way plus a number of inner ways  


For example, Churchill West Court (ref CHU016, http://preview.map.cam.ac.uk/v5.json?ref=CHU016&debug=1). The Map API tells you it is a way with id 148247888 and you can plug it into the OSM API thus
For example, Churchill West Court (ref CHU016, https://map.cam.ac.uk/v6.json?ref=CHU016&debug=1). The Map API tells you it is a way with id 148247888 and you can plug it into the OSM API thus


   http://www.openstreetmap.org/api/0.6/way/148247888/full
   http://www.openstreetmap.org/api/0.6/way/148247888/full

Latest revision as of 11:57, 27 March 2020

Please read Terms and conditions, Copyright, Fair Use, etc. if you are going to use this API.

This page describes version 6 of the API, made live on February 20, 2013.

Version 5 (old documentation) has been withdrawn. You can see a summary of changes from version 5.

There is an experimental Python Database API interface if you want to work with this API from Python.

Introduction

The same information as provided by the The Map URL API is provided in machine readable form using URLs like this:

 https://map.cam.ac.uk/v6.json?q=search[&partial=yes]
 https://map.cam.ac.uk/v6.json?bb=boundingbox
 https://map.cam.ac.uk/v6.json?ref=ref
 https://map.cam.ac.uk/v6.json?inst=inst

with the same interpretation as in The Map URL API (note that one=list is not relevant in the q= and bb= variants, and the simple name variant is not available to the API - just use http://map.cam.ac.uk/v6.json?q=name).

An additional option ?limit=limit is also available on the ?q and ?bb forms which limits the number of results returned to the number given. For example

 https://map.cam.ac.uk/v6.json?q=saint&limit=15

Values of query parameters, such as ?q= are limited to 2,000 characters. For ?inst= and ?ref= queries, a maximum of 25 may be requested at once (separating the requested codes with '|').

Also, there is another query type available to the database API not available when using a consumer URL. ?alpha=letter will provide an alphabetically ordered listing of the entire institution database for that letter. This is used as the basis for the directory page and other alphabetic listings. Please cache the results of this search so that it does not place an unwarranted load on the database. You can also filter by type, for example:

 https://map.cam.ac.uk/v6.json?alpha=s&filter=college

The version 6 API also supports discovery and navigation around the reference hierarchy. See The Database API reference discovery for more details. In addition, the interactive browser (also linked from the 'More...' menu) can be useful when exploring the data available and when identifying the various codes used.

The 'v6' is a version number, allowing for potential backward compatibility if we change the spec at some point in the future. Only v6 is useful for now. v5 was deprecated in January 2013 and backward compatibility was not provided.

The 'json' part indicates the results are provided in JSON format. We may produce other formats in future, in which case URLs such as https://map.cam.ac.uk/v6.xml?... would be introduced, but for the time being, only JSON is supported.

The result is a JSON array:

[ { "type": type0, ... }, { "type": type1, ... }, ... ]

where each object in the array is an entity matching the request. If there are no results, an empty array is produced. If there is only one result, it is still provided as an array (of one object), not as just the object. Note also that requests by inst and ref may occasionally also yield more than one result.

The content of the rest of each object depends on:

  • type
  • what information is available for each result
  • whether the request was a search (q=... or name) or direct look up (ref or inst URLs)

type is one of:

error
institution
site
college

building
entrance

nonuniversity
virtualsite
street
more

Error reports

If type is error, then the http request will also return an appropriate status code, typically 400 indicating the request is malformed (wrong combination of query parameters, for example) or 404 (api version or format not implemented for example). The consumer should also be prepared to handle other HTTP errors generated by the server which will not provide JSON data (500 for example). Apart from these, all correctly formed requests will generate status 200. Note that this includes requests with no results (which produce an empty array).

Note also that if you mis-spell 'v6.json' (for example, say you incorrectly use a capital V), then the URL may be interpreted as the end-user form M:/name so you would get a stream of HTML!

v5.json, the now deprecated API, will always produce an error like this (actually an HTTP 410 error).

Entity structure

Contents of JSON objects representing entities found are as follows, by type.

In general, each request includes information about things linked to each result: the buildings for an institution, the entrances to a site and so on. This referencing only applies one level deep: those parts are excerpted: they do not themselves contain further entities to which they refer. If you need these, you would have to request the content by ref or inst from the parent. The fields omitted in the second level are indicated with an asterisk in the tables that follow.

error

key value   notes
type error    
code the HTTP status code int  
error text describing the error string  

more

key value   notes
type more           When the number of results is limited by ?limit=limit, the last element in the array of results may indicate "more", that there are more results that could be found but the limit was reached. Because certain results are redacted in some circumstances, note that the number of elements in the array may be fewer than limit+1 even if the limit is reached. "more" is not included if all the available results are returned. There isn't any way to page through the results: the search needs to be made more specific.

institution

key value   notes
type institution    
inst the institution code of the entity string  
role kind of institution

string, one of:
college
academic
admin
nonacademic
mrc
library
museum
cafe

lecture
 
prefix the name prefix string for example, 'Department of', 'Centre for'
name the substantive part of the institution name string for example, 'Geography'. This is the field to sort on for alphabetically ordered institutions
suffix the name suffix string often an acronym or former name, which would often be presented in parentheses. For example, when name is 'Advanced Photonics and Electronics', prefix is 'Centre for ' and suffix would be 'CAPE'. The whole might be presented as 'Advanced Photonics and Electronics (CAPE), Centre for' or 'Centre for Advanced Photonics and Electronics (CAPE)'
parent* when the entity is subsidiary to another, this is the institution code of the parent institution entity for example the faculty of a department
options arbitrary space separated tokens indicating arbitrary options string  
sd the subdomain of the entity string e.g. "lucy-cav"
info contact information (etc) array of objects (see below)

for example:

  "info": [
    { "type": "founded", "founded": "1505" },
    { "type": "address", "address": [
        { "type": "street", "street": "St Andrew's Street" },
        { "type": "place", "place": "Cambridge" },
        { "type": "postcode", "postcode": "CB2 3BU" },
        {"type": "location", "location": {
            "type": "college", "ref": "CHRISTS", "name": "Christ's College",
            "lat": 52.206145, "lon": 0.122944, "primitive": "w", "id": 147488000
          }
        },
        ...
  ]

Note that all this contact information relates to the entity concerned. Subordinate entities will have their own contact information if relevant.

sortasvia when result matched via an AKA field (see below) or from a role, the index of the info element which it matched against integer

virtualsite

'virtualsite' entities are only returned as part of The Database API reference discovery process in response to a search with 'ref=*' or 'ref=SITE/*'. These are just like sites and subsites except that they have no location information associated with them. They exist only so that the complete set of prefix letters (including those for buildings not on any real site) is available as a starting point for reference discovery (see the documentation for details). Looking up their ref verbatim will yield no result.

key value   notes
type virtualsite
ref the reference of the entity string e.g. "K", "EXT/BEAUFORT"
See The Database API reference discovery for a discussion of reference formats
name the name of the entity (assuming it has one) string "north city"
nonuniversity key only present if the virtual site is not part of the university estate but where we want to refer to it in the map boolean always true if present. Currently the only virtual non-university site has reference 'EXT', along with some virtual sub-sites of 'EXT'

Fields common to all geographical objects

The remainder are all geographical objects and share the following common fields:

key value   notes
type      
ref the reference of the entity string

e.g. "H/FORVIE"
See The Database API reference discovery for a discussion of reference formats,

name the name of the entity (assuming it has one) string e.g. "Forvie Site", "Austin Building"
lat the latitude of a representative position of the entity float  
lon the longitude of a representative position of the entity float  
primitive whether the building was derived from an OSM way ("w") or node ("n") string (either "w" or "n") primitive and id can be used together to form a link to the OSM browser, as in http://osm.org/browse/way/1234567
id the OSM id of the node or way from which the entity was derived int sites, colleges and buildings are usually areas (ways) in OSM, though there are a few "buildings" which represent an office in larger, possibly non-university premises, represented just as a node. Complex buildings, e.g. one containing 'holes', are represented as OSM 'multipologon relations'. In these cases the referenced way will be the one corresponding to the outside of the building - the holes can be accessed via the relation containing this way and OSM tags relating to the building will be associated with the outer way or the relation (but not both).
 

site

key value   notes
type site    
nonuniversity true boolean present to distinguish non-university sites from university sites (currently the only non-virtual, non-university site is 'H', the Cambridge Biomedical Campus)
parent* when the site is a sub-site, this is the main site site object for example object for "Cambridge Biomedical Campus" when name is "Forvie Site"
entrances* to the site array of entrance objects see below

college

key value   notes
type college   This is the geographical entity for a college site or sub-site, not the institutional information which is an inst. This is very similar to site.
parent* when the college item is a subsidiary site, the main site college object e.g. object for "Magdalene College" when site is ref MAGD/CRIPPS
entrances* as for site array of entrance objects see below
institution* the institution information associated with this college area institution object  

building

key value   notes
type building    
parent* site/college in which the building is situated site/college object  
entrances* entrances of the building array of entrance objects see below
occupants* occupants of the building array of institution objects  

entrance

key value   notes
type entrance   entrances apply to sites and colleges as well as buildings. Note, entrances are always derived from OSM node entities.
parents* buildings and/or sites/colleges to which this entrance gives access array of building/site/college objects note that a few entrances give access to university properties on either side; also occasionally an entrance to a building isn't actually part of the building footprint.
occupants* the institutions that gain access by this entrance array of institution objects OK, you don't exactly "occupy" an entrance, but consistent with buildings
direction the direction of a normal to the parent building/site/college at an entrance, in degrees between -180 and 180 measured anticlockwise from the east (positive x axis) pointing away from the building float the direction can be used to orient an overlaid arrow pointing to the entrance.
user some or all of the letters "fbvg" string standing for "foot", "bicycle", "vehicle" and "goods" respectively, indicating the class or classes of users which can use the entrance.
door   boolean whether this entrance is the door to a building (true) or a gate to a site (false)

nonuniversity

Non-university objects are only provided no reference is available. Where they have a University reference they are included in the general scheme of sites and buildings, with the nonuniversity element set to true.

key value   notes
type nonuniversity    
role what kind of thing this is string e.g. "hotel"

street

key value   notes
type street   no additional fields other than the common ones

Contact information

Contact information for institutions and colleges is grouped into an array of items each of which may be repeated and qualified as necessary. For example, multiple phone numbers with descriptions of what each is for. Note that these all relate to the entity concerned. Subordinate entities will have their own contact information if relevant, so addresses, phone numbers etc. for child institutions should not be given as alternate addresses within the same info array.

key value  
person string primary contact named individual, for example "Prof. John Doe".
description string A brief description of the function of the institution
title string primary contact title, for example "The Bursar", where useful for more personal addressing.
address array of objects (see below)

postal address (assumed to be the primary address if not described otherwise by the role attribute - see below).

phone string in the international form +44 1223 33nnnn
fax string ditto
email string  
url string complete, including the http://
founded int (colleges only) year of foundation
logo string url of image which is used to brand the institution
twitter string twitter handle including the @, e.g. @camgeog
facebook string  
AKA string

another name or search term by which the institution is known. Unlike other info fields, the value of this info item is (usually) added to the search index.

This may be used in different ways according to the accompanying options. An "xm" option excludes the entry from the paper map (this might be a very old name, for example, which you want search results to hit, but not include in an up-to-date static map). "xw" excludes it from the web site searches and presentation, but includes it in the paper map and other alphabetic listings. "xd" excludes it from presentation (the user doesn't see it), but includes it in the index.

Additionally when a ?q returns a result via a match on an AKA, the top level structure contains 'viaaka', the index of the info element which it matched against. This is so that you can tell the user if you want to why their search matched when it doesn't appear to match the main entry name.

subsection string indicates that all the entries that follow up to a subsection-end entry or another subsection entry or the end of the info array are grouped together. This would typically be used where an institution lists contact details for a well-defined part or function of the institution - for example, the phone, fax and email for the Box Office part of the ADC Theatre. A consumer would typically render the subsection string as a subheading of some kind and possibly indent its contents or separate them out in some suitable way. (note: this supersedes the version 5 method of grouping, where repeated roles indicated subsections, which was rather clumsy and prevented the individual elements having their own roles).
subsection-end string (unused) explicitly terminates a group of subsection elements.

Contact information qualifiers

Each of these objects contains a type to identify the key, and may also contain other qualifying information, as follows:

key value  
type one of the keys listed in the previous table
role string description of what the contact information will be used for. If omitted, assumed to be the primary contact information of this type. For URLs this would typically be used for the link text rather than displaying the URL itself. For others it would serve as a caption. 
options string arbitrary space separated string of options (meanings client dependent)

Addresses

Addresses are further subdivided so that they can be presented linearly, in "label" form or as a VCARD etc, by combining the elements with suitable punctuation and markup, and also cross-linked where appropriate - for example the street element could be linked with the URL http://www.cam.ac.uk/streetname to jump to the map for the street name. These should be used in order when presenting an address.

Addresses may also be associated with geographical locations (sites, colleges and buildings) and their entrances. This supersedes the amorphous list of locations and entrances provided in version 5. An address may be

  • just a postal address for correspondence, in which no location or entrances will be included in the address data
  • a postal address with a corresponding location on the ground (possibly with entrances)
  • just a location (and possibly its entrances), where the intention is to show the location on a map, but to direct post to a central address in a second address element, or occasionally that a postal address is not available for the location.

Each element contains a type field whose value is one of the keys in the following table, and then a key/value pair according to the type, as follows:

key value  
maildrop string for parts of an address such as a room number or a PO Box number
building string name of building
number string location on a street, e.g. "42a"
site string e.g. "Lords Bridge", "New Museums Site"
street string e.g. "Downing Place"
street2 string occasionally a second street is part of the address
smallplace string where place is a local village
place string usually "Cambridge"
county string rarely needed
postcode string  
location location object see above. This is an excerpted geographical location object. There will only be at most one location object per address.
entrance entrance object see above. This is an excerpted geographical entrance object. There may be multiple entrance elements per address, but there will never be an entrance object in an address if there is no location object preceding it for the same address. Conversely, location elements do not have any entrance elements preceding them.

Some examples:

  • Hamilton Kerr Institute:
    [ {"type": "street", "street": "Mill Lane"},
     {"type": "smallplace", "smallplace": "Whittlesford"},
     {"type": "place", "place": "Cambridge"},
     {"type": "postcode", "postcode": "CB22 4NE"} ]
  • Division of Anaesthesia
    [
              { "type": "maildrop", "maildrop": "Box 93" },
              { "type": "maildrop", "maildrop": "Level 4" },
              { "type": "site", "site": "Addenbrooke's Hospital" },
              { "type": "street", "street": "Hills Road" },
              { "type": "place", "place": "Cambridge" },
              { "type": "postcode", "postcode": "CB2 2QQ" },
              { "type": "location", "location": {
                  "type": "building", "ref": "H132",
                  "lat": 52.17525, "lon": 0.141464, "id": 1643255315 }
              },
              { "type": "entrance", "entrance": {
                  "type": "entrance", "ref": "H131-A",
                  "name": "Addenbrooke's Hospital Main Entrance",
                  "lat": 52.175206, "lon": 0.140538,
                  "direction": 104, "user": "f", "primitive": "n", "id": 1643254795, 
          "entrance": "main", "door": true }
              },
              {
                "type": "entrance", "entrance": {
                  "type": "entrance","ref": "H-A",
                  "lat": 52.176241, "lon": 0.144354,
                  "direction": 15, "user": "fbv", "primitive": "n", "id": 664530277,
          "entrance": "main", "door": false
                }
              },
      ...
    ]

Here is a complete example record (for the Department of Anglo-Saxon, Norse and Celtic). Remember that all result records will be presented in an array, even if there is only one of them.

  {
    "type": "institution",
    "inst": "asnc",
    "prefix": "Department of",
    "name": "Anglo-Saxon, Norse and Celtic",
    "sd": "asnc",
    "role": "academic",
    "info": [
      { "type": "address",
        "address": [
          { "type": "number", "number": "9" },
          { "type": "street", "street": "West Road" },
          { "type": "place", "place": "Cambridge" },
          { "type": "postcode", "postcode": "CB3 9DP" },
          { "type": "location", "location": {
              "type": "building", "ref": "S040",
              "name": "Faculty of English",
              "lat": 52.20246, "lon": 0.108541, "id": 26378099 }
          },
          { "type": "entrance", "entrance": {
              "type": "entrance", "ref": "S040-A",
              "lat": 52.202422, "lon": 0.108616, "direction": -169,
              "user": "f", "primitive": "n", "id": 1487638771,
              "entrance": "main", "door": true }
          },
          { "type": "entrance", "entrance": {
              "type": "entrance", "ref": "S-C",
              "lat": 52.202752, "lon": 0.108839, "direction": 94,
              "user": "fb", "primitive": "n", "id": 961417125,
              "entrance": "main", "door": false
            }
          },
          { "type": "entrance", "entrance": {
              "type": "entrance", "ref": "S-E",
              "lat": 52.202702, "lon": 0.108056, "direction": 94,
              "user": "fbv", "primitive": "n", "id": 961417126,
              "entrance": "main", "door": false }
          }
        ]
      },
      { "type": "phone", "phone": "+44 1223 335079" },
      { "type": "fax", "fax": "+44 1223 335092" },
      { "type": "email", "email": "asnc@hermes.cam.ac.uk" },
      { "type": "url", "url": "http:\/\/www.asnc.cam.ac.uk\/" },
      { "type": "url", "url": "http:\/\/www.asnc.cam.ac.uk\/people\/index.htm", "role": "Contacts" }
    ]
  }

Coordinates

There are very few real-world coordinates in the database (it doesn't, for example, include building outlines). But this information is available from the OSM API by reference to the OSM id in the 'id' field of all geographic entities.

For building outlines, the OSM API supports:

 http://osm.org/api/0.6/way/<ID>
 http://osm.org/api/0.6/way/<ID>/full
 http://osm.org/api/0.6/way/<ID>/relations

Note however that a building doesn't have to be just a single closed way, since it can have have holes in the area. These are handled as OSM "multipolygons". In essence, there is an outer way plus a number of inner ways

For example, Churchill West Court (ref CHU016, https://map.cam.ac.uk/v6.json?ref=CHU016&debug=1). The Map API tells you it is a way with id 148247888 and you can plug it into the OSM API thus

 http://www.openstreetmap.org/api/0.6/way/148247888/full

returning

<osm version="0.6" generator="OpenStreetMap server">
<node id="1613469175" lat="52.2128314" lon="0.1013427" version="1" changeset="10553242" user="davidearl" uid="3582" visible="true" timestamp="2012-01-31T20:37:02Z"/>
<node id="1613469065" lat="52.2127198" lon="0.101803" version="1" changeset="10553242" user="davidearl" uid="3582" visible="true" timestamp="2012-01-31T20:36:58Z"/>
...
<nd ref="1613469175"/>
<nd ref="1613469065"/>
...
<tag k="amenity" v="university"/>
<tag k="building" v="yes"/>
<tag k="name" v="West Court"/>
<tag k="operator" v="Churchill College (University of Cambridge)"/>
<tag k="ref" v="CHU016"/>
</way>
</osm>

and http://www.openstreetmap.org/api/0.6/way/148247888/relations gets

<osm version="0.6" generator="OpenStreetMap server">
<relation id="1999559" visible="true" timestamp="2012-01-31T20:40:32Z" version="1" changeset="10553242" user="davidearl" uid="3582">
<member type="way" ref="148247888" role="outer"/>
<member type="way" ref="148248147" role="inner"/>
<tag k="type" v="multipolygon"/>
</relation>
</osm>

telling you it is a multipolygon outer, and giving the info to traverse to the inner as above.