I researched the topic and found this: Google Sheets API Sort column by date The problem is that it sorts by column A.
So I changed it to the following:
request = {
"requests": [
{
"sortRange": {
"range": {
"sheetId": sheet_id,
"startRowIndex": 1,
"startColumnIndex": 0
},
"sortSpecs": [
{
"dataSourceColumnReference": {
"name": "D"
},
"sortOrder": "DESCENDING"
}
]
}
}
]
}
sheets_service.batchUpdate(body=request, spreadsheetId=spreadsheet_id).execute()
But it still sort it by column A.