Creating study using REST API

Hello,
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.

Thanks,
Abhjit

Comments

  • GerbenRienkGerbenRienk Posts: 738 ✭✭✭
    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?


    Thanks,
    Abhijit
  • GerbenRienkGerbenRienk Posts: 738 ✭✭✭
    Yes, I'm afraid that's required. In most cases you would take
    username:password
    and encode that to use in the header, but with this rest-api you must use only
    apikey
    and encode that.
  • abhijitgosaviabhijitgosavi Posts: 8
    Hi,
    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: 738 ✭✭✭
    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
    Hi,
    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: 738 ✭✭✭
    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: 20
    Here is a document I created for Rest API training, hope this is helpful. Please follow step by step instruction as demonstrated.
    https://docs.google.com/a/openclinica.com/document/d/1acdOZk_oPmNY9zcIzpFQstO0TK6zWU6lcBnB6Q9aUcQ/edit?usp=sharing
    Best regards,
    Jigyasa
  • 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,
    abhijit
Sign In or Register to comment.