Add_Row Data Format

Options
versatile_Red00
edited 05/16/24 in API & Developers

Hello,

I am having issues adding rows of data to my sheet through the smartsheet python sdk. I am successfully able to import files and create sheets but when I try using add row via the add_row method, but I see no update or data being added to my sheet. I am even getting SUCCESS status message back from the api request. I am now questioning whether or not my data is in the correct format. The format I am trying to upload is a pandas dataframe converted into an array of dictionaries. All keys in the dictionaries correspond to the columns in the smartsheet. Is this not an acceptable format per the documentation?

Best Answer

  • Miguel Lopes
    Miguel Lopes ✭✭
    Answer ✓
    Options

    Hello Versatile_Red00,

    This might be a reach but have you tried setting the strict variable to false.

    # Specify cell values for one row
    row_a = smartsheet.models.Row()
     row_a.to_top = True
    row_a.cells.append({
      'column_id': 7960873114331012,
      'value': True
    })
    row_a.cells.append({
      'column_id': 642523719853956
      'value': 'New Status',
      'strict': False
    })
    

    This will add the values into the cells even if it does not match the properties.

Answers

  • Brian_Richardson
    Brian_Richardson Overachievers
    Options

    Here's the documentation, sounds like you have it already but just in case:

    https://smartsheet.redoc.ly/

    I don't have any specific suggestions for your use of Python as I use the API over REST HTTP endpoints and JSON.

    One simple tip is that sometimes the rows ARE being added, but you aren't seeing them because they are too far down the page. I know that sounds dumb, but it's caught me out before. Rows add under the last row on the sheet, and if there's a block of blank rows sometimes that add will happen but you need to scroll to find it.

    Otherwise, make sure you're including the location value (toTop, toBottom, etc) and the correct column Ids and you should be ok. Also ensure your destination sheet columns don't have column formulas in them and aren't set to "Restrict" checkboxes in the properties, that can often have unexpected results when using API. API won't write to column formula cells.

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • Brian_Richardson
    Brian_Richardson Overachievers
    Options

    Oh, another tip - Add Rows can only handle 500 row object arrays. That's not really documented anywhere. So you need to chunk up your rows into arrays of 500 or less.

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • Miguel Lopes
    Miguel Lopes ✭✭
    Answer ✓
    Options

    Hello Versatile_Red00,

    This might be a reach but have you tried setting the strict variable to false.

    # Specify cell values for one row
    row_a = smartsheet.models.Row()
     row_a.to_top = True
    row_a.cells.append({
      'column_id': 7960873114331012,
      'value': True
    })
    row_a.cells.append({
      'column_id': 642523719853956
      'value': 'New Status',
      'strict': False
    })
    

    This will add the values into the cells even if it does not match the properties.

  • Brian_Richardson
    Brian_Richardson Overachievers
    Options

    There doesn't seem to be a firm limit on rate, they just say they reserve the right to limit the rate at which you execute the calls. And I don't think there's any limit on total calls, just rate.

    https://smartsheet.redoc.ly/#section/Work-at-Scale/Rate-Limiting

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN