send_api_request.Rd
This is a flexible function for interacting with any of the numerous /api/* endpoints. It functions by taking key = value pairs required for each of the endpoints and crafting the appropriate JSON payload to submit to the server. All end points require a "unToken" to authorize the request - if this is not provided in the key = value pairs, it will automatically be picked up from the "token" parameter, which defaults to the "unToken" element in the session object.
send_api_request(
session,
...,
end_point,
token = session$unToken,
curl_handle = session$curl,
api_baseurl = session$base_url,
api_url = paste0(api_baseurl, end_point),
.curlOpts = list(),
simplify = grepl("list", end_point),
confirm_delete = FALSE
)
api_upload_data(
session,
registration_data,
other_data_column_names,
end_point = "/api/data/upload",
token = session$unToken,
curl_handle = session$curl,
api_baseurl = session$base_url,
api_url = paste0(api_baseurl, end_point),
.curlOpts = list()
)
list, and active session object created by
start_session()
key = value pairs of parameters for each end point
request. These vary by endpoint. For a list of the required
variables for each end point, use
list_endpoint_variable()
. See details for more information.
chracter, the end point for the API
character, the unToken for an active session
an existing curl handle for an active session. If not provided, one will be created just for this call.
character, the base URL for the API
character, the full URL to the endpoint
additional arguments passed to
RCurl::getURL()
logical, whether the result should be coerced to a data.frame. Most often useful for the /api/list/* endpoints
logical, confirm when the endpoint is one of /api/admin/delete/*. Defaults to FALSE, which will require interactive confirmation to proceed. For non-interactive sessions, this must be set to TRUE to complete a delete operation.
data.frame containing registration data to upload. Must have columns named "unAntName", "unTagName", "regDataTime"
character vector, the names of
other columns from the registration_data
to include in
the "data" slot of the data payload. Will be marshalled to JSON
before the upload.
json or data.frame result (depending on value of
simplify
There are some particularities around how the database expects some elements to be created. See the vignette "Telemetry API Administration" for details.
For /api/create/network and /api/create/batch, the antenna and tag
data must first be coerced into the proper format (a nested list) via
create_antenna_data()
and create_batch_tag_data()
,
respectively.
if (FALSE) {
send_api_request(my_session,
createUserInfo = "nothing here",
unUserName = "Matt",
createUserPass = "qwerty",
unToken = my_session$unToken,
end_point = "/api/admin/create/user")
}
if (FALSE) {
test_df = data.frame(unAntName = "NATO-StanNetwork-1",
unTagName = 99999,
regDataTime = format(Sys.time(), "%FT%T%z"),
temp = 39.0,
test2 = 2)
api_upload_data(my_session, test_df, c("temp"))
}