Cannot get API to work

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
https://XXXXXXXX/openemr/tests/api/InternalApiTest.php
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 ‘{
“grant_type”:“password”,
“username”: “ServiceUser”,
“password”: “password”,
“scope”:“site id”
}’

I get a 404…

Do I have to install something else?

Kind regards,

van Dijk

hi @vandijk, did you see this code ?

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 '{
    "grant_type":"password",
    "username": "HEU-admin-32",
    "password": "HEU-admin-32",
    "scope":"default"
}'

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.
-brady

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

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

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

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

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

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

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.)
https://openemr.XXXX.com/apis/api/auth
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 openecd.xxxxx.com Port 443

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

1 Like

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).

hi @vandijk, this works on one of the demos

curl --insecure -X POST -H 'Content-Type: application/json' 'https://six.openemr.io/b/openemr/apis/api/auth' \
-d '{
    "grant_type":"password",
    "username": "admin",
    "password": "pass",
    "scope":"default"
}'
1 Like

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.
Questions:

  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?

Regards,

Van dijk.

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)
-brady

1 Like

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

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

double post…

Hi @stephenwaite

The curl-post on the demo-site works.

Kind regards