CDC WONDER API for Data Query Web Service
Access data in the WONDER online databases immediately with automated data queries in XML format over HTTP, for use in your own web pages or widgets.
Send a POST request to the WONDER.cdc.gov web server. The first parameter is the contents of an XML document specifying the request criteria. Consent to abide by the data use restrictions is required, and can be included in the string that is passed as the 1st parameter, or can be passed as optional second parameter. The result of the request will be returned as an XML document. The results include the data table and applicable caveats and footnotes. All data use restrictions are enforced and apply to these data.
The XML document that specifies the request has a specific format and valid parameters specific to each unique online database. Examples and more information, including frequently asked questions are shown below. Please contact us to learn more.
The API Utility is a Java program that sends requests to the WONDER API, if you don't have another way to do that. Please note that you need to be able to compile and run a Java program to use this.
Sending a request:
The request must be a POST which contains one parameter with the name "request_xml" (without the quotes) whose value is the contents of the XML request document, sent to
Please note that, like other CDC websites, the WONDER website now uses https, so be sure to use that in the url to access the API. Each online database has a unique database ID, and a unique set of parameters and measures. In the examples shown here, the database ID is D76. D76 is the online database for Detailed Mortality 1999-2013, at https://wonder.cdc.gov/ucd-icd10.html.
Agreement to abide by data use restrictions:
All access to data and statistics on CDC WONDER, or subsequent re-use of that information, is subject to CDC's data use restrictions policy. The "request_xml" string passed as the first parameter may include this parameter:<value>true</value>
CDC WONDER API Examples and Description
The examples are simple text files, a matched pair for the request ("req.xml") and response ("resp.xml") for the D76 online database for Detailed Mortality 1999-2013, at https://wonder.cdc.gov/ucd-icd10.html.
- U.S. national cancer deaths (ICD-10 codes C00-D48)
by year and by race, for the 5 year time period 2009-2013.
Number of deaths, population estimates, crude death rates
and age-adjusted death rates per 100,000 persons,
95% confidence intervals and standard errors for age-adjusted death rates.
- Example 1 Request
- Example 1 Response
- Example 1 Request
-
U.S. national injury deaths for persons age 18 and under,
by Injury Intent and Injury Mechanism, for years 1999-2013.
Number of deaths, population estimates, crude death rates.
- Example 2 Request
- Example 2 Response
- Example 2 Request
Inside the 1st example request:
The first example data query groups results by year and by race, where cause of death is limited to ICD-10 codes for cancer, and years are limited to 1999-2013. It requests default statistical measures for the number of deaths, population estimates, crude death rates, and optional measures for age-adjusted rates, standard errors for age-adjusted rates, and 95% confidence intervals for age-adjusted rates. The first query asks to show suppressed values, show zero-value rows and totals.
"Example1" request break-down:
- Group results by:
- year (D76.V1-level1);
- and by race (D76.V8);
- where data are limited to:
- cause of death (O_ucd) set to ICD-10 codes (D76.V2) for cancer (C00-D48);
- and years (D76.V1) 1999-2013;
- and show:
- number of deaths (D76.M1);
- population estimates (D76.M2);
- crude death rates (D76.M3);
- age-adjusted rates (D76.M4);
- standard errors for age-adjusted rates (D76.M41);
- 95% confidence intervals for age-adjusted rates (D76.M42);
- suppressed values ("O_show_suppressed" display is true);
- zero-value rows ("O_show_zeros" display is true);
- and totals (O_show_totals).
Inside the 1st example response:
The "example1" response file includes the results table under the "data-table" section. Each "r" defines a row and each "c" is a cell or column's values for that row. Columns, left to right: first the year, then the race, then the number of deaths, the population, the crude death rate, then age-adjusted death rate, a sub-ordinate level "l" value to show the confidence interval range inside and below the age-adjusted death rate, and finally the standard error for the age-adjusted rates. The 2009 row spans 5 subordinate rows (c r="5"), one row for each of the 4 race categories plus the sub-total for the 2009 year. The sub-totals for each year are last (c c="1"). The very last row in the table is the summary total for the rows in the table (c c="2"). The "data-table" is set up by year and by race, because those are the request parameters for "B_1" and "B_2" in the request file.About the 2nd example:
The 2nd example groups results by Injury Intent and by Injury Mechanism, where age is limited to single-year age groups for ages < 18, and where cause of death is set to Injury Intent for the 5 injury categories only. The 2nd example requests default statistical summary measures for the number of deaths, population, and the crude death rate.
"Example2" request break-down:
- Group results by:
- Injury Intent (D76.V22) for "B_1";
- and by Injury Mechanism (D76.V23) for "B_2";
- where data are limited to:
- single-year age groups (O_age value is D76.V52) for ages < 18;
- cause of death is set to Injury Intent (O_ucd values is D76.V22), and D76.V22 is limited to the 5 injury categories only;
- and show:
- number of deaths (D76.M1);
- population estimates (D76.M2);
- crude death rates (D76.M3).
More about WONDER API queries:
These 2 example queries are for mortality data. The vital statistics online databases are open to API queries as of February 23, 2015. However, in keeping with the vital statistics policy for public data sharing, only national data are available for query by the API. Queries for mortality and births statistics from the National Vital Statistics System cannot limit or group results by any location field, such as Region, Division, State or County, or Urbanization (urbanization categories map to specific geographic counties). For example, in the D76 online database for Detailed Mortality 1999-2013, the location fields are D76.V9, D76.V10 and D76.V27, and the urbanization fields are D76.V11 and D76.V19. These 'sub-national" data fields cannot be grouped by or limited via the API, although these fields are available in the web application. The data response page includes more information about the possible request parameters for the specific online database. The response file contains information that supports both drawing the results table and also re-populating the request form for WONDER, including labels, validations and "caveat" messages that may be displayed to the end-user. Thus the response file may give you a broader sense of the metadata that supports possible variable/value pairs in forming a potential data request. Currently, this XML response file doesn't have charts or maps. WONDER uses the data in this response file to generate the input to the charting and mapping functions, after the user clicks on the chart or map tabs.Frequently asked questions for the API:
1) How to send a query? The URL to send the request is the server name (https://wonder.cdc.gov/controller/datarequest ) followed by the dataset code or ID for the specific online database referenced in your query. For the Detailed Mortality 1999-2013 online database, the dataset ID is "D76" as in " https://wonder.cdc.gov/controller/datarequest/D76". The request must be a POST which contains one parameter with the name "request_xml" (without the quotes), whose value is the contents of the XML request document. The WONDER server will then reply with an XML document that contains the results. 2) How to form valid queries with the XML? The valid metadata describing fields in WONDER varies per data set. If you "view source" for any single "Request Form" page, then you see those data items in the select boxes in the form. However, our Finder control makes calls back to the server, to get data for the more complex hierarchical code sets such as ICD chapter/sub-chapter/causes and Regions/States/Counties. You may wish to run a query (via the user interface) that "groups by" the desired fields, and then export the data in order to see the mapping of code value to label for each category in that field. This approach is particularly helpful for hierarchical lists, such as the International Classification of Diseases (ICD), Regions/States/Counties, Vaccine Type/Vaccine, or Year/Month lists. To download XML files with specific query parameters, first send the desired query via the user interface, and after the results display on the Results tab, then click the "API Options" button. 3) What is the key to understanding the query parameters? In the request file:B_ | are "by-variables" or those parameters selected in the "Group Results By" and the "And By" drop-down lists in the "Request Form." These "by-variables" are the cross-tabulations, stratifications or indexes to the query results. Expect the results data table to show a row for each category in the by-variables, and a column for each measure. For example, if you wish to compare data by sex, then "group results by" gender, to get a row for females and a row for males in the output. |
M_ | are measures to return, the default measures plus any optional measures. |
V_ | are variable values to limit in the "where" clause of the query, found in multiple select list boxes and advanced finder text entry boxes in the "Request Form." |
F_ | are values highlighted in a "Finder" control for hierarchical lists, such the "Regions/Divisions/States/Counties hierarchical" list. |
I_ | are the contents of the "Currently selected" information areas next to "Finder" controls in the "Request Form." |
VM_ | are values for non-standard age adjusted rates (see mortality online databases). |
O_ |
are other parameters, such as radio buttons, checkboxes, and
lists that are not data categories (Calculate Rates Per).
Among the things an "O_" may specify:
|
- Credit: If you are running the queries to pull the data into another data analysis system, when the data are "published" in any form, please be sure to include WONDER in the credit ("powered by CDC WONDER" is fine) and also give the official data source citations in the "Suggested Citation" data that comes packaged with the result sets. Some of those citations mention WONDER, in that case, you need not mention it twice.
- Notes: Please be sure to include the footnotes and the "caveats" or explanatory notes that appear below the results set. Those messages are important to the original data providers as part of public data release.
- Suppressions: Also, please be sure to observe the suppression constraints, if you re-assemble the data. Suppression constraints vary per each online database, and these are determined by the data provider, we merely implement these rules in WONDER. The online help for any specific online database describes the suppression constraints imposed, or feel free to ask us for any details. All data on CDC WONDER are covered by the data restrictions described at https://wonder.cdc.gov/datause.html. For more information on the Detailed Mortality confidentiality constraints, see the "About" tab on the user interface or the "About" section in the response XML file, and also see Assurance of Confidentiality for Vital Statistics. Please note that only national data are accessible to API queries for data from the National Vitals Statistics System.