Copy multiple files between projects

/action/files/copy

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, to copy a list of files at a time. Note that this call can be used in conjunction with the Datasets API as well as SPARQL to access data from datasets.

πŸ‘

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.

https://cgc-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.

Request

Example request

POST /v2/action/files/copy HTTP/1.1
Host: cgc-api.sbgenomics.com
X-SBG-Auth-Token: 3210a98c1db9318fa9d9273156740f74
curl --data '{"project": "RFranklin/my-project", "file_ids": ["568e69abe9b0307bc0414164"]}' -s -H "X-SBG-Auth-Token: 3210a98c1db9318fa9d9273156740f74" -H "content-type: application/json" -X POST "https://cgc-api.sbgenomics.com/v2/action/files/copy"

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.

Key

Data type of value

Content of value

project

string

The name of the project you want to copy into.

file_ids

a list of strings

The IDs of the files you want to copy.

Example request body

{
    "project": "RFranklin/my-project",
    "file_ids": ["568e69abe9b0307bc0414164", "5721e1bde4b0d1becbf4ebf0"]

}

Header Fields

Name

Description

X-SBG-Auth-Token
required

Your CGC authentication token.

Response

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

Example response body

{
  "568e69abe9b0307bc0414164": {
    "status": "OK",
    "new_file_id": "518cf5f4e4b0307bc0462062",
    "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.

Language