Copy file

post
https://api.box.com/2.0
/files/:file_id/copy

Creates a copy of a file.

Request

application/json

Path Parameters

stringin pathrequired
12345

The unique identifier that represent a file.

The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL https://*.app.box.com/files/123 the file_id is 123.

Query Parameters

string arrayin queryoptional
id,type,name

A comma-separated list of attributes to include in the response. This can be used to request fields that are not normally returned in a standard response.

Be aware that specifying this parameter will have the effect that none of the standard fields are returned in the response unless explicitly specified, instead only fields for the mini representation are returned, additional to the fields requested.

Request Body

stringin bodyoptional
FileCopy.txt255

An optional new name for the copied file.

There are some restrictions to the file name. Names containing non-printable ASCII characters, forward and backward slashes (/, \), and protected names like . and .. are automatically sanitized by removing the non-allowed characters.

objectin body

The destination folder to copy the file to.

stringnulloptional
0

The ID of folder to copy the file to.

stringin bodyoptional
0

An optional ID of the specific file version to copy.

Response

application/jsonFile

Returns a new file object representing the copied file.

Not all available fields are returned by default. Use the fields query parameter to explicitly request any specific fields.

none

Returns an empty response when the If-None-Match header matches the current etag value of the file. This indicates that the file has not changed since it was last requested.

application/jsonClient error

Returns an error if some of the parameters are missing or not valid.

  • bad_request when a parameter is missing.
application/jsonClient error

Returns an error if either the source file or the destination folder could not be found, or the authenticated user does not have access to either.

  • not_found when the authenticated user does not have access to the source file or the destination folder
application/jsonClient error
  • operation_blocked_temporary: Returned if either of the destination or source folders is locked due to another move, copy, delete or restore operation in process.

    The operation can be retried at a later point.

  • item_name_in_use when a folder with the same name already exists.
application/jsonClient error

An unexpected client error.

post
Copy file
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -X POST https://api.box.com/2.0/files/12345/copy \
     -H 'Authorization: Bearer <ACCESS_TOKEN>'
     -H 'Content-Type: application/json" '
     -d '{
       "parent": {
         "id": "123"
       }
     }'
.NET
string fileId = "11111";
string destinationFolderId = "22222";
var requestParams = new BoxFileRequest()
{
    Id = fileId,
    Parent = new BoxRequestEntity()
    {
        Id = destinationFolderId
    }
};

BoxFile fileCopy = await client.FilesManager.CopyAsync(requestParams);
Java
// Copy a file into the user's root folder
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
BoxFile file = new BoxFile(api, "id");
BoxFile.Info copiedFileInfo = file.copy(rootFolder, "New Name");
Python
file_id = '11111'
destination_folder_id = '44444'

file_to_copy = client.file(file_id)
destination_folder = client.folder(destination_folder_id)

file_copy = file_to_copy.copy(destination_folder)
print('File "{0}" has been copied into folder "{1}"'.format(file_copy.name, file_copy.parent.name))
Node
var fileID = '11111';
var destinationFolderID = '22222';
client.files.copy(fileID, destinationFolderID)
	.then(fileCopy => {
		/* fileCopy -> {
			type: 'file',
			id: '11112',
			file_version: 
				{ type: 'file_version',
				id: '99999',
				sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' },
			sequence_id: '0',
			etag: '0',
			sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
			name: 'My File.pdf',
			description: '',
			size: 68431,
			path_collection: 
				{ total_count: 1,
				entries: 
				[ { type: 'folder',
					id: '0',
					sequence_id: null,
					etag: null,
					name: 'All Files' },
					{ type: 'folder',
					id: '22222',
					sequence_id: null,
					etag: null,
					name: 'Personal Files' } ] },
			created_at: '2017-05-16T15:18:02-07:00',
			modified_at: '2017-05-16T15:18:02-07:00',
			trashed_at: null,
			purged_at: null,
			content_created_at: '2017-05-16T15:18:02-07:00',
			content_modified_at: '2017-05-16T15:18:02-07:00',
			created_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			modified_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			owned_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			shared_link: null,
			parent: 
				{ type: 'folder',
				id: '22222',
				sequence_id: null,
				etag: null,
				name: 'Personal Files' }
			item_status: 'active' }
		*/
	});
iOS
client.files.copy(fileId: "11111", parentId: "0") { (result: Result<File, BoxSDKError>) in
    guard case let .success(copiedFile) = result else {
        print("Error copying file")
        return
    }

    print("Copied file \(copiedFile.name) into folder \(copiedFile.parent.name); copy has file ID \(copiedFile.id)")
}