Do you use or administer OpenEMR? Take the General Satisfaction Survey to help improve the product

Getting a 400 error code querying my REST APIs

Hi guys,

I’m new to OpenEMR v6.0.0.0 and I have an issue trying to access the Rest APIs.

I’m directly logged on my ubuntu machine where OpenEMR is installed and I run a very basic auth command:

Blockquote
curl -X POST -v --insecure -H ‘Content-Type: application/json’ ‘http://localhost/apis/api/auth’
-d ‘{
“grant_type”:“password”,
“username”: “me”,
“password”: “mypassword”,
“user_role”:“users”,
“scope”:“default”
}’

and this is what I get back

Blockquote
Note: Unnecessary use of -X or --request, POST is already inferred.

Trying 127.0.0.1…
Connected to localhost (127.0.0.1) port 80 (#0)

POST /apis/api/auth HTTP/1.1
Host: localhost
User-Agent: curl/7.47.0
Accept: /
Content-Type: application/json
Content-Length: 142

upload completely sent off: 142 out of 142 bytes
< HTTP/1.1 400 Bad Request
< Date: Thu, 04 Feb 2021 05:46:36 GMT
< Server: Apache
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< X-XSS-Protection: 1; mode=block
< Content-Length: 0
< Connection: close
< Content-Type: text/html; charset=UTF-8
<
Closing connection 0

I verified my credentials using the main OpenEMR web interface and it works sop I’m wondering what I’m doing wrong …

Any help is greatly appreciated :slight_smile:

One more thing, I successfully ran the InternalTesting (PHP) page from a browser so the APIs seem to be up and running. I’m just wondering what I’m doing wrong with the curl auth request…

Your url for auth is wrong please refer to the api documentation this might also help.

Good luck.