Skip to main content

Demographics

Stable
English and FrenchUS 🇺🇸 and Canada 🇨🇦

Information about the population living around a given location or in a defined area can be retrieved using the v3/demographics endpoint.

warning

The /demographics endpoint uses v3 of the Local Logic API. The v1 and v2 versions of this API are no longer supported.

Anyone still using v1 or v2 is strongly encouraged to migrate to v3 to benefit from a variety of security, data, and format fixes.

Documentation for v1 and v2 APIs has been removed, but can be requested at support@locallogic.co.

Data sources

CountrySource
CanadaCensus 2021
USAAmerican Community Survey 2021

Data availability

TypeCanadaUSA
Household Income
Individual income
Commute mode
Household composition
Population age
Housing tenancy
Language knowledge
Education
Housing type
Mother tongue
Employment status
Children per Household

GET v3/demographics

The data returned describes a wide range of demographic variables, organized by categories. All populated areas in Canada and the US (50 states + District of Columbia) are covered.

GET v3/demographics

This API uses JWT token based authentication. This JWT Bearer token is what is used to populate the Authorization header below.

Instructions on how to retrieve this token can be found at Getting Started.

HeaderStatusDescription
AuthorizationrequiredYour bearer token retrieved from our authorization API, ex. Bearer eyJhbGci...
AcceptrequiredThe datatype to request, this API will return application/json.

QueryString

The region to be queried by the endpoint can be defined two ways: (1) by specifying a lat/lng coordinate, with optional radius/radius_unit parameters, (2) or by providing a polygon parameter.

When using the lat/lng coordinate query method without specifying radius/radius_unit parameters, the endpoint will return data for residents living within a five minute walk of the coordinate. When including radius/radius_unit parameters, the resulting circular area around the lat/lng coordinate will be queried. radius_unit can be either meter or mile.

When using the polygon query method, the demographic data returned will cover residents of the region defined by the polygon area. Polygons are specified using the WKT format. The only accepted type is POLYGON, and holes are not supported. Each polygon point must be defined as a lng/lat coordinate.

API Limitations

  1. The polygon query string has been limited to 5000 chars.
  2. The max north/south east/west distance accepted is 0.5 degrees.
  3. The max count of north/south east/west level 6 geohashes is 1000.
warning

WKT works on x/y planes. Therefore, the coordinates must be sent as lng/lat instead of lat/lng.

ParameterStatusDescription
latoptionalA decimal number between -90 and 90 (Latitude)
lngoptionalA decimal number between -180 and 180 (Longitude)
radiusoptionalA positive float number (Circle radius)
radius_unitoptionalThe unit type of the radius.
Available: meter, mile.
Default: meter
polygonoptionalList of 2D lng/lat points that define a 2D polygon, using the WKT representation
languageoptionalThe language that demographic variable labels will be returned in.
Available: en, fr.
Default: en

Usage examples

require('node-fetch')('https://api.locallogic.co/v3/demographics?' + new URLSearchParams({
lat: 41.847206,
lng: -87.668825,
radius: 500,
radius_unit: "meter",
language: 'en',
}), {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer eyJhbGciOiJ...'
}
})
.then(response => response.json())
.then(body => {
console.log(body)
})
.catch(error => {
console.log(error)
})

Response example

{
"data": {
"type": "demographics",
"attributes": {
"income": {
"label": "Income",
"type": "standalone",
"variables": [
{
"variable": "avg_household_income",
"value": 88555.1858,
"label": "Average household income"
},
{
"variable": "avg_individual_income",
"value": 39706.2035,
"label": "Average individual income"
}
]
},
"commute_mode": {
"label": "Commute mode",
"type": "percent",
"variables": [
{
"variable": "cmtr_transt",
"value": 0.23562293,
"label": "Transit"
},
{
"variable": "cmtr_foot",
"value": 0.011240746,
"label": "Foot"
},
{
"variable": "cmtr_cycle",
"value": 0.019079289,
"label": "Bike"
},
{
"variable": "cmtr_drive",
"value": 0.60276959,
"label": "Drive"
},
{
"variable": "cmtr_other",
"value": 0.016329394,
"label": "Other"
},
{
"variable": "cmtr_none",
"value": 0.11495802,
"label": "None"
}
]
}
}
}
}

In the above example of returned data, there are two categories of demographic data (“Income” and “Commute mode”). These categories have the following fields:

