1. RESTAPI Basic Operation Manual
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/archive/projects/PTV000/subjects/Haofei01/experiments/Haofei01_MR1/scans/4/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/archive/projects/PTV000/subjects/Haofei01/experiments/Haofei01_MR1/scans/4/resources/DICOM/files?format=zip" -o dicomfiles.zip
Note: In this above example, PVT000 is the project name, Haofei01 is the subject name, "Haofei01_MRI" is the session/experiment name, "4" is the scan name.
Upload all files into the scan
curl -u username -X PUT "https://xnat.sydney.edu.au/data/archive/projects/PTV000/subjects/Haofei01/experiments/Haofei01_MR1/scans/4/resources/ABC/files" -F "file=@filelist"
Note: In this above example, PVT000 is the project name, Haofei01 is the subject name, "Haofei01_MRI" is the session/experiment name, "4" is the scan name, "ABC" is the subfolder name, and "files" are necessary to be added.
Create folder
curl -u nmil0563 -X PUT "https://xnat.sydney.edu.au/data/archive/projects/PTV000/subjects/Haofei01/experiments/Haofei01_MR1/scans/4/resources/test"
Creates a subfolder under scans/4 named test. Note that no further subdirectories are allowed.
2. How can we determine the project, subject, session/experiments, scan name via the XNAT Web Interface ?
It is troublesome in using the RESTAPI command to list project, as they are in HTML/XML/JSON format. Another straightforward way to retrieve the information is via the XNAT web interface.
From the web interface, we can see the project name is : PVT100, Subject name is: "Haofei01", and session/experiment name is "Haofei01_MRI", Scan name is "4" .
Then we would like to know the directory structure below scan name, so we click on the "Manage Files" on the right side of the "Actions" Page.
So we know that the "DICOM" files have all the DICOM images we need. So it is easy for us to figure out the URL path mentioned above in the RESTAPI manuals.
2.1 What is "scans" vs "Resources" ?
We noticed in the File Manager screenshot above, there are "scans" vs "Resources".
Scans are the folder created by XNAT for the DICOM data. Therefore, all the DICOM related files (NIFTI, snapshot, description, report) can be placed into the folder.
Resources are the folder to keep all the non-DICOM data. By default it is not created. It has to be manually created.
We can click "Add Folder" in the FileManager to create new folder
Click "Create"
Reference
https://wiki.xnat.org/docs16/4-developer-documentation/using-the-xnat-rest-api