RPA.Smartsheet
module RPA.Smartsheet
class RPA.Smartsheet.Smartsheet
Smartsheet is a library for accessing Smartsheet using the Smartsheet API 2.0. It extends smartsheet-python-sdk.
class started
To use this library, you need to have a Smartsheet account and an API token.
You can get your API token from the Smartsheet Developer Portal.
This library currently only supports raw token authentication. Once
obtained, you can configure the access token using the Set Access Token
keyword or via the access_token
argument in the library import.
class on a sheet
The library supports working on a single sheet at a time. To select a sheet
to work on, use the Select Sheet
keyword. This will set the sheet as
the active sheet for all subsequent operations. Some operations
update the sheet, but this will not necessarily be reflected in the active
sheet. To refresh the active sheet, use the Refresh Sheet
keyword.
class Smartsheet objects
You can retrieve the native Smartsheet object from many keywords by
specifying the native
argument. The default will return a more
common Python object, such as a dictionary or list. The native object
is a class from the smartsheet-python-sdk library and will have
additional methods and attributes. The most important attributes
available for most native objects are (some may be unavailable
for some objects):
id
: the unique identifier of the objectname
: the name of the objecttitle
: the title of a columnpermalink
: the URL to the object
variable ROBOT_AUTO_KEYWORDS
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
variable ROW_EXCLUDES
List of supported options to remove cells from rows.
variable ROW_INCLUDES
Dictionary of supported additional objects to ask for via include
parameters for rows. Key is the name of the option, value is the
API attribute or function to call.
variable SEARCH_INCLUDES
Dictionary of supported additional objects to ask for via include
parameters for searches. Key is the name of the option, value is the
API attribute or function to call.
variable SEARCH_SCOPES
variable SHEET_INCLUDES
Dictionary of supported additional objects to ask for via include
parameters for sheets. Key is the name of the option, value is the
API attribute or function to call.
method add_column
Adds a column to the current sheet.
Parameters
- title β Column title.
- column_type β Column type, must be a supported type.
Defaults to
TEXT_NUMBER
. - formula β Formula for the column (e.g.,
=data@row
). Defaults toNone
. - hidden β Whether the column is hidden. Defaults to
False
. - index β Index of the column. You can insert a column into
and existing sheet by setting this index. Index is zero-based.
Defaults to
None
which will add the column to the end of the sheet. - description β Column description. Defaults to
None
. - primary β Whether the column is considered the primary
key for indexing and searching. Defaults to
False
. - format_string β Column format using a format descriptor
string. Defaults to
None
. - locked β Whether the column is locked. Defaults to
False
. - options β List of options for a
PICKLIST
orMULTI_PICKLIST
column. Defaults toNone
. - symbol β When a
CHECKBOX
orPICKLIST
column has a display symbol, you can set the type of symbols by selected an appropriate string from the symbol columns definitions. Defaults toNone
. - validation β Whether validation has been enabled. Defaults
to
False
. - width β Column width in pixels. Defaults to
None
.
Examples
method add_columns
Adds columns to the current sheet. Columns must be defined as
a list of dictionaries or Column objects. Dictionaries can have
additional keys set, see Add Column
keyword for more information.
Column types must be supported by the Smartsheet API
- Parameters: columns β Columns as a list of dictionaries or Column objects.
method add_rows
Adds rows to the current sheet with the provided data.
You can provide the data in several ways:
-
As a list of dictionaries: each list item represents a row as a single dictionary. The keys of the dictionary are the column IDs or Titles and the values are the values for the cells.
-
As a list of lists of dictionaries: each sub list item is a row and each dictionary is a cell. The keys of the dictionary should match cell attributes, e.g.,
column_id
,title
,value
, etc. See the`smartsheet API docs`_for more information. The dictionary keys must be provided in snake case. You must use this method to set formulas on the row.
-
As a list of native
Row
objects: eachRow
object is a native object from the API with new values for the cells. -
As a
Table
object: the columns of the Table must either be the column IDs or Titles.
Examples
Robot Framework:
Python:
method convert_row_to_dict
Converts a row object to a dictionary.
method convert_sheet_to_table
Converts the current sheet to table. You can provide a differnt
native sheet object to be converted via the sheet
parameter.
This keyword attempts to return the sheet as a table via
RPA.Tables
, but if that library is not available in this
context, the sheet is returned as its native data model (e.g.,
no operation is performed).
If the sheet contains additional data from the include
argument, they will be appended to the end of the table as
additional columns in the data model. These additional objects
will be attached as a list of objects depending on the items
requested.
method create_sheet
Creates a new sheet with the given name and columns, then sets the current sheet to the new sheet and returns it as a native Smartsheet object.
Parameters
- name β Name of the new sheet.
- columns β List of columns to create in the new sheet.
- from_sheet_id β Sheet ID to use as a template for the new sheet.
Examples
method download_attachment
Downloads the provided attachment from the currently selected
sheet to the provided download_path, which defaults to
the ${OUTPUT_DIR}
.
The attachment can be provided as an integer representing the
attachments ID, a dictionary with at least the key id
or as
the native Attachment
data model type.
Parameters
- attachment β An integar representing the attachment ID, a
dictionary with at least the key
id
, or a nativeAttachment
data model object. - download_path β The path to save the attachment to.
Examples
Robot Framework:
Python:
method get_application_constants
Gets application constants from the server. This is not necessary for most automation scenarios, but may be useful for debugging or for other advanced scenarios.
method get_cell_history
Retrieves the history of a cell in a row of the current sheet.
Parameters
- row β The row ID, row number, or a Row object.
- column β The column ID or title.
Examples
Robot Framework:
Python:
method get_current_user
Gets the current authenticated user, which is also set in the libraryβs memory as the current user. Call this again if you switch user or begin to impersonate a user.
method get_row
Returns a single row from the current sheet.
You can provide the row as a native Row
object or as an
integer representing the row ID.
method get_sheet
Retrieves a sheet from Smartsheet. This keyword also sets the currently selected sheet to the returned sheet.
You cannot provide both a sheet_id
and sheet_name
.
Parameters
- sheet_id β The ID of the sheet to get. You cannot supply
both a
sheet_id
andsheet_name
. - sheet_name β The name of the sheet to get, it will return
the first sheet name matching the provided name. You cannot supply
both a
sheet_id
andsheet_name
. - include β Additional metadata which can be retrieved with
the table. The list can only contain the following items:
attachments
,attachmentFiles
,discussions
,rowPermalink
, orALL
. Note thatattachmentFiles
will only download files if you do not setnative
toTrue
. - row_ids β A list of row IDs to include. All other rows will be ignored. The list can be a list object or a comma-separated list as a string.
- row_numbers β A list of row numbers to include. All other rows will be ignored. The list can be a list object or a comma-separated list as a string.
- column_ids β A list of column IDs to only include, others will not be returned. The list can be a list object or a comma-separated list as a string.
- filter_id β The ID of a filter to apply. Filtered out rows will not be included in the resulting table.
- native β Defaults to
False
. Set toTrue
to change the return type to the native Smartsheet data model. The native type is useful for passing to other keywords as arguments. - download_path β Defaults to
None
. Can be set whenattachmentFiles
is included in theinclude
parameter. All attachments will be downloaded to the provided directory.
Examples
method get_sheet_owner
Returns the ownerβs username and ID for the current sheet.
method list_attachments
Gets a list of all attachments from the currently selected sheet.
This will include attachments to the sheet, rows, and discussions.
Examples
Robot Framework:
Python:
method list_columns
Returns a list of columns for the current sheet.
Parameters
- sheet_id β The ID of the sheet to get columns from.
- sheet_name β The name of the sheet to get columns from.
method list_sheet_filters
Returns a list of available filters for the current sheet. You
can specify a different sheet via the sheet_id
or
sheet_name
parameters.
The returned list of filters can be used with the filter_id
argument of the get_sheet
keyword.
Examples
method list_sheets
Lists all sheets available for the authenticated account. Uses
cached lists if available unless use_cache
is set to False
.
The cached lists is used for other keywords, so if you need to refresh the cache for other keywords to use, you must do so via this keyword.
- Parameters:
use_cache β Defaults to
True
. You can set toFalse
to force a reload of the cached list of sheets.
Examples
method refresh_sheet
Refreshes the current sheet from the API and returns it
either as a Table or native data model depending on the
native
argument.
method search
Searches for all sheets for text matching the query. Returns a list of native Smartsheet Sheet objects. You can use the additional parameters to filter the search and increase speed.
Parameters
-
query β The text to search for.
-
location β The location to search. When specified with a value of
personalWorkspace
, the search will be limited to the current userβs personal workspace. -
modified_since β The date to search from. This can be either a string or an integer. If an integer is provided, it will be interpreted as a Unix timestamp. If a string is provided, it will be parsed via the Robot Framework time utilities, so you can provided it using keywords like
NOW - 1 day
. -
include β When specified with the value of
favoriteFlag
, results will either include afavorite
attribute orparentObjectFavorite
attribute depending on the type of object found by the search engine. -
scopes β
If search fails, try using an array for each type of this comma-separated list of search filters. The following strings can be used to filter the search results:
attachments
: Search in attachments.cellData
: Search in cell data.comments
: Search in comments.folderNames
: Search in folder names.reportNames
: Search in report names.sheetNames
: Search in sheet names.sightNames
: Search in sight names.summaryFields
: Search in summary fields.templateNames
: Search in template names.workspaceNames
: Search in workspace names.
Examples
method set_access_token
Sets the access token to be used when accessing the Smartsheet API.
Learn more about authenticating to Smartsheets here.
- Parameters: access_token β The access token created for your Smartsheet user.
Examples
method set_max_retry_time
Sets the max retry time to use when sending requests to the Smartsheet API. Returns the current max retry time.
- Parameters: max_retry_time β Maximum time to allow retries of API calls. Can be provided as a time string or int.
method set_row
Updates a single row of the current sheet with the provided data.
You can provide the row as a native Row
object or as an
integer representing the row ID. You may omit the data
argument if you are providing a native Row
object.
You can provide the data in several ways:
-
As a dictionary: the keys of the dictionary are the column IDs or Titles and the values are the values for the cells.
-
As a list of dictionaries: each dictionary is a cell. The keys of the dictionary should match cell attributes, e.g.,
column_id
,title
,value
, etc. See the`smartsheet API docs`_for more information. The dictionary keys must be provided in snake case. You must use this method to set formulas on the row.
-
As a native
Row
object: a native object from the API with new values for the cells.
For examples, see Set Rows
.
method set_rows
Updates rows of the current sheet with the provided data.
NOTE
In order to update rows, you must identify the rows to the
API. You can do this by providing the rowId
or rowNumber
as a column in the data. The ID must be the API ID, while the
number is the row number per the UI. This can only be excluded
if the length of the data matches the length of the sheet.
You can provide the data in several ways:
-
As a list of dictionaries: each list item represents a row as a single dictionary. The keys of the dictionary are the column IDs or Titles and the values are the values for the cells.
-
As a list of lists of dictionaries: each sub list item is a row and each dictionary is a cell. The keys of the dictionary should match cell attributes, e.g.,
column_id
,title
,value
, etc. See the`smartsheet API docs`_for more information. The dictionary keys must be provided in snake case. You must use this method to set formulas on the row.
-
As a list of native
Row
objects: eachRow
object is a native object from the API with new values for the cells. -
As a
Table
object: the columns of the Table must either be the column IDs or Titles.
Examples
Robot Framework:
Python:
property sheets
Full list of cached sheets.
method unselect_current_sheet
Resets the current sheet to None.
method update_column
Updates a column in the current sheet. See the Add Column
keyword
for a list of supported attributes.
Parameters
- column β Column ID or title.
- kwargs β Column attributes to update. See
Add Column
keyword for a list of supported attributes.