1

Using Smartsheet Python SDK, I'm running the following code to access Smartsheet to:

  1. Get customer list from "Customer name" column
  2. Update Picklist of "Customer name" column with the customer list get from 1.

import smartsheet

# Initialize Smartsheet client
smartsheet_client = smartsheet.Smartsheet(my SMARTSHEET_ACCESS_TOKEN)
sheet_Customer = 5623822008248192         
column_Customer_name = 4467860205528922      

sheet = smartsheet_client.Sheets.get_sheet(sheet_Customer) 
Customer_list = []
for row in sheet.rows:
   for cell in row.cells:
        if cell.column_id == column_Customer_name:
            Customer_list.append(cell.value)
        
Customer_list.sort()   # ABC Sort

# Specify column properties
column_spec = smartsheet.models.Column({'type': 'PICKLIST', 'options': Customer_list})

# Update customer list to "Customer name" column
response = smartsheet_client.Sheets.update_column(sheet_Customer,column_Customer_name, column_spec)  

The above coding run fine in Pycharm. Now i want to run it in Zapier, but Zapier does not support Python SDK but Python request. Can you help to code the above with Python request so that it can run in Zapier without using SDK?

Appreciate your help.

  • Smartsheet uses standard RESTful operations, you can make the calls manually. See their [API docs](https://smartsheet.redoc.ly/tag/columns#operation/column-updateColumn) for examples using cURL. – Software2 Aug 21 '21 at 13:56

1 Answers1

1

Take a look at the Smartsheet API documentation. The Python SDK is basically just a (somewhat) Pythonic wrapper around the requests library and the REST API.

For example, instead of smartsheet_client.Sheets.get_sheet(sheet_Customer), we could write:

BASE_URL = "https://api.smartsheet.com/2.0/"
HEADERS = {'Authorization': f'BEARER {SMARTSHEET_ACCESS_TOKEN}'}
response = requests.get(BASE_URL + f"sheets/{sheetId}", headers=HEADERS)

Now, because we're using requests, response will be a requests.Response object instead of a smartsheet.model.Sheet. We can get the JSON payload with

payload = response.json()
sheet_id = payload['id']

Et cetera.

Look at the Smartsheet API docs, as well as the Python Requests docs. There are also plenty of third-party resources on requests. Learning requests is eminently worthwhile; it pretty much opens the gates of the entire REST universe to you as a Python developer--most web services don't have Python-native APIs as Smartsheet does.

chiashurb
  • 31
  • 4