diff --git a/R/entrata_request.R b/R/entrata_request.R index a40b2e6..130c9c5 100644 --- a/R/entrata_request.R +++ b/R/entrata_request.R @@ -177,18 +177,11 @@ entrata <- function( validate_entrata_endpoint_method(endpoint, method) validate_entrata_method_params(endpoint, method, method_params) - req_body <- list( - auth = list( - type = "basic" - ), - requestId = 15, - method = list( - name = method, - version = method_version, - params = method_params - ) - ) |> - purrr::compact() + req_body <- derive_req_body( + method = method, + method_version = method_version, + method_params = method_params + ) username <- config$username password <- config$password @@ -253,3 +246,32 @@ entrata <- function( res <- req |> httr2::req_perform(verbosity = verbosity) return(res) } + +#' Derive Entrata API Request Body +#' +#' @description +#' Derives the request body for an Entrata API request. +#' +#' @param method The Entrata API method to use. +#' @param method_version The version of the API method to use. +#' @param method_params A named list of parameters to include in the request body. +#' +#' @return A list representing the request body. +#' +#' @export +#' +#' @importFrom purrr compact +derive_req_body <- function(method, method_version, method_params) { + list( + auth = list( + type = "basic" + ), + requestId = 15, + method = list( + name = method, + version = method_version, + params = method_params + ) + ) |> + purrr::compact() +} diff --git a/man/entrata.Rd b/man/entrata.Rd index f4edf59..27347d1 100644 --- a/man/entrata.Rd +++ b/man/entrata.Rd @@ -115,6 +115,56 @@ by appending to the request's URL path the provided endpoint, assigning the \code{POST} \code{HTTP} Method, adding the necessary authentication, populating the necessary request headers, and deriving the request's body using the provided \code{method} name and \code{params} parameters. See below for details. + +This is the raw format of the base template request: + +\if{html}{\out{
}}\preformatted{POST https://gmhcommunities.entrata.com/api/v1 +Headers: +Content-Type: 'application/json; charset=UTF-8' +Accept: '*/*' +Accept-Language: 'en-US,en;q=0.9' +Cache-Control: 'no-cache' +Connection: 'keep-alive' +Origin: 'https://gmhcommunities.entrata.com' +Pragma: 'no-cache' +Referer: 'https://gmhcommunities.entrata.com/' +Authorization: '' +Body: JSON Encoded Data +}\if{html}{\out{
}} + +where the \code{Authorization} header is a \code{Basic} authentication header with the +provided username and password and the body is a JSON encoded data object using +the provided \code{method} and \code{params}: + +\if{html}{\out{
}}\preformatted{\{ +"data": \{ + "auth": \{ + "type": [ + "basic" + ] + \}, + "requestId": [ + 15 + ], + "method": \{ + "name": [ + "" + ], + "version": [ + "r1" + ], + "params": \{ + "param1": [ + "value1" + ], + "param2": [ + "value2" + ] + \} + \} +\} +\} +}\if{html}{\out{
}} } \seealso{ \href{https://docs.entrata.com/api/v1/documentation/}{Entrata API Documentation}