400 Bad request trying to access API

Hi there,

I’m new with OpenEMR and with Docker too.
I’ve setup an enviroment using docker, you can find the setup file below.

version: ‘3.9’
services:
fhir:
image: conceptant/hapi-fhir
ports:
- 8080:8080
mysql:
restart: always
image: mariadb:10.2
command: [‘mysqld’,’–character-set-server=utf8’]
ports:
- 8320:3306
volumes:
- databasevolume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
openemr:
restart: always
image: openemr/openemr:flex
ports:
- 8300:80
- 9300:443
- 3000:3000
- 3001:3001
volumes:
- .:/var/www/localhost/htdocs/openemr:rw
- assetsvolume01:/var/www/localhost/htdocs/openemr/public:rw
- cachevolume01:/var/www/localhost/htdocs/openemr/gacl/admin/templates_c:rw
- cachevolume02:/var/www/localhost/htdocs/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/compiled:rw
- cachevolume03:/var/www/localhost/htdocs/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/cache:rw
- configvolume01:/var/www/localhost/htdocs/openemr/sites/default:rw
- configvolume02:/var/www/localhost/htdocs/openemr/interface/modules/zend_modules/config:rw
- logvolume01:/var/log
- nodemodules:/var/www/localhost/htdocs/openemr/node_modules:rw
- vendordir:/var/www/localhost/htdocs/openemr/vendor:rw
- ccdamodule:/var/www/localhost/htdocs/openemr/ccdaservice:rw
environment:
MYSQL_HOST: mysql
MYSQL_ROOT_PASS: root
MYSQL_USER: openemr
MYSQL_PASS: openemr
OE_USER: admin
OE_PASS: pass
FLEX_REPOSITORY: https://github.com/openemr/openemr.git
FLEX_REPOSITORY_BRANCH: master
EASY_DEV_MODE: “yes”
depends_on:
- mysql
phpmyadmin:
restart: always
image: phpmyadmin/phpmyadmin
ports:
- 8310:80
environment:
PMA_HOSTS: mysql
volumes:
databasevolume: {}
assetsvolume01: {}
cachevolume01: {}
cachevolume02: {}
cachevolume03: {}
configvolume01: {}
configvolume02: {}
logvolume01: {}
nodemodules: {}
vendordir: {}
ccdamodule: {}

I run them and they seem to work fine, but when I try to access the API endpoint I get 400 bad request, here is the api call.

curl --insecure -X POST -H ‘Content-Type: application/json’ ‘https://localhost:8300/apis/api/auth
-d ‘{
“grant_type”:“password”,
“username”: “myUSer”,
“password”: “myPassword”,
“scope”:“default”
}’

I tried using curl and Postman and the result is the same.
Is this something that could be because I didn’t enabled REST API for OpenEMR(if so, I don’t know how) or because the request is really wrong or maybe the setup is wrong…?

Thank you!

Hi Ionut,

There were some changes to authentication with the API as of version 6. It’s possible that the documentation you’re looking at was written for version 5.

The discussion on the changes here might be useful to you.
V6 Authorization and API changes afoot - OpenEMR Development - OpenEMR Community (open-emr.org)

Thanks,
-Rachel

1 Like