A Node.js module for interacting with an Open311 API.
A Node.js module for interacting with the Open311 API (GeoReport v2). This module is more than a simple wrapper; it attempts to normalize the response from different Open311 endpoints' interpretation of the Open311 specification to return consistent results, regardless of implementation or format:
npm install open311
var Open311 = ;// Example Open311 Server: City of Baltimore// More options here:var options =endpoint : ""jurisdiction : "baltimorecity.gov";// Create a new Open311 object.var baltimore = options;// Call serviceRequest with service_request_id// to get the status of a specific service request.baltimore;
To use this library, you must instantiate a new Open311 object:
var open311 = new Open311(options).
You can construct by passing a string that corresponds to the id of a city that is defined in the
var baltimore = new Open311('baltimore');
Or, you can pass individual
endpoint: the URL of the Open311 server; required for all methods except
jurisdiction: (optional) the
jurisdiction_idfor a given city, if required
discovery: the URL Service Discovery; required if using
format: the format data should be requested in; only required for XML-only Open311 servers (default:
apiKey: your API key; required if using
All methods use the standard
callback(err, data) format.
Fetches a city's Service Discovery listing that has URLs of Open311 servers. (Standard: Service Discovery)
truethe fetched endpoints will set/overwrite the endpoint URL of the Open311 object (default:
type: when caching, sets the
productionendpoint server (default:
specification: when caching, sets the matching API specification of the endpoint server (default
index: (optional) when caching, if the Service Discovery list multiple servers with identical production/specification settings, this is the index of the resulting matched servers (default:
var baltimore =discovery: "";// Make the API callbaltimore;
Fetches a list of acceptable 311 service request types and their associated service codes. (Standard: GET Service List)
// an example with Washington, DC, which is an XML-only endpointvar dc ="endpoint": """format": "xml""jurisdiction": "dc.gov";// Make the API calldc;
Fetches attributes associated with a service code. Those attributes may be required when submitting a new Service Request (Standard: GET Service Definition )
service_code is the string/number returned from an entry in
Submit a service request. (Standard: POST Service Request)
According to the Open311 specification,
data must include:
address_id: the specification is wiggly here, but
long is near universally required (despite the "OR")
Open311.serviceDefinition) set with the key
attribute[<code>] OR assign
data.attributes to be an object with key/values: e.g. Submitting this:
data ="service_code": "ABANDONED_VEHICLE""lat": 12345"long": 67890"attributes":"license_plate": "A234567""color": "blue"
...will result in the appropriate and standard-compliant attributes being constructed:
data ="service_code": "ABANDONED_VEHICLE""lat": 12345"long": 67890"attribute[license_plate]": "A234567""attribute[color]": "blue"
Fetches the service_request_id from a temporary token that was received when submitting a Service Request. This is unnecessary if the response from creating a service request does not contain a token. (Standard: GET service_request_id from a token)
token should either be a string or number.
Fetch a list of existing service requests based on query parameters (Standard: GET Service Requests)
Optional params might include those on the existing standard, such as:
service_request_id: a comma delimited list of
service_code: filter the by the service request's service_code
end_date: filter by the earliest/latest requested_datetime (when the request was submitted).
status: filter by the status (
Or params might include those not on the standard but widely supported, such as:
page_size: for paging through results
Fetches an individual request by its
service_request_id. (Standard: GET Service Request).
Note that this is just an alias to
Open311.serviceRequests, so instead of submitting a single string/numerical
service_request_id, you can submit an array of them of multiple
e.g. you can do any of these:
// as a stringbaltimore;
// as an arraybaltimore;
// as an even BIGGER arraybaltimore;
// as a comma separated query parameter// ...but why would you ever want to do that?baltimore;