1

Currently, I am using Alteryx Designer to connect with Smartsheet API and on Alteryx there is the "Choose Table or Specify Query" box which has "SQL Editor" where we have the following code:

SELECT * FROM "Proj PAGE 1__1234567891234567s_" as AM WHERE AM."ABC DEF" IS NOT NULL

Now, what I want to do is use Smartsheet API using Python to pass the above query. The reason is because I want the data where column "ABC DEF" is NOT NULL.

I am able to connect to the Smartsheet API and fetch the entire sheet but I am not aware of how to use the condition to request subset data.

Does anyone know how to achieve this result?

floss
  • 2,603
  • 2
  • 20
  • 37

1 Answers1

0

Not the most efficient solution, but once you've fetched the data from Smartsheet, you could find a specific column in it ("ABC DEF"), and then filter out the rows based on the condition that the value in the "ABC DEF" column isn't null.

    import smartsheet
    
    smartsheet_client = smartsheet.Smartsheet('<Access Token>')
    
    sheet = smartsheet_client.Sheets.get_sheet(<sheet_id>)
    
    abc_def_column_id = None
    for column in sheet.columns:
        if column.title == "ABC DEF":
            abc_def_column_id = column.id
            break
    
    if abc_def_column_id is None:
        print("'ABC DEF' Not found")
    else:
        # Rows where "ABC DEF" is NOT NULL
        filtered_rows = [row for row in sheet.rows if any(cell.value is not None and cell.column_id == abc_def_column_id for cell in row.cells)]
David Greydanus
  • 2,551
  • 1
  • 23
  • 42