Web links are objects that point to URLs. These objects are also known as bookmarks within the Box web application. Web link objects are treated similarly to file objects.
Calling BoxFolder.createWebLink(String name, URL url, String description)
will let you create a new web link with a specified name and description.
BoxFolder folder = new BoxFolder(api, id);
URL url = new URL("https://www.example.com");
folder.createWebLink("Link to Example", url, "This goes to an example page");
Name and description params are optional, so it is possible to create web link
with only one of them or with URL only:
BoxFolder.createWebLink(URL url)
BoxFolder folder = new BoxFolder(api, id);
URL url = new URL("https://www.example.com");
BoxWebLink.Info webLinkInfo = folder.createWebLink(url);
A web link info can be retrieved by calling the getInfo(String... fields)
method.
Optional parameters can be used to retrieve specific fields of the Device Pin object.
BoxWebLink webLink = new BoxWebLink(api, id);
BoxWebLink.Info webLinkInfo = webLink.getInfo();
A web link can be updated by calling the
updateInfo(BoxWebLink.Info fieldsToUpdate)
method.
BoxWebLink webLink = new BoxWebLink(api, id);
BoxWebLink.Info webLinkInfo = webLink.new Info();
webLinkInfo.setName("new name for weblink");
webLink.updateInfo(webLinkInfo);
A web link can be deleted by calling the delete()
method.
BoxWebLink webLink = new BoxWebLink(api, id);
webLink.delete();
You can create a shared link for a web link by calling the
createSharedLink(BoxSharedLinkWithoutPermissionsRequest sharedLinkRequest)
method.
// Optionally we can calculate and set the date when shared link will automatically be disabled
final long ONE_WEEK_MILLIS = 1000 * 60 * 60 * 24 * 7;
long unsharedTimestamp = System.currentTimeMillis() + ONE_WEEK_MILLIS;
Date unsharedDate = new Date(unsharedTimestamp);
BoxWebLink webLink = new BoxWebLink(api, "id");
BoxSharedLinkWithoutPermissionsRequest sharedLinkRequest = new BoxSharedLinkWithoutPermissionsRequest()
.access(OPEN)
.unsharedDate(unsharedDate);
BoxSharedLink sharedLink = webLink.createSharedLink(sharedLinkRequest);
You can remove a shared link for a web link by calling the removeSharedLink
method.
BoxWebLink webLink = new BoxWebLink(api, "12345");
BoxWebLink.Info webLinkInfo = webLink.getInfo();
info.removeSharedLink()
webLink.updateInfo(info)