api_support_notes.md
Available fields for API======================== The Crime Data API is what powers the CDE website (whose code isat[crime-data-explorer](https://github.com/18f/crime-data-explorer). AllAPI requests require an API key which can be provided to you securelyby a FBI CDE team member. All API endpoints are documented in Swagger, and interactivedocumentation can be found at [https://crime-data-api.fr.cloud.gov/swagger-ui/](https://crime-data-api.fr.cloud.gov/swagger-ui/) Note that this documentation is still not feature-complete. Manyfields are missing descriptions and the documentation will focusprimarily on what the frontend developers on the FBI project needbefore making the documentation more accessible. This document is asupplement to the Swagger documentation with some general notes aboutAPI usage. /incidents/----------- This is the endpoint used to query specific records from NIBRS. Itshould not be used to aggregate NIBRS statistics. You can filter by any field in the results of an `/incidents/` query byappending values to the query string in the API call. The`/meta/incidents` API endpoint returns a list of fields that can befiltered on. In some cases, fields might be codes within the FBIdatabase (ie, `state_id` or `offense_type_code`). To get a list ofthose possible values, look for one of the endpoints listed in the`/codes/` API endpoint. /incidents/count---------------- This is the endpoint used to query specific records from SRS aka"Return A" records. It should not be used to aggregate NIBRSstatistics. You can filter by any field in the results of an `/incidents/count` query byappending values to the query string in the API call. The`/meta/incidents/count` API endpoint returns a list of fields that can befiltered on. In some cases, fields might be codes within the FBIdatabase (ie, `state_id` or `offense_type_code`). To get a list ofthose possible values, look for one of the endpoints listed in the`/codes/` API endpoint. You can also filter by any field in `agencies` or its child tables(location, etc.); the handiest place to see these fields is in theresults of an `/incidents/` query. Including `by=field1_name,field2_name,field3_name` in the parameters will group the results by,and show, those field names. Other Endpoints--------------- The `/incidents` and `/incidents/count` endpoints are essentiallybroad by design, so that they could be used to explore futuredirections for the front-end interface. This does not make themespecially performant however, and as the CDE frontend is built, wewill develop more specific and efficient endpoints for elements on theCDE pages. Your best bet is to refer to the Swagger UI for the mostup-to-date listing on all the methods. General filtering rules======================= The API supports filtering for - equality (`fieldname=val`)- inequality (`fieldname!=val`)- comparison (`fieldname>=val`, `fieldname>=val`, `fieldname<val`, `fieldname<=val`) Filters are case-insensitive. The API does not yet support joining filters with OR or partial-string matches.Your input in how to prioritize those is valued. Speed===== Filtered queries will be slow unless an index exists on that table.Currently existingindexes are in `dba/manual_sql/indexes.sql`. They are easy to add - diskspace is the only expense - so please request whatever indexes the apprequires! Pagination========== App supports `page` and `per_page` arguments. Note that for largequeries, the total results returned will be a rough estimate forperformance reasons. This means that if we were to paginate over allrecords, the total nimber of pages might be less or more than thereported number of pages. Queries that are estimated to return lessthan a 1000 records are then precisely counted so that will not be anissue for them.