At a certain point during the day, I need to reset the data (to NULL) on a Smartsheet via the C# SDK (Nuget package)
Here's a prototype code snippet
// Connect tp Smartsheet API
SmartsheetClient ss = new SmartsheetBuilder().SetAccessToken(myAccessToken).Build();
// Load in the Sheet
Sheet sheet = ss.SheetResources.GetSheet(mySheetID, null, null, null, null, null, null, null);
// Get the row/cell we want to update
Row dataRow = sheet.Rows[0];
Cell dataCell = dataRow.Cells[9];
UpdateRowBuilder rb = new Row.UpdateRowBuilder(dataRow.Id);
//
// SET THE VALUE OF THE CELL HERE
//
List<Cell> resetCells = new List<Cell>();
resetCells.Add(new Cell.UpdateCellBuilder(dataCell.ColumnId, null).Build());
// Save the Sheet
ss.SheetResources.RowResources.UpdateRows(mySheetID, new List<Row>() { rb.SetCells(resetCells).Build() });
If I set the value of the cell to a (string) value, then all is fine and dandy and the sheet saves, and the value appears
However, if I set the value to NULL then I get an exception...
Smartsheet.Api.InvalidRequestException: Required object attribute(s) are missing from your request: cell.value.
at Smartsheet.Api.Internal.AbstractResources.HandleError(HttpResponse response)
at Smartsheet.Api.Internal.AbstractResources.PutAndReceiveList[T,S](String path, T objectToPut, Type objectClassToReceive)
at Smartsheet.Api.Internal.SheetRowResourcesImpl.UpdateRows(Int64 sheetId, IEnumerable`1 rows)
at LHRMayfly.LHRMayFly_Processor.Reset() in C:\Projects\SmartSheetProcessor.cs:line 173
So, the bottom line question is ... How do you remove a cell value?
Quick answer:
Simply set an empty string as the cell Value. UpdateCellBuilder(dataCell.ColumnId, String.Empty)
Discussion:
Smartsheet doesn't distinguish between different kinds of empty cells. So there is no logical difference between sending a null and an empty string.
The underlying REST/JSON API has a different representation for a missing element and an explicit null. It's more difficult to represent both these cases in a strongly-typed language like C#. (I'm open to suggestions.)