Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For the full list of commands, see XNAT REST API Directory along with the Tutorials

List projects (will return only the projects the user has access to)

curl -u username "https://xnat.sydney.edu.au/data/archive/projects"

^data is returned in JSON format by default. Modify format using the format parameter with html, xml, json, csv.

^username is the XNAT logon username, password will be prompt.

List projects (in XML format and save to a file)

curl -u username "https://xnat.sydney.edu.au/data/archive/projects/?format=xml" -o projects.xml

List files for an experiment (in XML format and save to a file)

curl -u username "https://xnat.sydney.edu.au/data/projects/[insert project name here]/subjects/[insert subject name here]/experiments/[insert session name here]/scans/[insert scan ID here]/files?format=xml" -o filelist.xml

Download all DICOM files for a scan (in zip format)

curl -u username "https://xnat.sydney.edu.au/data/projects/[insert project name here]/subjects/[insert subject name here]/experiments/[insert session name here]/scans/[insert scan id here]/files?format=zip" -o dicomfiles.zip

For example, below command downloads to dicomfiles.zip that contains all files for existing scan "3980" of existing session "29", that is for existing subject "MH_Brain" of existing project "fang1".

curl -u xufang "https://dev.xnat.sydney.edu.au/data/projects/fang1/subjects/MH_Brain/experiments/29/scans/3980/files?format=zip" -o dicomfiles.zip

Upload all files into the scan

curl -u username -X PUT "https://xnat.sydney.edu.au/data/projects/[insert project name here]/subjects/[insert subject name here]/experiments/[insert session name here]/scans/[insert scan id here]/resources/[insert a custom folder name here]/files?extract=true" -F “file=@compresses-file.zip

For example, below command will decompress test.zip and save all DICOM files into "TEST" folder under existing scan "3980" of existing session "29", that is for existing subject "MH_Brain" of existing project "fang1". You can specify the name of folder, if not existed, it'll be created.

curl -u xufang -X PUT "https://dev.xnat.sydney.edu.au/data/projects/fang1/subjects/MH_Brain/experiments/29/scans/3980/resources/TEST/files?extract=true" -F "file=@test.zip"

Create folder

curl -u username -X PUT "https://xnat.sydney.edu.au/data/projects/[insert project name here]/subjects/[insert subject name here]/experiments/[insert session name here]/scans/[insert scan id here]/resources/[insert a custom folder name here]"

For example, below command creates a sub-folder "TEST3" under scan named "3980" of existing session "29", that is for existing subject "MH_Brain" of existing project "fang1". Note that no further sub-directories are allowed.

curl -u xufang -X PUT "https://xnat.sydney.edu.au/data/projects/fang1/subjects/MH_Brain/experiments/29/scans/3980/resources/TEST3"