Query Metro Area with nested information about Cities
The Parcl Labs API allows us to retrieve data in more complex ways. In this example we will get a 14 day average for the New York-Newark metropolitan area and their first 10 cities in in alphabetical order. As before we need to add a handful of additional fields to the query
- To get the 14 day aggregation at the Metro level we need to use
parcl_price_feed_aggregate
after we define the geographic level (MSA_NAME
) in this case. - We need to add the nested city query underneath after the price feed aggregate query. Since we are only getting data for 5 cities we have to specify CITY_NAME and how do we want to get that information, in this case in alphabetical order.
- Also lets set the query under cities to only return the 3 day limit on
parcl_price_feed
ordered byDATE
desc (i.e. most recent days)
query pCities {
MSA(where: {MSA_NAME: {_eq: "New York-Newark-Jersey City, NY-NJ-PA"}}) {
MSA_NAME
parcl_price_feed_aggregate(limit: 14, order_by: {DATE: desc}) {
aggregate {
avg {
PARCL_PRICE_FEED
}
}
}
cities(limit: 5, order_by: {CITY_NAME: asc}) {
CITY_NAME
parcl_price_feed(limit: 3, order_by: {DATE: desc}) {
PARCL_PRICE_FEED
DATE
}
}
}
}
And these are the results:
{
"data": {
"MSA": [
{
"MSA_NAME": "New York-Newark-Jersey City, NY-NJ-PA",
"parcl_price_feed_aggregate": {
"aggregate": {
"avg": {
"PARCL_PRICE_FEED": 323.92405795264
}
}
},
"cities": [
{
"CITY_NAME": "Airmont",
"parcl_price_feed": [
{
"PARCL_PRICE_FEED": 341.3143958152173,
"DATE": "2022-10-21"
},
{
"PARCL_PRICE_FEED": 337.0259137499999,
"DATE": "2022-10-20"
},
{
"PARCL_PRICE_FEED": 336.15947946739124,
"DATE": "2022-10-10"
}
]
},
{
"CITY_NAME": "Albertson",
"parcl_price_feed": [
{
"PARCL_PRICE_FEED": 449.60709844565196,
"DATE": "2022-10-18"
},
{
"PARCL_PRICE_FEED": 453.1176557282607,
"DATE": "2022-10-14"
},
{
"PARCL_PRICE_FEED": 449.11529644565195,
"DATE": "2022-10-13"
}
]
},
{
"CITY_NAME": "Allamuchy",
"parcl_price_feed": [
{
"PARCL_PRICE_FEED": 102.34917855555555,
"DATE": "2022-09-22"
},
{
"PARCL_PRICE_FEED": 103.252825875,
"DATE": "2022-07-13"
},
{
"PARCL_PRICE_FEED": 98.15839128571429,
"DATE": "2022-06-24"
}
]
},
{
"CITY_NAME": "Allendale",
"parcl_price_feed": [
{
"PARCL_PRICE_FEED": 341.2188701304348,
"DATE": "2022-09-26"
},
{
"PARCL_PRICE_FEED": 341.6223331304348,
"DATE": "2022-09-19"
},
{
"PARCL_PRICE_FEED": 348.25621704347833,
"DATE": "2022-09-13"
}
]
},
{
"CITY_NAME": "Allenhurst",
"parcl_price_feed": [
{
"PARCL_PRICE_FEED": 784.7925772608696,
"DATE": "2022-09-16"
},
{
"PARCL_PRICE_FEED": 781.0496408478263,
"DATE": "2022-09-14"
},
{
"PARCL_PRICE_FEED": 780.4731289565218,
"DATE": "2022-08-03"
}
]
}
]
}
]
}
}
For a list of all the Metropolitan areas available see this
Updated 15 days ago