label

  • A display label to describe this category

type: which can be either of the following:

  • percent: this category’s variables are directly related; their values are percentages and theoretically should add up to 1.0 (100%). In practice, values may not add to 100% in all cases due to rounding.
  • standalone: this category’s variables are separate values

variables: A list of several variables for the category, each with the following:

  • variable, a programmatic key that will be constant regardless of language
  • value, the actual demographic value
  • label, a language-specific description which can be used for display purposes

In the above example:

The average household income of the surrounding area is $88,555
The average individual income is $39,706
60.2% of people commute by car
23.5% of people commute by transit
11.4% of people commute by other modes
1.9% of people commute by bicycle
1.1% of people commute by foot

GET v3/demographics/{geog_id}

Fetches demographics data aggregated to the level of Local Logic geographies or neighborhoods, with confidence intervals driven by margin of error in the source data. The data returned describes a wide range of demographic variables, organized by categories. All populated areas in Canada and the US (50 states + District of Columbia) are covered, and data exists for neighborhoods all the way up to metro areas (geography levels 10, 20, 30, and 40).

GET v3/demographics/{geog_id}

Header

This API uses JWT token based authentication. This JWT Bearer token is what is used to populate the Authorization header below.

Instructions on how to retrieve this token can be found at Getting Started.

HeaderStatusDescription
AuthorizationrequiredYour bearer token retrieved from our authorization API, ex. Bearer eyJhbGci...
AcceptrequiredThe datatype to request, this API will return application/json.

QueryString

ParameterStatusDescription
languageoptionalThe language in which to return the neighborhood names.
Accepted values: en, fr
Default: en

Usage examples

require('node-fetch')('https://api.locallogic.co/v3/demographics/g10_dr5rkxmw?' + new URLSearchParams({
language: 'en',
}), {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer eyJhbGciOiJ...'
}
})
.then(response => response.json())
.then(body => {
console.log(body)
})
.catch(error => {
console.log(error)
})

Response example

