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.
Publish Type
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.
Publish a sheet with the Java SDK
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.
Change published Sheet URL
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