Can't make requests from the API Documentation

Those who have tried to make a API call from either demo.openmrs.org or qa-refapp may have experienced it. https://qa-refapp.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm

The reason is that the host name of the Swagger Spec is invalid. The problem possibly is in here, which always returns the ip of the localhost (127.0.0.1).

If others could confirm, we can work on a fix.

How does one reproduce the problem?

Login to Login

Then visit apiDocs page.

Then make any valid request by clicking one of try out buttons.

One could try GET /drug. Once you made the request, there will be no response from the server as the request is sent to an invalid url.

For instance /drug, what is the invalid url, and what should the correct one be?

I also noticed that for getting drugs, the Model Example Value here https://qa-refapp.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm#!/drug/getAllDrugs is different from the one here: https://demo.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm#!/drug/getAllDrugs Did it get messed up?

No I mean when making a request. Once clicked on the try out button. It is nothing to do with the drug resource.

Requests are sent to 127.0.0.1. It is being always that way. So one can only make a request when running from localhost.

I do not seem to understand. Do you mind just answering the two questions i put above? :slight_smile:

This is what I see when I invoke GET /app from qa-refapp.openmrs.org

As shown in the picture request is sent to http://127.0.0.1:8081/openmrs/ws/rest/v1/app The correct request url should be https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/app

I guess that one fix for this is to set the global property for the REST API root url on that server. Maybe it’s not set?

It is to do with the host parameter of the swagger spec.

If you check in here: qa-refapp.openmrs.org/openmrs/module/webservices/rest/swagger.json, you’ll see “host” is set to “127.0.0.1:8081” and “schemes” to [ “http” ]. Here in case with qa-refapp, both values are invalid.

I think the simplest solution will be to simply omit host, and schemes params from the spec as suggested in here. API Host and Base Path

Omitting host and scheme

host and scheme can be omitted for a more dynamic association. In this case, the host and scheme used to serve the API documentation will be used for API calls. For example, if Swagger UI-based documentation is hosted at https://api.example.com/apidocs/index.html, “try it out” API calls will be directed to https://api.example.com.

BTW I’m not really sure what do you mean by ‘REST API root url’ .

I was talking about the webservices.rest.uriPrefix global property mentioned here.

This is used elsewhere in the REST module (e.g. when generating links in resources) to let you use a different URI than what the request is reporting. So maybe the correct fix is to use that GP in generating the swagger spec also.

(Or maybe leaving it blank will work fine. I don’t know if that’s allowed, or anything about swagger specs myself.)

Thanks for the information.

Here it is probably returning http://192.168.1.100/openmrs. As 192.168.1.100 shouldn’t be used as the host param of the spec, we should replace it with either servers domain name or the remote ip.

May be @pascal will have an idea whether we should omit these (host and schemes) or not.

Can we get the value of webservices.rest.uriPrefixr in the format http://yourdomainname.org/openmrs instead of http://192.168.1.100/openmrs ?

192.168.1.100 is not helpful in this case. We either need the domain or the remote ip.

I would say that for now, fix it with what you think is best. Then later on when others comment, you can always revisit it.

The value of webservices.rest.uriPrefix is supposed to be the external IP that consumers of the REST API would use. I.e. it should be set to http://yourdomainname.org/openmrs.