REST Web Services
You can use this service to retrieve daily statistical data about the hundreds of thousands of hydrologic sites served by the USGS. This service provides USGS water data in WaterML 1.1 (an XML schema) as well as the legacy RDB (tab-delimited) format and a JSON (Javascript-friendly) format.
Please join the USGS Water Data for the Nation Notification List . This way you will receive an announcement when changes are made to this web service, or if it there are significant problems with the service.
With hundreds of thousands of qualifying sites across the nation, the amount of data available is very large. No one user is allowed to download all of the data with a single call. The service has consequently been engineered to facilitate common mass queries, defaulting to returning a narrower set of data. You are encouraged to make your queries efficient too, mindful that many others need access to the data at the same time. Always specify the minimum amount of data you need in your request, using built in filters and date ranges to the maximum extent possible.
Probably the best way to learn how to use the service is to try it out!
The USGS provides this tool that allows you to generate syntactically correct calls to the service. You can even run the query live in your browser. When you have perfected your query you can copy and paste the URL into your application to get the precise data you need.
Typically data is downloaded as plain text via Hypertext Transfer Protocol (HTTP). However, gzip compression is supported by this service. Use of gzip compression may markedly speed up acquisition of data, particularly on large queries. It also is a more efficient use of USGS servers, so we appreciate when you are thoughtful enough to use it. Whether you can receive the data in gzip compressed formats depends on the capabilities of your client. Web browsers support gzip compression natively, but most regular users will use specialized utility programs like wget
and curl
to acquire data. If you can handle gzip compression, please place the following string into your HTTP request headers: Accept-Encoding: gzip, compress
curl and wget are typically used to download data. They may be configured to use gzip compression if the server will accept it. You may also explicitly have to tell it to use gzip compression. If so these tips should work:
gzip files are typically returned as a file with a .gz file suffix unless you instruct your program to uncompress it. See the gzip man page for instructions on uncompressing .gz files.
Please note that recent daily values are frequently qualified as provisional, so the data should be interpreted with caution as it is possible (although unlikely) it will be revised. See the USGS Provisional Data Disclaimer page for more information.
When using format=waterml (the default format), data are returned in XML using the WaterML 1.1 schema
. WaterML
is a schema that has recently been adopted by the Open Geospatial Consortium
. The crucial data are the embedded daily values. A unique daily value can be found inside the <value> tag, which is nested inside the <timeSeries> tag, such as in this example:
By itself this imparts no information as to what the daily value represents, other than the statistic is provisional because qualifiers="P". We do know the value is 14.8 and it represents a daily value for May 2, 2011. We also need to know what was measured. The key to figuring this out is to examine the outer <timeSeries> tag, which contains some important information, shown below in bold:
<ns1:timeSeries name="USGS:01646500:00010:00002">
...
</ns1:timeSeries>
The name attribute contains a sequence of useful information with key fields delimited by colons. The pattern is <agencyCd>:<siteNo>:<parameterCd>:<statisticsCd>.
So this node contains data about site number 01646500 (Little Falls Pumping Station on the Potomac River) monitored by the USGS. Specifically it has a calculated daily statistic for USGS parameter 00010, which is water temperature in degrees Celsius. How do we know this? It is made clear inside the <variable> node within the <timeSeries> node.
<ns1:variable ns1:oid="45807042">
<ns1:variableCode network="NWIS" vocabulary="NWIS:UnitValues" default="true" variableID="45807042">00010</ns1:variableCode>
<ns1:variableName>Temperature, water, °C</ns1:variableName>
<ns1:variableDescription>Temperature, water, degrees Celsius</ns1:variableDescription>
<ns1:valueType>Derived Value</ns1:valueType>
<ns1:unit>
<ns1:unitAbbreviation>deg C</ns1:unitAbbreviation>
</ns1:unit>
<ns1:options>
<ns1:option name="Statistic" optionCode="00002">Minimum</ns1:option>
</ns1:options><ns1:noDataValue>-999999.0</ns1:noDataValue>
</ns1:variable>
Since a daily value is a computation of many regular timeseries measurements, the next question is what statistic is being measured? A mean temperature? Maximum temperature? Minimum temperature? The statistics code is 00002, which the <options> tag nested inside the <variable> tag tells us is minimum (see above).
Putting it altogether, this means that for this site, the provisional minimum water temperature on May 2, 2011 was 14.8 degrees Celsius, or about 59 degrees Fahrenheit.
With other output formats, the location of the data will depend on the syntax of the format. You will need to inspect the format to locate the relevant data.
See the full description of output formats.
Since this system uses Hypertext Transfer Protocol (HTTP), any application errors are reported in the HTTP headers, which are normally not seen. This means that when writing applications, when you get a response it is important to first examine the HTTP status code that is returned in the HTTP response. The application server will return the error code along with a message describing the error in the event there is a problem. Programmers should always check the HTTP response code and if not a 200 handle the response as an exception. Among the status codes you may see:
HTTP Error Code | HTTP Error Code Description | Explanation |
---|---|---|
200 | OK | The request was successfully executed and some data should have been returned. |
304 | Not_Modified | This indicates your request was redirected using the proper URL. This may occur if the "path" of your URL is not fully qualified. Ideally a / is placed before the ? in the URL. Adding in this slash may make this go away. However, the request should still be processed. If this becomes annoying, you may also be able to tell your client program to automatically follow redirects. |
400 | Bad_Request | This often occurs if the URL arguments are inconsistent. An accompanying error should describe why the request was bad. Reasons include:
|
403 | Access_Forbidden | This should only occur if for some reason the USGS has blocked your Internet Protocol (IP) address from using the service. This can happen if we believe that your use of the service is so excessive that it is seriously impacting others using the service. To get unblocked, send us the URL you are using along with your client's IP using this form. We may require changes to your query and frequency of use in order to give you access to the service again. |
404 | Not_Found | Returned if and only if the query expresses a combination of elements where data do not exist. For multi-site queries, if any data are found, it is returned for those site/parameters/date ranges where there are data. Conditions that would return a 404 Not Found include:
|
500 | Internal_Server_Error | If you see this, it means there is a problem with the web service itself. It usually means the application server is down unexpectedly. This could be caused by a host of conditions but changing your query will not solve this problem. The application support team has to fix it. Most of these errors are quickly detected and the support team is notified if they occur. |
503 | Service_Unavailable | The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. |
Adobe Flex requires our server have a crossdomain.xml file
indicating those domains that can access our web service using Adobe Flex. We are adding these on a case by case basis. If you need to access the service using Adobe Flex or the Flex API, please contact us using this form and indicate the domain of the server that will access the service.
This service supports the Cross-Origin Resource Sharing (CORS) specification. CORS permits browser-based asynchronous access to the service even though content originates from a server different than the one serving the web page. Otherwise the browser's security controls would not allow content to come from USGS servers. Most, but not all browsers, support CORS. Some frameworks, like jQuery through the Ajax
crossDomain setting, support CORS automatically.
The URL must always be in this format:
https://waterservices.usgs.gov/nwis/dv/?<arguments>
where <arguments> are one or more HTTP GET parameter names and values based on the information below.
You specify the arguments that go in <arguments>.
Here is an example of a valid URL that should return data:
URL argument names and argument values can be in upper, lower or mixed case. They will all be handled correctly. All of the following will yield the same result:
https://waterservices.usgs.gov/nwis/dv/?stateCd=ny
https://waterservices.usgs.gov/nwis/dv/?statecd=ny
https://waterservices.usgs.gov/nwis/dv/?STATECD=ny
https://waterservices.usgs.gov/nwis/dv/?stateCd=NY
https://waterservices.usgs.gov/nwis/dv/?STATECD=NY
https://waterservices.usgs.gov/nwis/dv/?stateCd=Ny
The following conventions are used below to document URL argument values:
arg1=[ a {,x | ,y} | b | c,d,...]
In the above example, these would be the allowed legal values:
Want to only query one site? Use site (or sites) as your major filter, and put only one site number in the list! Example:
Major Filter (select one of the following) |
Meaning | Minimum Number of Argument Values | Maximum Number of Argument Values | Examples |
---|---|---|---|---|
sites (aliases: site, location) | A list of site numbers. You can specify unlimited sites, up to any limit imposed by the application server or your client. Sites are comma separated. Sites may be prefixed with an optional agency code followed by a colon. If you don't know the site numbers you need, you can find relevant sites with the NWIS Mapper ![]() ![]() |
1 | Unlimited (see caveat) | &site=01646500 &sites=USGS:01646500 &sites=01646500,06306300 |
stateCd (alias: stateCds) |
U.S. postal service (2-digit) state code. USPS List of State Codes. ![]() |
1 | 1 | &stateCd=NY |
huc (alias: hucs) |
A list of hydrologic unit codes (HUC) or aggregated watersheds. Only 1 major HUC can be specified per request. A major HUC has two digits. Minor HUCs must be eight digits in length. Not all sites are associated with a HUC. List of HUCs. ![]() |
1 | 1 Major, 10 Minor | &huc=01,02070010 |
bBox | A contiguous range of decimal latitude and longitude, starting with the west longitude, then the south latitude, then the east longitude, and then the north latitude with each value separated by a comma. The product of the range of latitude and longitude cannot exceed 25 degrees. Whole or decimal degrees must be specified, up to six digits of precision. Minutes and seconds are not allowed. Remember: western longitude (which includes almost all of the United States) is specified in negative degrees. Caution: many sites outside the continental US do not have latitude and longitude referenced to NAD83 and therefore can not be found using these arguments. Certain sites are not associated with latitude and longitude due to homeland security concerns and cannot be found using this filter. | 1 | 1 | &bBox=-83,36.5,-81,38.5 |
countyCd (alias: countyCds) |
A list of county numbers, in a 5 digit numeric format. The first two digits of a county's code are the FIPS State Code. ![]() ![]() |
1 | 20 | &countyCd=51059,51061 |
Many sites have periods of record that can be measured in decades, sometimes fifty years or more. Some sites have been measuring common parameters like streamflow continuously, others are seasonal in nature, and others have had periods when no funding was available to maintain the site so no data are available. Since daily values are by definition daily calculations, it makes no sense to request time periods in less than day increments. Please follow these rules for expressing dates with this service:
I want to... | Do this... | Syntax Rules | Examples |
---|---|---|---|
Get the latest daily values only | Nothing. Only the latest value is returned by default for each requested site, parameter and statistic. |
|
&stateCd=ny¶meterCd=00060 // Get the latest discharge daily values for all sites in New York state |
Get a range of daily values from now | Specify the period argument |
|
&period=P7D // Retrieve last seven days up from now to most recent instantaneous value) |
Get a range of daily values from an explicit begin or end date | Use the startDT and endDT arguments |
|
&startDT=2010-11-22&endDT=2010-11-22 // One day of daily values only |
URL Argument Name | format |
---|---|
Description | Used to specify the output format of the data returned.
|
Syntax | format=[waterml{,1.1} | waterml,2.0 | rdb{,1.0} | json{,1.1}] |
Default | waterml |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | indent |
---|---|
Description | Used to specify whether block structured data formats(&format=waterml|json only) should include indentation for easy viewing. Four space characters are inserted for every level of indentation. Otherwise the parameter is ignored. |
Syntax | indent=[on|off] |
Default | off |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Additional filters can be applied after specifying a major filter. This further reduces the set of expected results. Users are encouraged to use minor filters because it allows more efficient use of this service.
URL Argument Name | parameterCd (aliases: variable, parameterCds, variables, var, vars, parmCd) |
---|---|
Description |
|
Syntax | parameterCd|variable={parameterCd1,parameterCd2,...} |
Default | returns all time-series parameters for the requested sites |
Minimum argument values required | 1 |
Maximum argument values allowed | 100 |
Examples |
|
URL Argument Name | statCd (alias: statisticCd) |
---|---|
Description |
|
Syntax | statCd=[ all | { statCd1,statCd2,... } ] |
Default | all - all statistics codes served for the sites and parameters requested |
Minimum argument values required | 1 |
Maximum argument values allowed | 20 |
Examples |
|
URL Argument Name | siteStatus |
---|---|
Description | Selects sites based on whether or not they are active. If a site is active, it implies that it is being actively maintained. A site is considered active if:
If it does not meet these criteria, it is considered inactive. Some exceptions apply. If a site is flagged by a USGS water science center as discontinued, it will show as inactive. A USGS science center can also flag a new site as active even if it has not collected any data. The default is all (show both active and inactive sites). |
Syntax | siteStatus=[ all | active | inactive ] |
Default | all - sites of any activity status are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | siteType (aliases: siteTypes, siteTypeCd, siteTypeCds) |
---|---|
Description |
|
Syntax | siteType=[all | { siteType1,siteType2,... } ] |
Default | All site types are returned |
Minimum argument values required | 1 |
Maximum argument values allowed | No limit |
Examples |
|
URL Argument Name | modifiedSince |
---|---|
Description |
|
Syntax | modifiedSince=[ISO-8601-duration] |
Default | None |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name | agencyCd (alias: agencyCds) |
---|---|
Description |
|
Syntax | agencyCd=agencyCd1 |
Default | All sites regardless of agency code are retrieved |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Name |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their altitude |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Drainage Area (drainAreaMin and drainAreaMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their drainage area |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Local Aquifer Code (localAquiferCd)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | all |
Minimum argument values required | 0 |
Maximum argument values allowed | 1000 |
Examples |
|
Well Depth (wellDepthMin and wellDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their well depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Hole Depth (holeDepthMin and holeDepthMax)
URL Argument Names |
|
---|---|
Description |
|
Syntax |
|
Default | All sites are retrieved, regardless of their hole depth |
Minimum argument values required | 1 |
Maximum argument values allowed | 1 |
Examples |
|
Here is a simple example using the popular PHP scripting language that retrieves the most recent mean streamflow daily value for all sites marked with the site type in "Stream" Rhode Island. PHP is popular on web servers for serving dynamic content. It may be useful in understanding how to access the service and traverse XML trees but should not be used as a "best practice" way of retrieving data.
Here is an example of using this service with Web 2.0 technologies, specifically Asynchronous Javascript and XML (AJAX), using the service's JSON
format and a Web 2.0 toolkit called jQuery
. This is designed to work in a browser and the jQuery library makes it very portable across browsers.
Please provide any feedback you have on this service using this form.