Title: | Access and Write 'Smartsheet' Data using the 'Smartsheet' API 2.0 |
---|---|
Description: | Interact with the 'Smartsheet' platform through the 'Smartsheet' API 2.0. <https://smartsheet.redoc.ly/>. API is an acronym for application programming interface; the 'Smartsheet' API allows users to interact with 'Smartsheet' sheets directly within R. |
Authors: | Cole Johanson [aut, cre, cph] |
Maintainer: | Cole Johanson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-22 03:52:28 UTC |
Source: | https://github.com/cole-johanson/smartsheetr |
Randomly selects letters for a Smartsheet sheet name
random_sheet_name(n = 10)
random_sheet_name(n = 10)
n |
The number of characters to generate |
A character vector
random_sheet_name()
random_sheet_name()
Add columns to an existing sheet
ss_add_columns(ss_id, data, index = 0)
ss_add_columns(ss_id, data, index = 0)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
data |
A data frame of columns to be added |
index |
The index location where the columns should be added |
A ss_addcolumns_resp
object
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_add_columns(ss_id, data.frame("FK"=character()), index=1) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_add_columns(ss_id, data.frame("FK"=character()), index=1) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Add rows to a sheet.
ss_add_rows(ss_id, data, column_ids = NULL)
ss_add_rows(ss_id, data, column_ids = NULL)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
data |
A data frame of rows to be added |
column_ids |
A vector of the columnIds of the smartsheets sheetId. If |
A ss_addrows_resp
object
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_add_rows(ss_id, data.frame("PK"="1")) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_add_rows(ss_id, data.frame("PK"="1")) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
The workhorse function that performs each call to the Smartsheet API
ss_api(FUN, ...)
ss_api(FUN, ...)
FUN |
An http verb function, typically from the |
... |
Further parameters passed to the http verb function |
Helper function to take columns data and create a data frame.
ss_cols_to_dataframe(ss_cols_data)
ss_cols_to_dataframe(ss_cols_data)
ss_cols_data |
A data frame |
Returns a vector of the Smartsheet internal column ids for a given sheet
ss_column_ids(ss_id)
ss_column_ids(ss_id)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
A numeric vector
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) col_names = colnames(ss_read_sheet(ss_id)) col_ids = ss_column_ids(ss_id) setNames(col_ids, col_names) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) col_names = colnames(ss_read_sheet(ss_id)) col_ids = ss_column_ids(ss_id) setNames(col_ids, col_names) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Return the Smartsheet Column Type that aligns with the R class
ss_column_type(r_class)
ss_column_type(r_class)
r_class |
A character vector (returned from a call to |
See https://smartsheet.redoc.ly/tag/columnsRelated/#section/Column-Types
A character vector
The opposite of ss_column_type
ss_column_type_to_class(ss_column_type)
ss_column_type_to_class(ss_column_type)
ss_column_type |
A character vector |
See https://smartsheet.redoc.ly/tag/columnsRelated/#section/Column-Types
A character vector
The primary column(s) cannot be deleted.
ss_delete_columns(ss_id, column_ids = NULL)
ss_delete_columns(ss_id, column_ids = NULL)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
column_ids |
A vector of the smartsheet rowIds, or NULL to delete all non-primary columns |
A list of ss_resp objects
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) col_ids = ss_column_ids(ss_id) ss_delete_columns(ss_id, col_ids[2]) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) col_ids = ss_column_ids(ss_id) ss_delete_columns(ss_id, col_ids[2]) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Delete rows from a given sheet
ss_delete_rows(ss_id, row_ids = NULL)
ss_delete_rows(ss_id, row_ids = NULL)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
row_ids |
A vector of the smartsheet rowIds, or NULL to delete all |
A list of ss_resp objects
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) row_ids = ss_row_ids(ss_id) ss_delete_rows(ss_id, row_ids[2]) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) row_ids = ss_row_ids(ss_id) ss_delete_rows(ss_id, row_ids[2]) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Delete a smartsheet
ss_delete_sheet(ss_id)
ss_delete_sheet(ss_id)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
A ss_resp
object
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_read_sheet(ss_id) ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_read_sheet(ss_id) ss_delete_sheet(ss_id) ## End(Not run)
ss_get()
wraps the httr::GET()
function
ss_post()
wraps the httr::POST()
function
ss_put()
wraps the httr::PUT()
function
ss_delete()
wraps the httr::DELETE()
function
ss_get(path, ...) ss_post(path, body, ...) ss_delete(path, ...) ss_put(path, ...)
ss_get(path, ...) ss_post(path, body, ...) ss_delete(path, ...) ss_put(path, ...)
path |
A character vector to add to the API url. See (https://smartsheet.redoc.ly/#section/Introduction) for more information. |
... |
Further arguments passed to |
body |
A list of objects |
Note that the environment variable SMARTSHEET_API_TOKEN should be defined in order to run this or any
other smarsheetr
functions.
An httr::response object
Get a data frame describing the smartsheets available
ss_list_sheets()
ss_list_sheets()
Note that the environment variable SMARTSHEET_API_TOKEN should be defined in order to run this or any
other smarsheetr
functions.
A dataframe
## Not run: ss_list_sheets() ## End(Not run)
## Not run: ss_list_sheets() ## End(Not run)
List smartsheet users
ss_list_users()
ss_list_users()
A dataframe
## Not run: ss_list_users() ## End(Not run)
## Not run: ss_list_users() ## End(Not run)
Reads a Smartsheet sheet into an R data frame
ss_read_sheet(ss_id)
ss_read_sheet(ss_id)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
A tibble::tbl_df object
## Not run: df = mtcars ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: df = mtcars ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Rename a set of columns. One of the following must be true:
column_names is not NULL
column_locs is not NULL, or
new_names is the same length as the number of columns of the ss_id sheet
ss_rename_columns(ss_id, new_names, column_names = NULL, column_locs = NULL)
ss_rename_columns(ss_id, new_names, column_names = NULL, column_locs = NULL)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
new_names |
A character vector of new names for the chosen columns |
column_names |
A vector of names of columns within the sheet to be replaced |
column_locs |
A vector of locations of columns within the sheet to be replaced |
A list of ss_resp objects
## Not run: df = data.frame("PK"=character(), "temp"=character()) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_rename_columns(ss_id, new_names="FK", column_names="temp") ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: df = data.frame("PK"=character(), "temp"=character()) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_rename_columns(ss_id, new_names="FK", column_names="temp") ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Replace the contents of a sheet with a new data frame
ss_replace_sheet(ss_id, data)
ss_replace_sheet(ss_id, data)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
data |
A data frame |
A named list of ss_resp objects
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_replace_sheet(ss_id, data=mtcars) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ss_replace_sheet(ss_id, data=mtcars) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Helper to rbind lists in a list into a data frame
ss_resp_data_to_dataframe(resp_data)
ss_resp_data_to_dataframe(resp_data)
resp_data |
A list of lists |
Returns a vector of the Smartsheet internal row ids for a given sheet
ss_row_ids(ss_id)
ss_row_ids(ss_id)
ss_id |
The sheetId, permalink, or name of the Smartsheet sheet to read |
A numeric vector
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_row_ids(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: df = data.frame(PK=c(1,2), FK=c("a","b")) ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=df)) ss_row_ids(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Get a smartsheet sheetId from a response
ss_sheetid(resp)
ss_sheetid(resp)
resp |
An ss_resp object |
A numeric sheetId
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()))) ## End(Not run)
Creating a sheet requires either a template or a set of columns (see https://smartsheet.redoc.ly/tag/sheets#operation/create-sheet-in-sheets-folder). This function only allows for the columns option.
ss_write_sheet( sheet_name, data = data.frame(PK = character()), use_rownames = FALSE )
ss_write_sheet( sheet_name, data = data.frame(PK = character()), use_rownames = FALSE )
sheet_name |
A character vector |
data |
A data frame |
use_rownames |
Logical; whether to use the rownames as the Primary Column |
The Smartsheet API 2.0 uses two calls for creating a sheet with data. The first is a call to create a sheet and populate the columns (analogous to ss_write_sheet_columns). The second is to add rows (analogous to ss_add_rows). ss_write_sheet accomplishes both of these steps.
A smartsheetr response object
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=mtcars)) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: ss_id = ss_sheetid(ss_write_sheet(paste0("smartsheetr-example-",random_sheet_name()), data=mtcars)) ss_read_sheet(ss_id) # clean up ss_delete_sheet(ss_id) ## End(Not run)
Write the initial columns for the a sheet
ss_write_sheet_columns(sheet_name, data = data.frame(PK = character()))
ss_write_sheet_columns(sheet_name, data = data.frame(PK = character()))
sheet_name |
A character vector |
data |
A data frame of columns to be added |
The Smartsheet API 2.0 uses two calls for creating a sheet with data. The first is a call to create a sheet and populate the columns (analogous to ss_write_sheet_columns). The second is to add rows (analogous to ss_add_rows). ss_write_sheet accomplishes both of these steps.
A ss_createsheet_resp
object
## Not run: temp_sheet_name = paste0("smartsheetr-example-",random_sheet_name()) ss_id = ss_sheetid(ss_write_sheet_columns(temp_sheet_name, data=mtcars)) ss_read_sheet(ss_id) # No rows. Use ss_write_sheet() to write the full data frame # clean up ss_delete_sheet(ss_id) ## End(Not run)
## Not run: temp_sheet_name = paste0("smartsheetr-example-",random_sheet_name()) ss_id = ss_sheetid(ss_write_sheet_columns(temp_sheet_name, data=mtcars)) ss_read_sheet(ss_id) # No rows. Use ss_write_sheet() to write the full data frame # clean up ss_delete_sheet(ss_id) ## End(Not run)
Helper function to replace NULL values with NA, and unlist, which is useful in converting nested lists to data frames
unlist_and_replace_null(l)
unlist_and_replace_null(l)
l |
A list |
This function validates a single ss_id is passed in and returns a smartsheets sheetId
validate_ss_id(ss_id)
validate_ss_id(ss_id)
ss_id |
A smartsheet sheet name, permalink, of sheetId |
A smartsheets sheetId