After filling out the app registration form and clicking the submit button, an error message "Failed to fetch" appears

I would like to create a standalone app that fetches data from the OpenEMR API for a single patient. The first step is to register the app, which can be done by accessing the following URL: http://localhost/openemr/interface/smart/register-app.php. However, after filling out the form with the necessary information, such as the app’s name, redirect URI, etc., and clicking the submit button, an error message appears at the bottom of the button saying, “Failed to fetch.”

hi @Amine_El_Kahmaze , did you enter anything in the contact email?

hi, yes a valid email

Upon investigating the source code, I discovered that the error is triggered as a result of a POST HTTP request to the URL (http://localhost:2020/openemr/oauth2/default/registration). The base URL (http://localhost:2020) is the one specified in the globals > config > connectors section. (look blew the comment “look here”)
fetch(fhirRegistrationURL, {
method: ‘POST’, // *GET, POST, PUT, DELETE, etc.
headers: {
‘Content-Type’: ‘application/json’
body: JSON.stringify(appRegister) // body data type must match “Content-Type” header
}).then(result => {
if (!result.ok) {
return result.json().then(json => { throw json });
return result.json();
}).then(resultJSON => {
document.querySelector("#clientID").value = resultJSON.client_id;
document.querySelector("#clientSecretID").value = resultJSON.client_secret;
//look here
.catch(error => {
let msgText = error.message + fhirRegistrationURL;
if (!msgText) {
msgText = JSON.stringify(error);
document.querySelector("#errorResponseContainer").textContent = msgText;

In the installed version of OpenEMR, there is no file located at the path “openemr/oauth2/default/registration” to handle the specific request.

there’s routing/re-writing that handles that path, can’t reproduce in the demos, guessing it’s something in your data entry in the form

Your mod_rewrite is not working if you are using apache. We use .htaccess files to rewrite the requests. You also likely need to setup your oauth2 connector URL as explained in the API readme documentation. Also, make sure you are on the same domain and schema, you can’t cross ssl/non-ssl.

1 Like

Indeed, I am utilizing SSL with a self-signed certificate; however, the browser continues to display a warning indicating that the certificate is issued by an untrusted Certificate Authority. Could this issue be the root cause of the problem?

Only if you haven’t accepted the SSL certificate in your chrome browser. Otherwise if meets the CORS requirements it will work fine on a localhost domain with a self-signed certificate. Go to the URL directly, if the URL is not resolving it means the rewrite URLs are not working. Check your apache and php error logs for more debugging info.

What is meant by URL is this: https ://localhost:9300/oauth2/default/registration?

I managed to resolve the issue by modifying the port setting in the connector section to match the one used by the Apache server, which differs from the port specified in the documentation (9300). However, after making this change, I encountered a new error: “The authorization server encountered an unexpected condition that prevented it from fulfilling the request: Security error - problem with authorization server keys.”

Hi Amine_El_Kahmaze
were you able to slove this issue ? if yes can post the solution