get_user_data: Get data for each user from RapidPro

View source: R/get_user_data.R

get_user_dataR Documentation

Get data for each user from RapidPro

Description

This function retrieves contact data from RapidPro for each user. It is a wrapper function around get_data_from_rapidpro_api and allows for filtering and formatting of the returned data.

Usage

get_user_data(
  rapidpro_site = get_rapidpro_site(),
  token = get_rapidpro_key(),
  call_type = "contacts.json",
  filter_variable = "group",
  filter_variable_value = "joined",
  flatten = FALSE,
  date_from = NULL,
  date_to = NULL,
  format_date = "%Y-%m-%d",
  tzone_date = "UTC",
  unlist_consent = FALSE
)

Arguments

rapidpro_site

A string containing the RapidPro website URL from which to retrieve the data. Use set_rapidpro_site() to amend the website.

token

A string containing the API token required for authentication. Use set_rapidpro_key() to set the token.

call_type

A string specifying the type of data call. The default is "contacts.json". To get user data for a specific group, such as "joined", set this parameter to "contacts.json?group=joined", or, for multiple groups use the filter_variable and filter_variable_value parameters.

filter_variable

A string specifying the variable used to filter the data. The default is "group". This variable is appended to the call_type to form the final API endpoint.

filter_variable_value

A string specifying the value of filter_variable used to filter the data. For example, "joined" can be used to filter contacts by group.

flatten

Logical, default is FALSE. If TRUE, the data will be flattened into a two-dimensional tabular structure.

date_from

A character string representing the start date to filter the data from. The date format should match format_date.

date_to

A character string representing the end date to filter the data to. The date format should match format_date.

format_date

A character string specifying the date-time format, as used by strptime. The default is "%Y-%m-%d".

tzone_date

A character string specifying the time zone for date conversion. The default is "UTC". This parameter is passed to as.POSIXct to ensure correct time zone handling.

unlist_consent

Logical, default is FALSE. If TRUE, any variables containing "consent" in their name will be unlisted, simplifying the data structure.

Details

This function builds the API call to retrieve user data from RapidPro, with optional filtering by group and date. The retrieved data can be flattened into a simple data frame, and optional date filters can be applied. If unlist_consent is set to TRUE, variables containing "consent" will be unlisted to simplify the structure.

Value

A data frame containing the contact data from RapidPro, filtered and formatted according to the specified parameters.

Examples

#\dontrun{
## Set the RapidPro site and API key
#set_rapidpro_site("https://app.rapidpro.io")
#set_rapidpro_key("your_api_key")
#
# # Get data for users in the "joined" group
# user_data <- get_user_data(call_type = "contacts.json", filter_variable = "group", filter_variable_value = "joined")
#
# # Get data for users in the "joined" group, filtering by date range
# user_data <- get_user_data(call_type = "contacts.json", filter_variable = "group", filter_variable_value = "joined", date_from = "2023-01-01", date_to = "2023-12-31")
# }


lilyclements/Rapidreadr documentation built on April 17, 2025, 6:10 p.m.