Create Shared Link

Create Shared Link

Shared links may be created directly for file or folder resources to generate a read-only URL to permit users with the appropriate access level to view the content.

You may only have one active shared link for a file or folder at any time.

At minimum the information needed to create a shared link will be:

  • The type of resource, either a file or folder.
  • The ID of that resource.

Optionally when creating a shared link the following may be specified:

  • The access level, which may be one of:

    • open: A public shared link. Anyone with the link may access the link.
    • company: Anyone within your enterprise may access the link.
    • collaboration: Anyone collaborated on the content may access the link.
  • An expiration time when the shared link will automatically disable.
  • A password required to access the resource.

If an access level is not specified when creating a shared link it will use the default access level specified by the enterprise admin.

To create a shared link on a file, specify the ID of the file with any optional shared link parameters.

.NET
string fileId = "11111";
var sharedLinkParams = new BoxSharedLinkRequest()
{
    Access = BoxSharedLinkAccessType.open
};
BoxFile file = client.FilesManager.CreateSharedLinkAsync(fileId, sharedLinkParams);
string sharedLinkUrl = file.SharedLink.Url;
Java
BoxFile file = new BoxFile(api, "id");
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
Date unshareDate = new Date();
BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions);
Python
file_id = '11111'

url = client.file(file_id).get_shared_link()
print('The file shared link URL is: {0}'.format(url))
Node
client.files.update('93745', {shared_link: client.accessLevels.DEFAULT})
	.then(file => {
		var sharedLinkURL = file.shared_link.url;
		// ...
	});

To create a shared link on a folder, specify the ID of the folder with any optional shared link parameters.

.NET
var sharedLinkParams = new BoxSharedLinkRequest()
{
    Access = BoxSharedLinkAccessType.open
};
BoxFolder folder = await client.FoldersManager.CreateSharedLinkAsync("11111", sharedLinkParams);
string sharedLinkUrl = folder.SharedLink.Url;
Java
BoxFolder folder = new BoxFolder(api, "id");
SharedLink link = folder.createSharedLink(BoxSharedLink.Access.OPEN, null,
    permissions);
Python
url = client.folder(folder_id='22222').get_shared_link()
print('The folder shared link URL is: {0}'.format(url))
Node
client.folders.update('12345', {shared_link: client.accessLevels.OPEN})
    .then(folder => {
        /* folder -> {
            type: 'folder',
            id: '11111',
            sequence_id: '1',
            etag: '1',
            name: 'Pictures from 2017',
            created_at: '2012-12-12T10:53:43-08:00',
            modified_at: '2012-12-12T11:15:04-08:00',
            description: 'Some pictures I took',
            size: 629644,
            path_collection: 
            { total_count: 1,
                entries: 
                [ { type: 'folder',
                    id: '0',
                    sequence_id: null,
                    etag: null,
                    name: 'All Files' },
                  { type: 'folder',
                    id: '22222',
                    sequence_id: '3',
                    etag: '3',
                    name: 'Archives' } ] },
            created_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User'
                login: 'user@example.com' },
            modified_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            owned_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            shared_link: {
                url: 'https://app.box.com/s/31uw1b0dxr2swzbv1qu8d4ixz1v727dl',
                download_url: null,
                vanity_url: null,
                effective_access: 'open',
                is_password_enabled: false,
                unshared_at: null,
                download_count: 0,
                preview_count: 0,
                access: 'open',
                permissions: {
                    can_download: true,
                    can_preview: true
                },
            parent: 
            { type: 'folder',
                id: '22222',
                sequence_id: '3',
                etag: '3',
                name: 'Archives' },
            item_status: 'active',
            item_collection: 
            { total_count: 1,
                entries: 
                [ { type: 'file',
                    id: '33333',
                    sequence_id: '3',
                    etag: '3',
                    sha1: '134b65991ed521fcfe4724b7d814ab8ded5185dc',
                    name: 'tigers.jpeg' } ],
                offset: 0,
                limit: 100 } }
        */
    });