Skip to main content
Skip table of contents

Data import using CURL/REST

Import existing DICOM/PDF/XXX data into XNat


  1. project exists in XNat
  2. XNat 1.5.4 (virtual machine image with default user and password)

  3. DICOM data is sorted into sub-directories
  4. using curl and bash

Upload DICOM from a directory structure

The following code first defines some variables like the project and visit id (session) and afterwards uses 'curl' to send a single DICOM file to the pre-archive. From there in a second step it needs to be moved to the archive to be visible.

erg=`curl -H 'Content-Type: application/dicom' \
    "http://localhost:8080/xnat/data/services/import \
?inbody=true&PROJECT_ID=$PROJECT&SUBJECT_ID=$subject&EXPT_LABEL=$session" \
 --data-binary @$u | tr -d [:cntrl:]`

The last part of the command (tr) will remove any control characters from the returned information that we have to use for the next step. 'erg' is used by the following steps as a reference to the uploaded data. The '\' character at the end of each line needs to be the last character and indicates that the command continues.

Mark data as ready

Data in the pre-archive needs to be moved into the archive to be visible for the user. In a first step after all the DICOM files have been moved using the call above we call build/commit to mark the data in the pre-archive as 'READY'.

echo "CALLING URL: $url ($args)"
/usr/bin/curl $args $url

/usr/bin/curl $args $url

Move data from the pre-archive to the archive

Data which is marked 'ready' in the pre-archive can be moved to the archive with:

/usr/bin/curl $args $url

Add PDF data to the session

PDF (and csv) data can be uploaded and is available in the "Manage Files' tab of the session. This could be a report that was created outside of XNat. Binary files do not need to be copied first to the pre-archive.

args="-X PUT -u $USER:$PASSWORD"
curl $args "$url" --data-binary @$u

Update for XNat 1.6.1

I have updated the script to work with a larger number of DICOM files. Before it was only possible to send at most 1,000 DICOM files before getting an error message. The error message was apparently caused by the large number of sessions created each time the authentication '-u x:y' was used in curl. Waiting for 10 minutes closed the sessions again and the script could be run again. The new version of the script creates now a single session that is used throughout the script. for version 1.6.1 with single session sign on

Add demographic information

Right after a subject has been defined I can send demographic information to the system. Somehow this does not work anymore after the data has been moved from the pre-archive to the archive.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.