Trying to create a basic REST API call

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!

hi @perreq, see the api readme

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

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?

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,

send error here.

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