pythonexcelsmartsheet-apismartsheet-api-2.0

How to gather row id's of sheet that is being imported?


I am currently trying to move rows from a sheet I import, into another existing sheet. As of right now I am using result.data.id to return the sheet id that will be associated with the imported sheet. For further clarification here is the line of code I am using to move the rows.

response =smart.Sheets.move_rows(result.data.id,smart.models.CopyOrMoveRowDirective({'row_ids': [**IDK**],'to': smart.models.CopyOrMoveRowDestination({'sheet_id': 1174866712913796})}))

I run into my issue when it prompts me to enter the row ids that I am trying to move into the existing sheet. As the imported sheet has not been created yet, I can not reference the row ids within the smart sheet. My question is: Is there something similar to result.data.id but for row ids? Or is there something else I can enter for row_ids that will just move all the rows in a sheet?


Solution

  • If you're wanting to copy all rows from the sheet you've just imported, you should be able to use the Copy Rows operation. As the documentation shows:

    Here's an example request in Python:

    response = smart.Sheets.copy_sheet(
      4583173393803140,                               # sheet_id
      smartsheet.models.ContainerDestination({
        'destination_type': 'folder',               # folder, workspace, or home
        'destination_id': 9283173393803140,         # folder_id
        'new_name': 'newSheetName'
      })
    )
    

    UPDATE (list rows):

    Since I now understand that you want to copy all rows from the sheet you import into another sheet that already exists, the Copy Sheet approach that I've described above isn't appropriate.

    Instead, after you've imported the sheet, you can use the Get Sheet operation to get data about the sheet you've imported. Here's an example of the Get Sheet operation in Python:

    sheet = smartsheet_client.Sheets.get_sheet(
      4583173393803140)           # sheet_id
    

    The response will contain (amongst other things), a rows property, which is an array of Row objects, representing all of the rows in the imported sheet. Each Row object contains an id property that specifies the ID of the row.

    You'll need to iterate through that array of Row objects, adding the value of each id property to a comma-delimited list of IDs -- this will give you the list of IDs that the Move Rows to Another Sheet operation requires.