Copy multiple files between projects

This call allows you to copy files between projects. Unlike the call to copy a file between projects, this call lets you batch the copy operation and copy a list of files at a time.

👍

File IDs

Note that a file's ID is dependent on the project it is contained in. So, when you copy files from one project to another, their IDs will be different in the target project.

The file names, however, do not change by copying, except where copying would yield non-unique file names in a project. For details of this use case, see the tipbox at the bottom of the page.

Request

https://api.sbgenomics.com/v2/action/files/copy
https://eu-api.sbgenomics.com/v2/action/files/copy

Files are specified by their IDs, which you can obtain by making the API call to list all files accessible to you.

Example request

POST /v2/action/files/copy HTTP/1.1
Host: api.sbgenomics.com
X-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96
curl --data '{"project": "RFranklin/my-project", "file_ids": ["5655df71e4b08c5d86970945", "5721e1bee4b0d8becbf4ebf0"]}' -s -H "X-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96" -H "content-type: application/json" -X POST "https://api.sbgenomics.com/v2/action/files/copy"
from sevenbridges import Api

api = Api(url='https://api.sbgenomics.com/v2',
          token='3259c50e1ac5426ea8f1273259740f74')

# send POST request to SB API
copy_results = api.actions.bulk_copy_files(
    files=['5655df71e4b08c5d86970945', '5721e1bee4b0d8becbf4ebf0'],
    destination_project='RFranklin/my-project'
)

for original_file_id, copy_result in copy_results.items():
    print(original_file_id, copy_result)

Request body

In the body, you should enter a list of key-value pairs. The keys, and the values they take, are described in the following table.

KeyData type of valueContent of value
projectstringThe name of the project you want to copy into.
file_idsa list of stringsThe IDs of the files you want to copy.

Example request body

{
    "project": "RFranklin/my-project",
    "file_ids": ["5655df71e4b08c5d86970945", "5721e1bee4b0d8becbf4ebf0"]

}

Header Fields

NameDescription
X-SBG-Auth-Token
required
Your Seven Bridges Platform authentication token.

Response

See a list of Seven Bridges Platform-specific response codes that may be contained in the body of the response.

Example response body

{
  "5655df71e4b08c5d86970945": {
    "status": "OK",
    "new_file_id": "568cf5f4e4b0307bc0462062",
    "new_file_name": "sorted.bam"
  }
}

👍

Interpreting the request body

The request returns an object "new_file_name" for every file copied.

The "new_file_name" will be the same as the file's old name in all cases except for the case in which you already have a file with that name in the target project. If an identically-named file exists in the project, then the copied file will be automatically renamed by prefixing it with an increment of 1. For instance, if I copy the file named file.ext to my project, and there already exists a file.ext there, then my incoming file will be renamed 1_file.ext.

It is not possible to re-name files other than by this automatic procedure with this call. If you want to copy and rename a file, use the alternative (non-batch) call to copy a file. This restriction optimizes the batch request: it adds 100ms per file to rename it during copying, so if copying 100 files, it would take 10s longer to rename all of them.