I am trying to write a simple program in Java using the Smartsheet API that goes through a fairly large sheet, and indents certain rows. Here is some code similar to what I'm using.
Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken("[My Access Token]").build();
sheetId = 00000000000000; // My Sheet ID
Sheet sheet = smartsheet.sheetResources().getSheet(sheetId, null, null, null, null, null, null, null);
List<Row> rows = sheet.getRows();
Row row = new Row();
row.setId(rows.get(2).getId()); // Updating the second row of the sheet.
row.setIndent(1);
row.setParentId(rows.get(1).getId()); // Set the parent as the row immediately above (which is not indented).
Cell cell = new Cell();
cell.setColumnId(rows.get(1).getCells().get(0).getColumnId());
cell.setValue("Test");
List<Cell> cells = Arrays.asList(cell);
row.setCells(cells);
rows = Arrays.asList(row);
smartsheet.sheetResources().rowResources().updateRows(sheetId, rows);
When I run this, I always get the following error on the last line.
Exception in thread "main" com.smartsheet.api.InvalidRequestException: Invalid row location.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.smartsheet.api.internal.AbstractResources$ErrorCode.getException(AbstractResources.java:147)
at com.smartsheet.api.internal.AbstractResources.handleError(AbstractResources.java:894)
at com.smartsheet.api.internal.AbstractResources.putAndReceiveList(AbstractResources.java:745)
at com.smartsheet.api.internal.SheetRowResourcesImpl.updateRows(SheetRowResourcesImpl.java:252)
at Test3.main(Test3.java:67)
The indentation seems to be causing this, as if I remove the setIndent(...) line, it runs fine. Am I doing something wrong here? Thank you in advance for your help.
I did not try your specific code, however, my understanding is that you should be able to setIndent without setting the parentId. Use parentId when you are adding new rows, setIndent when you are updating existing rows.