I am trying to change the URL for a smartsheet edit by anyone publication with the following code
Sheet sheet = null;
try {
sheet = smartsheet.sheets().getSheet(sheetId, null);
} catch (SmartsheetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
SheetPublish publish = new SheetPublish.PublishStatusBuilder().setReadOnlyFullEnabled(false).
setReadOnlyLiteEnabled(false).setIcalEnabled(false).setReadWriteEnabled(true).build();
publish.setReadWriteUrl(URL);
smartsheet.sheets().updatePublishStatus(sheet.getId(), publish);
} catch (SmartsheetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When I run this I get an InvalidRequestException. I need to be able to change this.
I'm not sure if you are trying to publish a sheet and get the URL or change the URL for a sheet that is already published. I will cover both topics.
First you need to decide what type of publish you would like to do. Below is a short description of each of the publishing types. More info about publishing can be found here.
setReadOnlyLiteEnabled: Lightweight version of the sheet without row attachments or discussions.
setReadOnlyFullEnabled: Rich version of the sheet with the ability to download row attachments and discussions.setReadWriteEnabled: Rich version of sheet with the ability to edit cells and manage row attachments and discussions.
setIcalEnabled: Add key dates from this sheet to your non-Smartsheet calendar
With your example code it looks like you were trying to publish a sheet with the setReadWriteEnabled type. So here is an example that accomplishes that and prints out the URL of where the sheet is published.
SheetPublish sheetPublish = new SheetPublish.PublishStatusBuilder().setIcalEnabled(false).setReadOnlyFullEnabled(false).
setReadOnlyLiteEnabled(false).setReadWriteEnabled(true).build();
SheetPublish sheetPublishResult = smartsheet.sheets().updatePublishStatus(7298027523204996L, sheetPublish);
System.out.println(sheetPublishResult.getReadWriteUrl());
Currently there is not an option to generate a new URL.
If you must remove access to the published sheet at a specific URL, then you can turn off the publish settings by setting the appropriate type to false (e.g. setReadWriteEnabled(false)
).
The smartsheet API (which the Java SDK uses) documents what we can set when publishing a sheet at this location.
Copying the sheet to a new sheet and then publish the new sheet is another option. This would give you a new publish URL since this is a new sheet. This can be accomplished with code like the following
// Setup a sheet to copy
Sheet sheet = new Sheet();
sheet.setFromId(7298027523204996L);
// Copy the sheet
Sheet newSheet = smartsheet.sheets().createSheetFromExisting(sheet, EnumSet.allOf(ObjectInclusion.class));
// Setup what we will publish
SheetPublish sheetPublish = new SheetPublish.PublishStatusBuilder().setIcalEnabled(false).setReadOnlyFullEnabled(false).
setReadOnlyLiteEnabled(false).setReadWriteEnabled(true).build();
// publish the new sheet
SheetPublish sheetPublishResult = smartsheet.sheets().updatePublishStatus(newSheet.getId(), sheetPublish);
System.out.println(sheetPublishResult.getReadWriteUrl());