{
"data": {
"type": "demographics",
"attributes": {
"commute_mode": {
"variables": [
{
"variable": "cmtr_workers_total",
"type": "count",
"value": 16792,
"label": "Number of workers 16 years and over",
"confidence_interval": {
"high_estimate": 17861,
"low_estimate": 15728,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_foot",
"type": "percent",
"value": 0.105347784659,
"label": "Foot",
"confidence_interval": {
"high_estimate": 0.13018103858980467,
"low_estimate": 0.08093139590281085,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_cycle",
"type": "percent",
"value": 0.020366841353,
"label": "Bike",
"confidence_interval": {
"high_estimate": 0.027751310147689376,
"low_estimate": 0.013101476893758932,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_transt",
"type": "percent",
"value": 0.537339209147,
"label": "Transit",
"confidence_interval": {
"high_estimate": 0.5784897570271558,
"low_estimate": 0.4964268699380657,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_drive",
"type": "percent",
"value": 9.9452120057,
"label": "Drive",
"confidence_interval": {
"high_estimate": 0.12696522153406384,
"low_estimate": 0.07479752262982372,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_other",
"type": "percent",
"value": 0,
"label": "Other",
"confidence_interval": {
"high_estimate": 0.0026798475464506905,
"low_estimate": 0,
"confidence_level": 0.9
}
},
{
"variable": "cmtr_none",
"type": "percent",
"value": 0.190090519294,
"label": "None",
"confidence_interval": {
"high_estimate": 0.21712720343020486,
"low_estimate": 0.16335159599809433,
"confidence_level": 0.9
}
}
],
"label": "Commute mode"
},
"household_income": {
"variables": [
{
"variable": "inc_25_30",
"type": "percent",
"value": 0.015357867284,
"label": "$25,000 to $30,000",
"confidence_interval": {
"high_estimate": 0.022602144305998264,
"low_estimate": 0.008113590263691683,
"confidence_level": 0.9
}
},
{
"variable": "inc_200_plus",
"type": "percent",
"value": 0.0208780063749,
"label": "$200,000 or more",
"confidence_interval": {
"high_estimate": 0.23362793393219356,
"low_estimate": 0.1841495218777166,
"confidence_level": 0.9
}
},
{
"variable": "inc_households_total",
"type": "count",
"value": 13804,
"label": "Total Households",
"confidence_interval": {
"high_estimate": 14523,
"low_estimate": 13088,
"confidence_level": 0.9
}
}
],
"label": "Household income"
},
"income_stats": {
"variables": [
{
"variable": "inc_home",
"type": "median",
"value": 112647,
"label": "Median Household Income",
"confidence_interval": {
"high_estimate": 156106,
"low_estimate": 69189,
"confidence_level": 0.9
}
},
{
"variable": "inc_person",
"type": "median",
"value": 68560,
"label": "Median Per Capita Income",
"confidence_interval": {
"high_estimate": 89703,
"low_estimate": 47418,
"confidence_level": 0.9
}
}
],
"label": "Per capita income"
},
},
"meta": {
"language": "en"
}
},
"meta": {
"message": "Successfully called v3/demographics API.",
"type": "LocalLogic.API.Success",
"statusCode": 200
}
}

In the above example of returned data, there are three categories of demographic data (“Commute mode”, "Household income" and "Per capita income"). These categories have the following fields:

label

  • A display label to describe this category

type: which can be either of the following:

  • percent: this category’s variables are directly related; their values are percentages and theoretically should add up to 1.0 (100%). In practice, values may not add to 100% in all cases due to rounding.
  • count: this category’s variables are separate values

variables: A list of several variables for the category, each with the following:

  • variable, a programmatic key that will be constant regardless of language
  • value, the actual demographic value
  • label, a language-specific description which can be used for display purposes
  • confidence_interval, which describes a range and the confidence level (as a ratio) for how often we estimate the true value will fall in the given range

In the above example:

9.9% of people commute by car
53.7% of people commute by transit
10.5% of people commute by foot
2.0% of people commute by bicycle
0.0% of people commute by other modes
The median household income is $112,647 (between $69,189 and $156,106 90% of the time)

SDK Implementations

Demographics is used by two SDKs:

SDKDescription
Local Demographics SDKRetrieves the demographics information near a provided location.
NeighborhoodDemographics SDKRetrieves the demographics information within a given neighborhood.

Error codes

When calling Local Logic’s API, you may receive an HTTP error code. These errors are explained below. In general, error codes starting with “4” are due to an invalid API call and can be fixed on your end, whereas error codes starting with “5” are due to server errors (that is, problems on our end). If you receive something not described here, please contact us at support@locallogic.co.

400 - BadRequest

This error code happens when the request inputs are incorrect. Use the detail field of the response for clarification. Example:

{
"code": "LocalLogic.API.BadRequest",
"detail": "ValidationErrors: AroundEndpoint is invalid:\n\tinclude is invalid: \"bad_input\" is not an acceptable value: \"groceries\", \"restaurants\", \"nightlife\", \"cafes\", \"shopping\", \"daycares\", \"primary_schools\", \"high_schools\""
}

401 - Unauthorized

This error code happens when your API key cannot access specific resources or locations. For example, some API keys can only access certain countries / states / provinces. Feel free to contact us for more information. Example:

{
"code": "LocalLogic.API.Unauthorized",
"detail": "Your API KEY doesn't support this region"
}

403 - Forbidden

This error code happens when you forgot to include security credentials with your request or you are requesting a parameter that you do not have access to. Example:

{
"message": "Forbidden"
}

404 - NotFound

This error code happens when we don’t have data for the requested location. For example, if you send a lat/lng pair for a location in Antarctica, we will return this error as we don’t have data for Antarctica (yet!). Example:

{
"code": "LocalLogic.API.NotFound",
"detail": "No Location Scores found for this location."
}

422 - Unprocessable Entity

This error code is returned when the correct parameters have been sent however, the data they contain is not valid. For example, if you send a lat/lng pair and the latitude is invalid (ie. not in the range [-90, 90]) and/or the longitude is invalid (ie. not in the range [-180, 180]).

{
"message": "Latitude must be within [-90, 90], Longitude must be within [-180, 180], Requires at least lat/lng pair, or geography_ids. None supplied.",
"code": "LocalLogic.API.BadRequest",
"statusCode": 422
}

500 - ServerError

This error code means that an error occurred on our end. Feel free to retry the same request to see if the problem persists. If you received a lot of these errors, please contact us at support@locallogic.co Example:

{
"code": "LocalLogic.API.ServerError",
"detail": "No Location Scores found for this location."
}

502 - BadGateway

This error code means that an error came from our cloud provider. Feel free to retry the same request to see if the problem persists. Example:

{
"message": "Internal server error"
}