Query observations
/v2/observation is the endpoint you’ll reach for most: it returns values of a
statistical variable for
one or more places.
The request
Section titled “The request”You need three things:
variable.dcids— what to measure (e.g.Count_Person).entity.dcids— where (e.g.country/BRA), orentity.expressionto expand a relation.select— which fields to return; repeat for each (entity,variable,value,date).
Add date=LATEST to get the most recent value.
curl -G "https://brazildatacommons.com.br/core/api/v2/observation" \ --data-urlencode "variable.dcids=Count_Person" \ --data-urlencode "entity.dcids=country/BRA" \ --data-urlencode "date=LATEST" \ --data-urlencode "select=entity" \ --data-urlencode "select=variable" \ --data-urlencode "select=value" \ --data-urlencode "select=date"import requests
BASE = "https://brazildatacommons.com.br/core/api"resp = requests.get( f"{BASE}/v2/observation", params=[ ("variable.dcids", "Count_Person"), ("entity.dcids", "country/BRA"), ("date", "LATEST"), ("select", "entity"), ("select", "variable"), ("select", "value"), ("select", "date"), ],)resp.raise_for_status()print(resp.json()["byVariable"])const BASE = "https://brazildatacommons.com.br/core/api";const qs = new URLSearchParams();qs.append("variable.dcids", "Count_Person");qs.append("entity.dcids", "country/BRA");qs.set("date", "LATEST");for (const f of ["entity", "variable", "value", "date"]) qs.append("select", f);
const res = await fetch(`${BASE}/v2/observation?${qs}`);const data = await res.json();console.log(data.byVariable);Try it live
Section titled “Try it live”Edit any value and press Run. Newlines in a value expand to a repeated parameter
(that’s how select gets its four entries):
GET URL
/core/api/v2/observation?variable.dcids=Count_Person&entity.dcids=country%2FBRA&date=LATEST&select=entity&select=variable&select=value&select=dateAll states in Brazil at once
Section titled “All states in Brazil at once”Swap entity.dcids for an entity.expression to expand a relation — here, every state
containedInPlace Brazil:
GET URL
/core/api/v2/observation?variable.dcids=Count_Person&entity.expression=country%2FBRA%3C-containedInPlace%7BtypeOf%3AState%7D&date=LATEST&select=entity&select=variable&select=value&select=dateDiscovering variables
Section titled “Discovering variables”Don’t know a variable’s DCID? Search for it, then feed the result back in above:
GET URL
/core/api/v1/variable/search?query=populationSee also
Section titled “See also”- API reference for
/v2/observation— every parameter and the full response shape. - JavaScript SDK — a typed client that wraps these calls.