Skip to content

Commit

Permalink
feat: create and delete groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Jan 5, 2024
1 parent 9ecf48e commit 20ae1f8
Show file tree
Hide file tree
Showing 34 changed files with 183 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(adjust_tableau_font_style)
export(adjust_tableau_size)
export(authenticate_server)
export(check_dashboard_names)
export(create_group)
export(download_filtered_tableau_image)
export(download_tableau_crosstab_excel)
export(download_tableau_data)
Expand Down
50 changes: 50 additions & 0 deletions R/create_group.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' Create Group
#'
#' Creates a group on Tableau Server or Tableau Cloud site.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, and `site_id`.
#' @param group_name The name of the group to create.
#' @param api_version The API version to use (default: 3.19).
#'
#' @return The ID of the new group.
#' @export
#'
#' @family Tableau REST API
create_group <- function(tableau, group_name, api_version = 3.19) {
base_url <- tableau$base_url
token <- tableau$token
site_id <- tableau$site_id

url <- paste0(
base_url,
"/api/",
3.19,
"/sites/",
site_id,
"/groups"
)

# Construct the request body
request_body <- paste0(
"<tsRequest>",
"<group name=\"", group_name, "\"/>",
"</tsRequest>"
)

api_response <- httr::POST(
url,
httr::add_headers("X-Tableau-Auth" = token),
body = request_body
)

# Check the response status code
if (httr::status_code(api_response) != 201) {
stop("Group creation failed. Please check your API key and base URL.")
}

# Extract the ID of the new group from the Location header
location_header <- httr::headers(api_response)$location
group_id <- stringr::str_extract(location_header, "\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}")

return(group_id)
}
31 changes: 31 additions & 0 deletions R/delete_group.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Delete Group
#'
#' Deletes the specified group from the site.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`, and `site_id`.
#' @param group_id The ID of the group to delete.
#' @param api_version The API version to use (default: 3.19).
delete_group <- function(tableau, group_id, api_version = 3.19) {
base_url <- tableau$base_url
site_id <- tableau$site_id
token <- tableau$token

url <- paste0(
base_url,
"api/",
api_version,
"/sites/",
site_id,
"/groups/",
group_id
)

api_response <- httr::DELETE(url,
httr::add_headers("X-Tableau-Auth" = token)
)

# Check the response status code
if (httr::status_code(api_response) != 204) {
stop("Group deletion failed. Please check your API key and base URL.")
}
}
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@
- [ ] Update Subscription
- [x] Add User to Group
- [x] Add User to Site
- [ ] Create Group
- [ ] Delete Group
- [x] Create Group
- [x] Delete Group
- [ ] Delete Users from Site with CSV
- [x] Get Groups for a User
- [x] Get Users in Group
Expand Down
1 change: 1 addition & 0 deletions man/add_tags_to_view.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/add_tags_to_workbook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/add_user_to_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/add_user_to_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/authenticate_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions man/create_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/delete_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_filtered_tableau_image.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_tableau_crosstab_excel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_tableau_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_workbooks_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_workbooks_server_pdf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/download_workbooks_server_powerpoint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_groups_for_user.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_connected_apps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_datasources.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_jobs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_projects.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_refresh_tasks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_schedules.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_user_favorites.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_users.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_views.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_server_workbooks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_table_assets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/get_users_in_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/remove_user_from_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/remove_user_from_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20ae1f8

Please sign in to comment.