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!

Creating study using REST API

I am trying to create a study using REST API. But, it shows 401 Bad credentials error with a description as this request requires HTTP authentication.

I set API key of a user to api_key in the header of the URL. Is there any other authentication is required?
And how to remove this error.



  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Hi Abhit,
    Did you encode it Base64?
    Kind regards,
    Gerben Rienk
  • abhijitgosaviabhijitgosavi Posts: 8
    Hi GerbenRienk,
    No. I am not encoding key to Base64. Does it need?

  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Yes, I'm afraid that's required. In most cases you would take
    and encode that to use in the header, but with this rest-api you must use only
    and encode that.
  • abhijitgosaviabhijitgosavi Posts: 8
    I encode API-key to base64. But it shows 500 Internal Server Error.
    I am not getting what actually error is. Please suggest solving this error and how to create study successfully.
  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Hi Abhijit,
    That's good: you're one step further. It means that the server is trying to rocess the request, but something went wrong. Did you look in the logs?
    And can you share the api you are sending the request to plus the parameters? Then we can have a look.
    Kind regards,
    Gerben Rienk
  • abhijitgosaviabhijitgosavi Posts: 8
    I check in logs but it shows the same error 500 internal server error.
    Post API : http://localhost:8080/OpenClinica/pages/auth/api/v1/studies/
    Header : api_key: YzhhODI1NDUxMDRlNGZkODk5Mzg2NTBmYTcwZGJkMjM=
    Parameters :
    "briefTitle": "Experimental new Study",
    "principalInvestigator": "default",
    "expectedTotalEnrollment": "10",
    "sponsor": "n_a",
    "protocolType": "Interventional",
    "status": "available",
    "assignUserRoles": [
    { "username": "usera", "role": "Data Manager" }
    "uniqueProtocolID": "TES003",
    "briefSummary": "Study for post api",
    "startDate": "2017-05-12"

  • GerbenRienkGerbenRienk Posts: 838 ✭✭✭
    Hi Abhijit,
    How strange: I can create a study with these same parameters, except for the user-account:

    Which version of OpenClinica do you use?
    Gerben Rienk
  • jguptajgupta Posts: 27
    Here is a document I created for Rest API training, hope this is helpful. Please follow step by step instruction as demonstrated.
    Best regards,
  • abhijitgosaviabhijitgosavi Posts: 8
    Thanks! Gerben and jigyasa for your help with this.
    Can we upload CRF using Rest API? Is there any API for CRF upload?

    Best regards,
  • mysterybbsmysterybbs Posts: 1
    I ran into a similar problem where posting to the /OpenClinica/pages/auth/api/v1/studies/ gave me the 500. looking at the log:

    SEVERE: Servlet.service() for servlet [pages] in context with path [/OpenClinica] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
    at org.akaza.openclinica.controller.StudyController.getStudyOwnerAccount(StudyController.java:1038)
    at org.akaza.openclinica.controller.StudyController.createNewStudy(StudyController.java:290)
    at sun.reflect.GeneratedMethodAccessor271.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)

    Going down the trace it seems ownerUserAccount is returned as null. The user account I used was set as a technical admin, I could get the apiKey ok, I've tried sending the api key as plain text and as base64.

    Any idea what I might be missing?
Sign In or Register to comment.