REST create concept error

0 views
Skip to first unread message

mareike...@gmail.com

unread,
Apr 16, 2014, 6:56:20 AM4/16/14
to d...@openmrs.org

Hi all,

so I am new to OpenMRS, and I've got some serious problems with the REST Web Services and I have no clue, why the following does not work for me. I'm testing the REST calls directly in OpenMRS.

1) I get an error, if I try to GET all persons/patients with the following command: openmrs/ws/rest/v1/person

Normally, this should get me a whole list of persons, but everything I get is the following: error! msg: error errorThrown: undefined req: [object XMLHttpRequest]

But openmrs/ws/rest/v1/person/uuid gives me the person.

2) Is there a way to get a more precise error message??

3) the greatest problem is, that I want to create concepts via the REST service. As stated in the description, I need the names (name, locale), the datatype and the conceptclass. here an example of my call:

Type:POST

URI: /openmrs/ws/rest/v1/concept

Body Content: {"datatype": "N/A", "conceptClass": "Misc", "names": [{"name":"TEST", "locale":"en"}]}

representation: create

But I only get the same error as stated above. Is there anything wrong with my call or why else do I get only errors? Or do I have to do something before trying to create concepts via REST? If I do create a concept via the dictionary, I can later change things via REST.

thank you for your answers.

Friedman, Roger (CDC/CGH/DGHA) (CTR)

unread,
Apr 16, 2014, 6:57:36 AM4/16/14
to d...@openmrs.org

getting all patients is a prohibited operation

--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/

To unsubscribe from this group and stop receiving emails from it, send an email to dev+uns...@openmrs.org.

Darius Jazayeri

unread,
Apr 16, 2014, 10:20:09 AM4/16/14
to dev
The HTTP response should include a more detailed message in its content. Are you sure it doesn't?

About creating a concept, maybe this will help?

-Darius

mareike...@gmail.com

unread,
Apr 16, 2014, 11:23:19 AM4/16/14
to d...@openmrs.org
Thank you for the fast reply!

Good to know, that getting a list of all patients is prohibited (even though it could be mentioned next to the example..)

Yes, I have already seen this forum entry, and also tried it this way. But I only got the same error message. To create a concept, you need the names tag, which in turn needs only the name and the locale. If I try to create something aside from a concept, it works just fine.
 
The http response is: 500 Internal Server Error. Or what exactly do you mean?
But I thought, maybe I could get a more detailed error message right in Openmrs under the testing REST URIs tab.

Is there a chance, that the error is caused due to some missing rights, or a failed installation? Or maybe a version conflict with tomcat?

Darius Jazayeri

unread,
Apr 16, 2014, 11:32:30 AM4/16/14
to dev
Hi Mareike,

The response should typically be a 400 if you send the wrong data, and the response should be JSON giving you error details, e.g.
Inline image 1

If you are getting back a 500, then probably some uncaught exception is happening on the server, and you should see evidence of this in the form of a stack trace in the server logs.

-Darius

mareike...@gmail.com

unread,
Apr 17, 2014, 5:10:45 AM4/17/14
to d...@openmrs.org
ok, now it works, even though I don't know why.
thats an example: { "names": [ { "name": "Test Concept", "locale": "en", "conceptNameType": "FULLY_SPECIFIED" } ], "datatype": "TEXT", "conceptClass": "Question" }

Thank you so much for your help!

But I have another question relating to the nice image you send: is this a special REST surface? I think this wolud help me a lot.

Darius Jazayeri

unread,
Apr 17, 2014, 10:36:39 AM4/17/14
to dev
Hi Mareike,

The screenshot is just the Chrome javascript console and the network tab.

(In the json you sent in the first email you didn't specify conceptNameType, so maybe that's the difference.)

-Darius

mareike...@gmail.com

unread,
Apr 22, 2014, 7:16:36 AM4/22/14
to d...@openmrs.org
Hi Darius,

