perreq
(lurken Soderberg)
October 24, 2020, 11:58am
1
Hello.
I am trying to access openEMR from API call.
First, by using postman. I found a good demo server that I can access from the browser:
http://eight.openemr.io/a/openemr
When using postman, I am providing this in the request body:
{
“grant_type”: “password”,
“username”: “admin”,
“password”: “pass”,
“scope”: “default”
}
But still I get 401 Unauthorized as response.
The goal is to create a .NET application that can access openEMR, this is my simple code:
string URL = "http://eight.openemr.io/a/openemr/apis/api/auth";
string URL2 = "http://eight.openemr.io/a/openemr/apis/api/patients";
var client = new FhirClient(URL);
Patient myPat = new Patient();
myPat.Identifier.Add(new Identifier("http://www.nhsdev.net/psn", "4568532"));
myPat.Active = true;
HumanName patName = new HumanName();
patName.GivenElement.Add(new FhirString("Vincent"));
patName.Use = HumanName.NameUse.Official;
myPat.Name.Add(patName);
myPat.Gender = AdministrativeGender.Male;
myPat.BirthDate = "1989-01-21";
myPat.ManagingOrganization = new ResourceReference() { Reference = "Organization/NHSDEVORG" };
client.Create<Patient>(myPat);
I get an exception:
“Operation was unsuccessful because of a client error (Unauthorized). Body has no content.”
How do I provide a body in the request?
Thanks for any help!
zerai
(Zero)
October 24, 2020, 1:25pm
3
Hi,
based on your code you should try a post request on patient fhir endpoint
Fhir authorization endpoint
Hi @perreq ,
I had faced same issue way back please find below solution for same
Hi All,
Here is final solution for API issue, when your API is not working or showing HTTP 404 error you means your .htaccess is not working just go to apache config file check AllowOverride option and change the AllowOverride None to AllowOverride All.
Now try again API url you should receive the internal server error means the our .htaccess is working but we did not enabled the apache mod_rewrite. use below command to enable mod_rewrite a2enmod rewrite then restart the server.
Note: If…
perreq
(lurken Soderberg)
October 25, 2020, 12:58pm
5
Thanks for all response guys!
I guess the “curl -X POST” is PHP. I still dont know how to implement this in a c#.NET application.
I found a huge project on Github in c#. But I just want to start with a simple “hello world” example. Maybe that is not possible to do if I only have the FhirClient object to play around with.
Has anyone of you created a .NET application?
Annapoorna
(Annapoorna Krishna)
December 2, 2020, 9:18am
6
Hi @Nilesh_Hake ,
I tried your suggestion but I do not know how to enable the apache mod_rewrite. If you could elaborate on this, it would be a great help.
Annapoorna
(Annapoorna Krishna)
December 2, 2020, 2:31pm
8
Hi @Nilesh_Hake ,
I get 401 unauthorized error with an empty body when I call this below API on postman.
http://localhost:80/openemr/apis/oauth2/default/registration
using version 5.0.2
I am trying to creating RESTAPI using openemr and postman, i dont know the steps please anybody help me , i followed this link but i am not getting openemr/API_README.md at master · openemr/openemr · GitHub
1 Like