pythonpython-requestssmartsheet-api

How do I get all the rows in a Smartsheet by sending an API call using the requests package in python?


I am trying to get just the rows in a smartsheet in a single API call by using the Python requests package instead of the smartsheet SDK. Here is an snippet of my API call to get all the sheets:

payload = {'exclude':'nonexistentCells'}
r = requests.get("https://api.smartsheet.com/2.0/sheets/{sheetID}", headers=smartHeaders, params=payload)

the headers are my Authentication token and my Content-Type.

I tried to use /rows in my request like so:

r = requests.get("https://api.smartsheet.com/2.0/sheets/{sheetID}/rows", headers=smartHeaders, params=payload)

, but unfortunately it does not work and I get a 400 level error code 405. Any help is greatly appreciated.


Solution

  • According to the documentation (https://smartsheet.redoc.ly/tag/rows), the rows section doesn't seem to have any kind of "list" call. You can get, update, and delete rows (and some other unrelated stuff) with a row id, but not getting all rows this way.

    I can, however, get the rows from your original call using my own auth and sheetId. Is there an issue with doing it this way? I convert the response into json and pull out json['rows']

    url = "https://api.smartsheet.com/2.0/sheets/{sheetId}"
    payload={'exclude':'nonexistentCells'}
    response = requests.get(url, headers=headers, data=payload)
    
    json = response.json()
    rows = json['rows']
    
    print(rows)
    print(len(rows))