Get civic service request data from a registered open311 endpoint.
o311_request
queries a single service request by ID.
o311_requests
queries a single page of service requests.
o311_request_all
tries to iterate through all pages of an endpoint
to return a complete dataset of service requests.
Usage
o311_requests(
service_code = NULL,
start_date = NULL,
end_date = NULL,
status = NULL,
page = NULL,
...
)
o311_request(service_request_id, ...)
o311_request_all(
service_code = NULL,
start_date = NULL,
end_date = NULL,
status = NULL,
...,
max_pages = Inf,
progress = TRUE
)
Arguments
- service_code
[character]
IDs of the service types to be queried. Defaults to all available codes of an endpoint. A list of all available service codes can be retrieved using
o311_services
.- start_date, end_date
[POSIXt]
Start date and end date of the query results. Must be date-time objects. If not specified, defaults to the last 90 days.
- status
[character]
Status of the public service ticket. Can be one of
"open"
or"closed"
. IfNULL
, returns all types of tickets.- page
[integer]
Page of the response. Most endpoints paginate their responses in a way that only a limited number of tickets are returned with each query. To retrieve all data, consider using
o311_request_all
.- ...
Further endpoint-specific parameters as documented in the respective endpoint reference.
- service_request_id
[character]
Identifier of a single service request. Request IDs can usually be retrieved from
o311_requests
.- max_pages
[integer]
Number of pages to search until the result is returned.
- progress
[logical]
Whether to show a waiter indicating the current page iteration.
Value
A dataframe containing data on civic service requests. The dataframe can contain varying columns depending on the open311 implementation.
Details
o311_request_all
applies a number of checks to determine when to
stop searching. First, many endpoints return an error if the last page
is exceeded. Thus, if the last page request failed, break.
Second, if exceeding the pagination limit does not return an error, the
response is compared with the previous response. If identical, the
response is discarded and all previous responses returned. Finally,
if the page exceeds max_pages
, the responses up to this point are
returned.
open311 leaves space for endpoints to implement their own request parameters. These parameters can be provided using dot arguments. These arguments are not validated or pre-processed. Date-time objects must be formatted according to the w3c standard. Some more common parameters include:
q
: Perform a text search across all requests.update_after
/updated_before
: Limit request according to request update dates.per_page
: Specifiy the maximum number of requests per page.extensions
: Adds a nested attribute"extended_attributes"
to the response.long
/lat
/radius
: Searches for requests in a fixed radius around a coordinate.
As dot arguments deviate from the open311 standard, they are not guaranteed
to be available for every endpoint and might be removed without further
notice. Refer to the endpoint docs to learn more about custom parameters
(o311_endpoints()$docs
).
Examples
o311_api("zurich")
# \donttest{
if (o311_ok()) {
# retrieve requests from the last two days
now <- Sys.time()
two_days <- 60 * 60 * 24 * 2
o311_requests(end_date = now, start_date = now - two_days)
# retrieve only open tickets
tickets <- o311_requests(status = "open")
# request the first ticket of the previous response
rid <- as.character(tickets$service_request_id[1])
o311_request(rid)
if (interactive()) {
# request all data
o311_request_all()
}
# request data of the first 5 pages
o311_request_all(max_pages = 5)
}
#> Simple feature collection with 1000 features and 13 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 8.471601 ymin: 47.32524 xmax: 8.598776 ymax: 47.43136
#> Geodetic CRS: WGS 84
#> # A tibble: 1,000 × 14
#> service_name agency_sent_datetime title updated_datetime status service_code
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Brunnen/Hydr… 2024-11-07T14:57:09… Hund… 2024-11-07T16:1… closed Brunnen/Hyd…
#> 2 Signalisatio… 2024-11-07T13:17:05… Ich … 2024-11-07T15:2… open Signalisati…
#> 3 Signalisatio… 2024-11-07T11:52:05… Unge… 2024-11-07T13:1… closed Signalisati…
#> 4 Abfall/Samme… 2024-11-07T10:52:04… Am 2… 2024-11-07T10:5… closed Abfall/Samm…
#> 5 Abfall/Samme… 2024-11-07T10:12:05… Tepp… 2024-11-07T11:0… closed Abfall/Samm…
#> 6 Signalisatio… 2024-11-07T09:32:05… Mitt… 2024-11-07T10:0… closed Signalisati…
#> 7 Allgemein 2024-11-07T09:02:05… Kont… 2024-11-07T09:0… closed Allgemein
#> 8 Beleuchtung/… 2024-11-06T23:57:05… Die … 2024-11-07T06:0… open Beleuchtung…
#> 9 Beleuchtung/… 2024-11-06T22:47:05… Röhr… 2024-11-07T06:0… open Beleuchtung…
#> 10 Beleuchtung/… 2024-11-06T22:32:04… Peit… 2024-11-07T06:0… open Beleuchtung…
#> # ℹ 990 more rows
#> # ℹ 8 more variables: description <chr>, requested_datetime <chr>,
#> # service_notice <chr>, detail <chr>, interface_used <chr>,
#> # service_request_id <int>, media_url <chr>, geometry <POINT [°]>
# }