Python SDK API to add rows with Multi Columns to Smartsheet
I have a script that reads columns from my source Smartsheet (SS) and gets the values from the columns in the SS and stores them in variables. This code works. Where I am getting stuck is assigning the variables (2 or more columns) to a new row and then adding the row to the destination SS. For example:
源党卫军,读取第一行并分配以下variables:
- hub_site_clli= value from the source SS from the column named "Hub/Site CLLI"
- hub_site_name = value from the source SS from the column named "Hub/Site Name".
- This code works. Note: The col names on the source SS are the same names of the columns on the destination SS.
Where I'm getting stuck is using the Smartsheet SDK API, assign hub_site_clli and hub_site_name to a new row and then add that row to the destination SS. The destination column IDs for the columns on the destination SS are as follows:
Destination "Hub/Site Name" Column =hub_site_name_col= 123456789123456
Destination Hub/Site CLLI Column =hub_site_clli_col= 5592086053080964
I've looked at and used theSmartsheet's SDK examplesbut it doesn't show me the entire picture. For example,I can't find any examples on how to update 2 or more columns on a row. They all seem to show just one column in the examples.
THIS IS THE CODE I WROTE TO ASSIGN TO A ROW AND APPEND TO THE DESTINATION SS. WHICH DOESN'T WORK.
-----------------------------------------------------------------------------------------------------
hub_site_clli_col = 1088486425710468
hub_site_name_col = 5592086053080964
cin_count_total_col = 7568017969860484
cin_count_deployed_col = 1938518435647364
cin_count_pending_col = 6442118063017860
olt_count_total_col = 4190318249332612
olt_count_deployed_col = 4344071636078468
olt_count_pending_col = 6595871449763716
row_id = 7192002709901188
import smartsheet
smartsheet_client = smartsheet.Smartsheet(access_token)
# Initialize client. Uses the API token in the environment variable "SMARTSHEET_ACCESS_TOKEN"
smartsheet_client = smartsheet.Smartsheet()
# Make sure we don't miss any error
smartsheet_client.errors_as_exceptions(True)
sheet = smartsheet_client.Sheets.get_sheet(
4812284098465668)
# Specify cell values for one row
row_a = smartsheet.models.Row()
row_a.to_top = True
row_a.cells.append({
'column_id':hub_site_name_col,
'value': "YYUUNN"
'column_id':hub_site_clli_col,
'value': "CCIILL123"
})
# Add rows to sheet
response = smartsheet_client.Sheets.add_rows(
4812284098465668, # destination sheet_id
[row_a])
WHAT I WAS EXPECTING:
I was expecting a new row on the destination sheet with thehub_site_nameandhub_site_cllicolumns filled in with hub_site_name = YYUUNN and hub_site_clli = "CCIILL123". But instead I got an error:
AND THIS IS THE ERROR I AM GETTING:
File "./mike.py", line 64, in
add_row()
File "./mike.py", line 30, in add_row
smartsheet_client = smartsheet.Smartsheet(access_token)
File "/home/mtuccillo/.local/lib/python3.8/site-packages/smartsheet/smartsheet.py", line 154, in __init__
self._session = pinned_session(pool_maxsize=max_connections)
File "/home/mtuccillo/.local/lib/python3.8/site-packages/smartsheet/session.py", line 53, in pinned_session
method_whitelist=Retry.DEFAULT_METHOD_WHITELIST.union(['POST'])))
AttributeError: type object 'Retry' has no attribute 'DEFAULT_METHOD_WHITELIST'
Best Answers
-
Genevieve P. Employee Admin
I see you've received a response in the StackOverflow Community on this thread:
I would suggest following-up on that thread as it looks like there are some good tips/tricks!
Cheers,
Genevieve
-
cabbsman ✭✭
Answers
-
Genevieve P. Employee Admin
I see you've received a response in the StackOverflow Community on this thread:
I would suggest following-up on that thread as it looks like there are some good tips/tricks!
Cheers,
Genevieve
-
cabbsman ✭✭
Categories
See below link:<\/p>
https:\/\/smartsheet.redoc.ly\/tag\/groups#operation\/add-group<\/a><\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":227,"urlcode":"api-and-developers","name":"API and Developers"},{"tagID":442,"urlcode":"groups-and-group-management","name":"Groups and Group Management"}]},{"discussionID":106741,"type":"question","name":"Using the API to get attachment URLs","excerpt":"I have PDF row attachments in a sheet. I need to get a direct URL to the attachment but I can't see a way to do this in the API. Using the GUI to \"send\" the file provides a link - so I'm trying to get something similar through the API. I'm aware that the the URL using the GUI method expires after 30 days. I would prefer…","snippet":"I have PDF row attachments in a sheet. I need to get a direct URL to the attachment but I can't see a way to do this in the API. Using the GUI to \"send\" the file provides a link -…","categoryID":320,"dateInserted":"2023-06-21T22:40:34+00:00","dateUpdated":null,"dateLastComment":"2023-06-22T20:21:40+00:00","insertUserID":150432,"insertUser":{"userID":150432,"name":"jzadra","url":"https:\/\/community.smartsheet.com\/profile\/jzadra","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-06-26T19:32:15+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":150432,"lastUser":{"userID":150432,"name":"jzadra","url":"https:\/\/community.smartsheet.com\/profile\/jzadra","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-06-26T19:32:15+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":2,"countViews":33,"score":null,"hot":3374853734,"url":"https:\/\/community.smartsheet.com\/discussion\/106741\/using-the-api-to-get-attachment-urls","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/106741\/using-the-api-to-get-attachment-urls","format":"Rich","tagIDs":[227,268],"lastPost":{"discussionID":106741,"commentID":381846,"name":"Re: Using the API to get attachment URLs","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/381846#Comment_381846","dateInserted":"2023-06-22T20:21:40+00:00","insertUserID":150432,"insertUser":{"userID":150432,"name":"jzadra","url":"https:\/\/community.smartsheet.com\/profile\/jzadra","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-06-26T19:32:15+00:00","banned":0,"punished":0,"private":false,"label":"✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-06-22T20:20:13+00:00","dateAnswered":"2023-06-22T00:36:56+00:00","acceptedAnswers":[{"commentID":381653,"body":" You make a call to<\/p> https:\/\/api.smartsheet.com\/2.0\/sheets\/$Sheet_ID?include=attachments<\/a><\/p> substituting $Sheet_ID for the sheet ID and get the attachment id for each row<\/p> Then call<\/p>