Cannot get API to work

(van dijk) #1

Hi all,

I cannot get the api to work:
I have a non-docker installation on Ubuntu (5.0.2)
https://XXXXXXXX/openemr/ and it works flawlessly.

did this:
Enable this API service in OpenEMR menu: Administration-Globals-Connectors-“Enable OpenEMR REST API”

but when I start by calling
I get an empty page as response.

when I call
curl -X POST -H ‘Content-Type: application/json’ https://XXXXXXXX/openemr/apis/api/auth
-d ‘{
“username”: “ServiceUser”,
“password”: “password”,
“scope”:“site id”

I get a 404…

Do I have to install something else?

Kind regards,

van Dijk

(Stephen Waite) #2

hi @vandijk, did you see this code ?

(Brady Miller) #3

hi @vandijk ,

I need to test this feature quite a bit and here’s the command I use:
(using name/pass HEU-admin-32 and then generally the scope is always default unless you are using multisite feature). I also need to use --insecure tag since I’m using self-signed certs on the openemr server I’m using.

curl --insecure -X POST -H 'Content-Type: application/json' 'https://localhost:9082/apis/api/auth' \
-d '{
    "username": "HEU-admin-32",
    "password": "HEU-admin-32",

(Brady Miller) #4

hi @stephenwaite ,
Note that testing script is for using the api internally (when already logged into OpenEMR). More for developers to make sure we didn’t break anything on api internal use when we do dev work on the api.

(Jerry P) #5

Lose the single quotes in body json array. content type is jason so string is implied…
“username”: “ServiceUser”,
“password”: “password”,
“scope”:“site id”

(van dijk) #6

In my browser window? No just empty page (http-200, so php works)

(van dijk) #7

I tried in same browser with logged-in session in another tab.

(van dijk) #8

It should work out of the box right? I do not have to install extra code next to openemr right?

(Brady Miller) #9

Hi @vandijk ,
You need to do the above command on command line (not browser).

(van dijk) #10

I tried it on localhost (for testing, did not change credentials)

(van dijk) #11

I installed a brand new open-emr site with https enabled. Maybe that was the problem…(Setting Enable OpenEMR REST API - popup says SSL required.)
But still nog luck. html-code 404

404 Not Found

Not Found

The requested URL was not found on this server.

Apache/2.4.29 (Ubuntu) Server at Port 443

(Stephen Waite) #12

thank you @brady.miller, saw below part of @vandijk’s post and thought that maybe could start with that, if not working then thinking there’s something in the error logs

(van dijk) #13

Hai Stephen,

Tnx for your reply. https://XXXXXX/tests/api/InternalApiTest.php
comes back with http-200 and an empty page… (empty head, empty body).

(Stephen Waite) #14

hi @vandijk, this works on one of the demos

curl --insecure -X POST -H 'Content-Type: application/json' '' \
-d '{
    "username": "admin",
    "password": "pass",

(van dijk) #15

Hi Stephen,

Thanks for your reply and patients.
It looks like something is missing, installed Open-emr on another ubuntu server from scratch, no difference, nothing in error log.

  1. should it work out of the box (without adding code or extensions ?)
  2. there is a recommendation during install how to configure the directive of the apache conf. (Denied access to /sites/ etc) should this be altered for using the api?
  3. is everybody in this thread, working with the docker build?


Van dijk.

(Brady Miller) #16

hi @stephenwaite ,
Nice call on using the demo (note the demo won’t even need the --insecure tag since it is using a genuine ssl cert) for testing. @vandijk , did Stephen’s above command work for you? (this will ensure that your curl client is working)

(van dijk) #17

Hi Brady,

Thank you for your response, in the screenshot above, I’m showing that curl is not working for the api. It also shows curl is working for the open-emr-site itself.

Kind regards,
Van Dijk

(van dijk) #18

Ok, another build from scratch, this time the docker variant:
Open-emr works, enabled the rest-api setting, but still no luck:
… empty body …

(van dijk) #19

double post…

(van dijk) #20

Hi @stephenwaite

The curl-post on the demo-site works.

Kind regards