We are currently working on the forum. For the short-term, all forum content will be in read-only format. We apologize for the interruption and look forward to collaborating with you shortly. All the best in your research!

REST Call to login to OpenClinica

I am using curl to run some tests to Login and do some test automation on studies, i am not able to login and get exact header, url and body that i need to use. can someone give me a sample of how i can login. I looked at documentation but i am not able to figure out from that.


  • toskriptoskrip Posts: 279 ✭✭✭

    you need two requests to perform RESTfull URL call to OC. First is the post request in order to trigger login mechanism of spring security, which will open a session (with cookie) for you. And the second is get request to specific RESTfull endpoint. The second request need to reuse the session that was created by first request. With curl you simple store cookie in extra file and reuse it during second request. Here is an example:

    curl d j_username=root -d j_password=12345678 --cookie-jar ./session http://localhost:8080/OpenClinica/j_spring_security_check

    curl --cookie ./session http://localhost:8080/OpenClinica/rest/clinicaldata/json/view/S_DEFAULTS1/SS_01/*/*


  • yogiyogi Posts: 25
    that works fine. But what is if i want to get the html casebook of an subject :D then OpenClinica needs some time to process. But CURL get´s a page but only this one that we have to wait :D

    Any ideas?

  • toskriptoskrip Posts: 279 ✭✭✭

    yes, the thing is html casebook was designed to be used within OC only (or within a browser). It will be complicated to use html casebook from CURL because it seems to be that the page that you get back (about the need of time to process) has lot of java script that need to be executed (normally browser does that) in order to generate the html casebook. CURL is not executing the java script (there is no java script execution engine in CURL). You would have to process result that you get back with something that can execute the underlying javascript in order to get the final html report.

  • toktok Posts: 1
    Thanks! Works like a charm!
    Is that the only way to authenticate for this API call?

    GET /rest/clinicaldata/json/view/:study/:subject/:event/:form

    There is no apikey or similar mechanism available?

    Should I also do logout

    curl --cookie-jar ./session http://localhost:8080/OpenClinica/j_spring_security_logout

    or what happens to a session left open?
  • toskriptoskrip Posts: 279 ✭✭✭
    Late response but at least something. Currently in community version this is the only way known to me. The authenticated session is restricted to the calling agent (if the same user tries with different browser/ toolstack) it will be considered as not authenticated. You could do the logout action if you want, otherwise the session will expire after some time (don't know exactly from the memory ... could e around 20 minutes or so).

    I also remember that if e.g. you are logged in from user interface and execute the successful POST login on the same user by different program. The original authenticated session (in this case from GUI) is closed.

Sign In or Register to comment.