Attention: Confluence is not suitable for the storage of highly confidential data. Please ensure that any data classified as Highly Protected is stored using a more secure platform.
If you have any questions, please refer to the University's data classification guide or contact ict.askcyber@sydney.edu.au

Skip to end of banner
Go to start of banner

XNAT REST API Manuals and examples

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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 POST "çABC/files" -F "file=@abc.txt"

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. 


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.

https://xnat.sydney.edu.au/data/archive/projects/PTV000/subjects/Haofei01/experiments/Haofei01_MR1/scans/4/resources/DICOM/files?format=zip

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

https://wiki.xnat.org/docs16/4-developer-documentation/using-the-xnat-rest-api/downloading-files-via-xnat-rest-api




  • No labels