The purpose of this user guide is to instruct developers and researchers on how to use the Census Data Application Programming Interface (API) to request data from U.S. Census Bureau datasets.
Below are the terms you will need to be familiar with when running an API query, like this one for the dataset, Vintage 2014 Population Estimates: US, State, and PR Total Population and Components of Change (Use Firefox or Chrome):
|We recommend that you use Chrome or Firefox when building and running API queries.|
A variable is each unit of data you are searching for in a dataset. Each variable that you can search for in a dataset has a name, which may be an acronym or meaningful on its own; e.g., STNAME, POP, DATE_.
In larger datasets, such as the American Community Survey, many of these names are based on an alphanumeric code; e.g., B01003_001E (Total Population).
You can find the list of variables in the dataset by visiting the variables page. For example, the variables page for the Vintage 2014 Population Estimates: US, State, and PR Total Population and Components of Change.
You can include up to 50 variables in the same API call, separated by commas.
Most of the time, you have the option to choose the variables you want to include in your API call, but occasionally some datasets have required variables. Required variables are the parameters that you need to include in your search; otherwise, your search will produce no data and will return an error message. The variable table for each dataset lists which variables are required, as shown below in the variables page for the 2014 Population Estimates (Total and Components of Change) Dataset.
Attributes are additional variables you can include in your API call that give more information for the primary variable. For instance, they may provide labels, annotations, notes, margins of error, statistical significance, or flags that are related to your primary variable.
Attributes are available in many datasets and you can explore them in the discovery tool. For example, in the 2019 American Community Survey 1-Year dataset, you can see variables listed in the Attributes column of the discovery tool (shown below).
The get function (get=) specifies the required and selected variables you are requesting the API to give you. For example (use Chrome or Firefox):
The predicate specifies how variables should be filtered or limited, and you can create predicates of geography, string variables, numeric variables, and time (in time series datasets).
In this example, the predicate limits the search on the July 1, 2014 (&DATE_=7) population or housing unit estimate and for all states (&for=state:*):
Below are some examples of predicates that you can use as a guide when building your queries.
The predicate &for restricts the variables by geography at various levels, while &in and %20 restricts to geographic areas smaller than state level. You can include wildcards (*) along with &for and &in.
Examples to get results for a single geography:
Examples to get results for multiple geographies:
|The “Examples” pages in the discovery tool will list the available geographic levels and predicates for your dataset so you don’t have to build these from scratch.|
For more information on Census Bureau geography, visit the Geography webpage.
You can create a predicate of string variables with various restrictions and can include wildcards (*). Below are several examples across different surveys and programs.
Examples to get results for a single variable value:
Examples to get results for multiple variable values:
|You can use wildcards (*) in predicates with string variables and geographies only. You cannot use wildcards in time predicates or predicates with numeric variables.|
You can create a predicate of a range of values for numeric (integer and float) variables. Please note that you cannot build a predicate with wildcards for numeric variables.
Examples from County Business Patterns and the American Community Survey:
|You can use colons (:) to restrict results by a range of variable values for integer and float variables only. You cannot use colons with string variables.|
For some datasets available on the Census Data API, data are stored for multiple points of time in one dataset, rather than across several datasets for individual points of time. When this occurs, we refer to the dataset as a time series dataset. You can find the list of time series datasets in the time series section of the API Discovery Tool.
You can limit by time in most time series datasets by using the predicate &time. Please note that you cannot build a predicate with wildcards (*) for time in a time series dataset. The plus sign (+) is needed for time ranges, such as the time range from 1997 to 2012 (below).
Some time series datasets do not include the variable “time.” Instead, they use other variables such as “Year.” For these time-related variables, check the predicate type in the discovery tool to find out whether you can filter it following the guidelines for string or numeric variables described earlier in this document.
For more information about time series datasets, see the Time Series Dataset Example – International Trade Monthly Exports section of this user guide.
The group function group([insert table ID]) allows you to get results for an entire table in one easy command; e.g. group(S0101). It provides results for all variables without having to individually include them in the API call. Even if the table has more than 50 variables, the group call will provide results for all variables in that table.
For example, this API query provides results for all 912 variables for table S0101 from the American Community Survey https://api.census.gov/data/2019/acs/acs1/subject?get=group(S0101)&for=state:*