regarding the conceptNameType: I tried including all parameters, also localePreferred and conceptNameType, but it did not work. I am getting the feeling, that creating or updating is sometimes a little buggy, because sometimes it works just fine and sometimes, I get the error and after trying it again, it works.
But anyhow, for now, everything should be clear to me. So thank you for helping me,
Mareike

mareike...@gmail.com

unread,
Apr 23, 2014, 5:04:09 AM4/23/14
to d...@openmrs.org
Hi again,
now I am trying to create the concepts via a python script. Because now I know, that my query has to be in the right format, something else must cause the error I get. It is a  "HTTP/1.1 500 Internal Server Error\r\n'".
(yes, I have seen the post here https://groups.google.com/a/openmrs.org/forum/#!topic/dev/CHJ1xgqNkcQ).
It also works, if I am trying to GET something or update an existing concept.

Here is the code I use.



def testConceptCreation():
  
    teststring = """{ "names": [ { "name": "TestConsole22", "locale": "en", "conceptNameType": "FULLY_SPECIFIED" } ], "datatype": "TEXT", "conceptClass": "Question" } """

timestamp = datetime.datetime.now().strftime("%a, %d %b %Y %I:%M:%S GMT")
  
    uri ="http://omrsdev.mydomain.de"
    path = '/openmrs/ws/rest/v1/concept/'
    h = http.Http()
    auth = base64.encodestring( 'name' + ':' + 'password' )

    h.add_credentials("name", "password")
 
    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=UTF-8'
        }
       
    target = urlparse(uri+path)
    # If you need authentication some example:
   
    body = teststring;
 
    response, content = h.request(
            target.geturl(),
            'POST',
            headers=headers,
            body=teststring
            )
   
    # assume that content is a json reply
    # parse content with the json module
    data = json.loads(content)

mareike...@gmail.com

unread,
Apr 27, 2014, 4:58:08 PM4/27/14
to d...@openmrs.org
Hi,
does anyone have the same problem?
because creating a person and updating concepts works just fine with the code I posted before, the error has to be the json string or some missing rights maybe?
json string: { "names": [ { "name": "TestConsole22", "locale": "en", "conceptNameType": "FULLY_SPECIFIED" } ], "datatype": "TEXT", "conceptClass": "Question" }
(and this call works via the rest testpage directly in openmrs)

Mareike

Ope Bakare

unread,
Apr 27, 2014, 5:01:55 PM4/27/14
to d...@openmrs.org
Hi Mareike.

I wrote a of perl script to do the same thing that works after a lot of debugging and hackery.
If you'd like it, I have attached it to this message.

Forgive the lack of clear documentation in the code, but it's fairly readable for perl.

Ope

createConcepts.pl

Mareike Mokroß

unread,
Apr 28, 2014, 6:47:07 AM4/28/14
to d...@openmrs.org
Hi Ope,
the script you attached works in some way, but it is somehow weird. Because the concepts were created, but I still get the ominous 500 error and the uuid will not be returned. Do you have any guesses?


However, I can create concepts and therefore thank you!
Mareike


--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/

Opeyemi Bakare

unread,
Apr 28, 2014, 6:56:40 AM4/28/14
to d...@openmrs.org, d...@openmrs.org
If you get a 500 error, enable the verbose output so you can see the detail of the json object, as well as the response and I'll help you as much as I can.

Sent from my iPhone

Mareike Mokroß

unread,
Apr 28, 2014, 8:28:38 AM4/28/14
to dev
So somehow I "un"-commented the line #print Dumper($client->POST($conceptCall, $postData)); #for debug
which in the end, caused the 500 and the missing uuid.
now, everything works just fine. thanks a lot for your help!!

Mareike


Opeyemi Bakare

unread,
Apr 28, 2014, 11:05:38 AM4/28/14
to d...@openmrs.org, dev
Excellent!

Glad it worked out for you.

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages