Create Patient Using A POST Request

Hi OpenMRS, I know this could be way easy, but I need help creating a patient via post. I am using Postman and sending the request via (http://localhost:8080/openmrs/ws/rest/v1/patient) The body of the request is:

{
  "identifiers": [
    {
      "identifier": "abc123ez",
      "identifierType": "2f470aa8-1d73-43b7-81b5-01f0c0dfa53c",
      "location": "9356400c-a5a2-4532-8f2b-2361b3446eb8",
      "preferred": true
    }
  ],
  "person": {
    "gender": "M",
    "age": 14,
    "birthdate": "1970-01-01T00:00:00.000+0100",
    "birthdateEstimated": false,
    "dead": false,
    "deathDate": null,
    "causeOfDeath": null,
    "names": [
      {
        "givenName": "Patrick",
        "familyName": "Paddy"
      }
    ]
  }
}

And below is the error I am getting

Here is the screenshot for postman

The error message you have is, I hope, pretty clear about this: “Privileges required: Get Identifier Types”. So the user you authenticated as does not have the privilege called “Get Identifier Types” and so is unable to create an identifier for the patient.

1 Like

Thanks @ibacher I have granted admin privileges but that did not solve the issue, unfortunately.

Could you tell us what you actually did? I don’t quite know what this means.

The role assigned to the user needs to have this privilege:

Screenshot of Get Patient Identifiers privilege in a role

Or be the system developer role (which has all privileges)

Alternatively, if you’re getting a different error message (because, e.g., you gave the user system developer permissions and the request still fails), that would be helpful to see.

Many identifiers (depending on how they are configured) do not support supplying an arbitrary identifier in the POST request, i.e., you need to tell the system to generate an identifier for you and then use that allocated identifier for the patient you are creating.

1 Like

hello @seremba could you navigate to the “authorization” section and and select “basic auth” and then fill in user as Admin and password as Admin123

see if you get the same error coz @ibacher is right

Thank you @ibacher, and @josephbate , your suggestions were really helpful. I managed to create a patient using REST API

1 Like

Trying to think around this, could he try changing the “identifiers” field to “identifier” in the request body??

That would generate a completely different error, (since identifier is not a supported field on patient), but do nothing to solve the issue.

1 Like