# Cannot get API to work

**URL:** <https://community.open-emr.org/t/cannot-get-api-to-work/13157>\
**Category:** Management and Administration\
**Created:** [November 17, 2019, 1:44pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157 "2019-11-17T13:44:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 17, 2019, 1:44pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/1 "2019-11-17T13:44:16Z")

</div>

Hi all,

I cannot get the api to work:  
I have a non-docker installation on Ubuntu (5.0.2)  
[https://XXXXXXXX/openemr/](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](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](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

---

<div class="post-metadata">

**Author:** ![stephenwaite](https://community.open-emr.org/user_avatar/community.open-emr.org/stephenwaite/32/15754_2.png) [@stephenwaite](https://community.open-emr.org/u/stephenwaite)\
**Post date:** [November 18, 2019, 2:35am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/2 "2019-11-18T02:35:42Z")

</div>

hi @vandijk, did you see this [code](https://github.com/openemr/openemr/blob/rel-502/tests/api/InternalApiTest.php#L13-L15) ?

---

<div class="post-metadata">

**Author:** ![brady.miller](https://community.open-emr.org/user_avatar/community.open-emr.org/brady.miller/32/10178_2.png) [@brady.miller](https://community.open-emr.org/u/brady.miller)\
**Post date:** [November 18, 2019, 6:22am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/3 "2019-11-18T06:22:42Z")

</div>

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.

```auto
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"
}'

```

---

<div class="post-metadata">

**Author:** ![brady.miller](https://community.open-emr.org/user_avatar/community.open-emr.org/brady.miller/32/10178_2.png) [@brady.miller](https://community.open-emr.org/u/brady.miller)\
**Post date:** [November 18, 2019, 6:25am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/4 "2019-11-18T06:25:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sjpadgett](https://community.open-emr.org/user_avatar/community.open-emr.org/sjpadgett/32/21623_2.png) [@sjpadgett](https://community.open-emr.org/u/sjpadgett)\
**Post date:** [November 18, 2019, 6:56am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/5 "2019-11-18T06:56:21Z")

</div>

> [@vandijk](#):
>
> ‘{  
> “grant\_type”:“password”,  
> “username”: “ServiceUser”,  
> “password”: “password”,  
> “scope”:“site id”  
> }’

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”  
}

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 8:52am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/6 "2019-11-18T08:52:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 8:53am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/7 "2019-11-18T08:53:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 8:55am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/8 "2019-11-18T08:55:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brady.miller](https://community.open-emr.org/user_avatar/community.open-emr.org/brady.miller/32/10178_2.png) [@brady.miller](https://community.open-emr.org/u/brady.miller)\
**Post date:** [November 18, 2019, 9:01am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/9 "2019-11-18T09:01:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 9:19am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/10 "2019-11-18T09:19:11Z")

</div>

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

 ![image](https://discourse-uploads-openemr.s3.dualstack.us-east-1.amazonaws.com/original/2X/d/dd01e526694090b09a3b6253a987af5525af702c.png)

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 3:04pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/11 "2019-11-18T15:04:24Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![stephenwaite](https://community.open-emr.org/user_avatar/community.open-emr.org/stephenwaite/32/15754_2.png) [@stephenwaite](https://community.open-emr.org/u/stephenwaite)\
**Post date:** [November 18, 2019, 6:42pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/12 "2019-11-18T18:42:51Z")

</div>

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

> [@vandijk](#):
>
> but when I start by calling  
> [https://XXXXXXXX/openemr/tests/api/InternalApiTest.php](https://XXXXXXXX/openemr/tests/api/InternalApiTest.php)  
> I get an empty page as response.

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 18, 2019, 7:07pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/13 "2019-11-18T19:07:06Z")

</div>

Hai Stephen,

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

---

<div class="post-metadata">

**Author:** ![stephenwaite](https://community.open-emr.org/user_avatar/community.open-emr.org/stephenwaite/32/15754_2.png) [@stephenwaite](https://community.open-emr.org/u/stephenwaite)\
**Post date:** [November 18, 2019, 7:54pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/14 "2019-11-18T19:54:12Z")

</div>

hi @vandijk, this works on one of the demos

```auto
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"
}'

```

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 19, 2019, 7:54am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/15 "2019-11-19T07:54:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brady.miller](https://community.open-emr.org/user_avatar/community.open-emr.org/brady.miller/32/10178_2.png) [@brady.miller](https://community.open-emr.org/u/brady.miller)\
**Post date:** [November 19, 2019, 10:20am UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/16 "2019-11-19T10:20:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 19, 2019, 12:00pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/17 "2019-11-19T12:00:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 19, 2019, 12:22pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/18 "2019-11-19T12:22:25Z")

</div>

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

 ![image](https://discourse-uploads-openemr.s3.dualstack.us-east-1.amazonaws.com/original/2X/9/9eb73ff664b633f0fe7a4f9ceebe463dc020a5e3.png)

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 19, 2019, 12:48pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/19 "2019-11-19T12:48:04Z")

</div>

double post…

---

<div class="post-metadata">

**Author:** ![vandijk](https://community.open-emr.org/letter_avatar_proxy/v4/letter/v/f14d63/32.png) [@vandijk](https://community.open-emr.org/u/vandijk)\
**Post date:** [November 19, 2019, 1:01pm UTC](https://community.open-emr.org/t/cannot-get-api-to-work/13157/20 "2019-11-19T13:01:58Z")

</div>

Hi @stephenwaite

The curl-post on the demo-site works.

Kind regards

[Next page](https://community.open-emr.org/t/cannot-get-api-to-work/13157.md?page=2)
