I would try adding ?xsiType=xnat:mrSessionData to the end of the URL. So it looks like: "/data/archive/projects/datarelease1_2/subjects/CC00099AN18/experiments/MR_session?xsiType=xnat:mrSessionData"
or "/data/archive/projects/datarelease1_2/subjects/CC00099AN18/experiments/myMrSessionId?xsiType=xnat:mrSessionData"
with whatever session ID you want.
-Mike
The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.
You need to provide a description of the experiment for the PUT call in the form of an XML document. XNAT can create a project or subject with just the information provided on the REST path:
http://10.1.1.17/data/projects/PROJ_ID
http://10.1.1.17/data/projects/PROJ_ID/subjects/SUBJ_ID
The first one creates a project with the ID PROJ_ID, the second creates a subject in project PROJ_ID with the label SUBJ_ID. The issue with experiments is that there are many different types of experiment to create, along with a number of properties that can be set. The easiest way to create a new experiment is PUT an XML document to the REST call. You can do this with a really basic XML descriptor. For your example below the following XML would work:
<xnat:MRSession ID="" label="MR_session" xmlns:xnat="http://nrg.wustl.edu/xnat"/>
You must provide that blank ID attribute, since the XML will not parse without it. For XNATRestClient, you just need to save that to a file, e.g. MR_session.xml, and specify that with the -local parameter.
You can get a lot more complicated with the XML you send to the server, including creating scans, etc., for imaging sessions or other property values for different types of subject or image assessors, but this will get you started. You can get templates to work with by downloading different experiment types from the server. On the page for an existing experiment in the UI, you click on Download XML and use that as a template, or download through REST by doing a GET with “format=xml” added to the query string (I use httpie instead of XNATRestClient, which is no longer supported):
$ http --session=admin xnatdev.xnat.org/data/projects/XNAT_01/subjects/XNAT_01_01/experiments/XNAT_E00008 format==xml
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: keep-alive
Content-Security-Policy: frame-ancestors 'self'
Content-Type: text/xml
Date: Mon, 26 Feb 2018 15:30:08 GMT
Server: nginx/1.10.3 (Ubuntu)
Set-Cookie: SESSION_EXPIRATION_TIME="1519659008810,900000"; Version=1; Path=/
Transfer-Encoding: chunked
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xnat:MRSession ID="XNAT_E00008" project="XNAT_01" label="XNAT_01_01_MR08" xmlns:arc="http://nrg.wustl.edu/arc" xmlns:val="http://nrg.wustl.edu/val" xmlns:pipe="http://nrg.wustl.edu/pipe" xmlns:wrk="http://nrg.wustl.edu/workflow" xmlns:scr="http://nrg.wustl.edu/scr" xmlns:xdat="http://nrg.wustl.edu/security" xmlns:cat="http://nrg.wustl.edu/catalog" xmlns:prov="http://www.nbirn.net/prov" xmlns:xnat="http://nrg.wustl.edu/xnat" xmlns:xnat_a="http://nrg.wustl.edu/xnat_assessments" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nrg.wustl.edu/workflow http://xnatdev.xnat.org/schemas/workflow.xsd http://nrg.wustl.edu/catalog http://xnatdev.xnat.org/schemas/catalog.xsd http://nrg.wustl.edu/pipe http://xnatdev.xnat.org/schemas/repository.xsd http://nrg.wustl.edu/scr http://xnatdev.xnat.org/schemas/screeningAssessment.xsd http://nrg.wustl.edu/arc http://xnatdev.xnat.org/schemas/project.xsd http://nrg.wustl.edu/val http://xnatdev.xnat.org/schemas/protocolValidation.xsd http://nrg.wustl.edu/xnat http://xnatdev.xnat.org/schemas/xnat.xsd http://nrg.wustl.edu/xnat_assessments http://xnatdev.xnat.org/schemas/assessments.xsd http://www.nbirn.net/prov http://xnatdev.xnat.org/schemas/birnprov.xsd http://nrg.wustl.edu/security http://xnatdev.xnat.org/schemas/security.xsd">
<xnat:subject_ID>XNAT_S00001</xnat:subject_ID>
</xnat:MRSession>
HTH.
--
Rick Herrick
Sr. Programmer/Analyst
Neuroinformatics Research Group
Washington University School of Medicine
Phone: +1 (314) 273-1645
From: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com> on behalf of Jianliang Gao <pilla...@gmail.com>
Reply-To: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com>
Date: Monday, February 26, 2018 at 8:51 AM
To: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com>
Subject: [XNAT Discussion] How to use REST API to PUT experiments?
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.
The example with “http xnatdev.xnat.org/data/experiments/XNAT_E00008 format==xml” is a GET operation, if that’s what you referring to. That is just a way to get the XML for an existing data object in XNAT. Note that, if you use the experiment ID, like XNAT_E12345, you don’t need the project and subject, since that ID is unique across the system. In the XML you sent, the subject ID is CC00099AN18, so you could retrieve that with something like (the --download flag just tells httpie to write the response body to a file instead of displaying on stdout):
$ http --download xnatdev.xnat.org/data/experiments/XNAT_E00008 format==xml
I took the subject XML you attached to your last post and edited it down to what I’ve attached here. I then sent that to the server:
$ http --session=admin PUT xnatdev.xnat.org/data/projects/XNAT_01/subjects/XNAT_01_02 < CC00099AN18.xml
HTTP/1.1 201 Created
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 11
Content-Security-Policy: frame-ancestors 'self'
Content-Type: text/plain;charset=ISO-8859-1
Date: Tue, 27 Feb 2018 20:29:19 GMT
Server: nginx/1.10.3 (Ubuntu)
Set-Cookie: JSESSIONID=22531260E66381E5BD3EC404A580598A; Path=/; HttpOnly
Set-Cookie: SESSION_EXPIRATION_TIME="1519763357724,900000"; Version=1; Path=/
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
XNAT_S00003
You’ll need to remove that <experiments> element in the subject you pulled down: the experiments won’t be created as part of the subject creation and won’t resolve properly. But otherwise you can specify just about any other property or attribute you like through the XML.
--
Rick Herrick
Sr. Programmer/Analyst
Neuroinformatics Research Group
Washington University School of Medicine
Phone: +1 (314) 273-1645
From: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com> on behalf of Jianliang Gao <pilla...@gmail.com>
Reply-To: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com>
Date: Tuesday, February 27, 2018 at 3:15 AM
To: "xnat_di...@googlegroups.com" <xnat_di...@googlegroups.com>
Subject: Re: [XNAT Discussion] How to use REST API to PUT experiments?
Thank you very much for your help. I practised Mike's suggestion and yes, I did insert session data successfully. Then I checked my project and subject information and compared to the original metadata from an existing XNAT dataset. I missed some information such as gender, date etc. Here I enclose the xml file of the subject metadata I downloaded from an existing XNAT database using GET method. To be honest I don't quite get Rick's explanation in the second part regarding httpie. The example you demo is equivalent to GET, isn't it? Do you mind to show me how I can PUT the xml to my XNAT database with both methods, XNATRestClient and httpie?
Thank you very much.
Best wishes,
Jianliang
On Monday, 26 February 2018 15:26:47 UTC, Michael McKay wrote:
I would try adding ?xsiType=xnat:mrSessionData to the end of the URL. So it looks like: "/data/archive/projects/datarelease1_2/subjects/CC00099AN18/experiments/MR_session?xsiType=xnat:mrSessionData" or "/data/archive/projects/datarelease1_2/subjects/CC00099AN18/experiments/myMrSessionId?xsiType=xnat:mrSessionData" with whatever session ID you want.
-Mike
The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussion+unsubscribe@googlegroups.com.
To post to this group, send email to xnat_discussion@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.
The issue with the 301 is that the site is redirecting you to the https version of the site. You have two options:
Add the --follow flag to your httpie call:
http --follow http://data.developingconnectome.org/data/archive/projects/DataRelease1_1/subjects/CC00099AN18 format=xml
Or change the URL directly to https:
http https://data.developingconnectome.org/data/archive/projects/DataRelease1_1/subjects/CC00099AN18 format=xml
By default, httpie, just like curl, doesn’t follow 30x redirects from HTTP servers, just displays them. Here’s the curl equivalent:
$ curl http://data.developingconnectome.org/data/archive/projects/DataRelease1_1/subjects/CC00099AN18
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.1</center>
</body>
</html>
Also, I’m pretty certain that you don’t want format=xml on that command, but format==xml. Httpie interprets x=y as a data field to be included in the request body, by default as JSON but can be as a form if the --form parameter is specified. With your version, httpie does this (a lot of extraneous header info removed from the output):
$ http --verbose --session=admin xnatdev.xnat.org/data/projects/XNAT_01/subjects/XNAT_01_01 format=xml
POST /data/projects/XNAT_01/subjects/XNAT_01_01 HTTP/1.1
Accept: application/json, */*
{
"format": "xml"
}
HTTP/1.1 405 Method Not Allowed
Allow: DELETE, PUT, GET, OPTIONS, HEAD
This is really powerful feature and one of the main reasons I use it, but you need to be aware of what it’s doing or you’ll end up getting something other than what you expect! If you change that ‘=’ to ‘==’, you’ll get this:
$ http --verbose --session=admin xnatdev.xnat.org/data/projects/XNAT_01/subjects/XNAT_01_01 format==xml
GET /data/projects/XNAT_01/subjects/XNAT_01_01?format=xml HTTP/1.1
HTTP/1.1 200 OK
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xnat:Subject ID="XNAT_S00001" project="XNAT_01" label="XNAT_01_01" …>
…
</xnat:Subject>
You’ll also need to authenticate against your server. I tried your call with format==xml and got this:
$ http https://data.developingconnectome.org/data/archive/projects/DataRelease1_1/subjects/CC00099AN18 format==xml
HTTP/1.1 401 Unauthorized
Which makes sense if it’s not an open public XNAT instance. Authenticating and accessing with httpie is pretty simple. For one call do this:
$ http --auth owner --session=owner xnatdev.xnat.org/data/projects
http: password for ow...@xnatdev.xnat.org:
Once you’ve authenticated, the session information is cached just like a browser caches it in a cookie and you can reuse the same session with just the --session argument:
$ http --session=owner xnatdev.xnat.org/data/projects
Regarding your issues trying my examples, that’s because xnatdev.xnat.org doesn’t exist on the internet. I have a Vagrant VM built with the XNAT Vagrant project with the host and server parameters set to xnatdev.xnat.org in the local.yaml, the site URL set to http://xnatdev.xnat.org, and xnatdev.xnat.org configured in my desktop machine’s /etc/hosts file to the default IP for that VM. You can try my examples on your own server by changing the server address (http://xnatdev.xnat.org becomes https://data.developingconnectome.org) and using valid project, subject, session labels in the REST URLs.
The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.
The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.
Jianliang,
Try using https in your URL instead of http.
Thanks,
Charlie
The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
xnat_discussi...@googlegroups.com.
To post to this group, send email to
xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.