We have recently enabled new extensions on the REST V2 APIs, that provide better filtering, chaining (multi-node hops), and expanded DCID resolution.
Node and Observation endpoints
Chaining
The “chaining” operator, +, which allowed for recursive, multiple-hop queries across the graph, was previously only supported for 2 expressions: <-containedInPlace and ->specializationOf. Now, it is supported for any property, in any direction, allowing queries such as the following. (Nesting is limited to 10 levels.)
Get all nodes in a class hierarchy
Get all the child nodes of the Person class, recursively.
https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Person&property=<-subClassOf%2B
Get all ancestors of a place
Get all ancestors of Santa Clara County, recursively.
https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId/06085&property=->containedInPlace%2B
Filtering
Previously only two types of filters were supported: ->specializationOf+{typeOf:StatVarGroup} and <-containedInPlace+{typeOf:PLACE_TYPE}. Now, you can use any combination of filters, using any property and direction. You can even specify multiple values for a filter expression. This allows queries such as the following.
Get a list of all existing statistical variables filtered by 2 property values
Get all statistical variables pertaining to female students.
https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=StatisticalVariable&property=%3C-typeOf{gender:Female,populationType:Student}
Resolve endpoint
Previously, you could only obtain DCID resolutions for places, using a predefined set of properties. Now, you can use any property, on any entity type, to get DCIDs, allowing queries like the following.
Find the DCID of a non-place entity using its name
Look up the DCID of a statistical variable group by its name.
https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Sustainable%20Development%20Goals&property=%3C-name-%3Edcid
Find the DCID of a non-place entity using another field
Look up the DCID of a provenance by its URL.
https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=https://unstats.un.org/sdgs/dataportal&property=%3C-url-%3Edcid
Observation endpoint
The syntax for the Observation API has been simplified so that the select=variable and select=entity parameters are no longer required. Thus, for example, this query, to get the availability of variables for one country:
https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&entity.dcids=country/TGO&select=variable&select=entity
Can now be specified as:
https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&entity.dcids=country/TGO
And this query, to get the observations for population in all counties in a U.S. state:
https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&date=LATEST&variable.dcids=Count_Person&entity.expression=geoId%2F06%3C-containedInPlace%2B%7BtypeOf%3ACounty%7D&select=entity&select=variable&select=date&select=value
Can now be specified as:
https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&date=LATEST&variable.dcids=Count_Person&entity.expression=geoId%2F06%3C-containedInPlace%2B%7BtypeOf%3ACounty%7D&select=date&select=value