# How to get all patient from Database using Rest Api.

**URL:** <https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412>\
**Category:** Development\
**Created:** [March 19, 2019, 8:06am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412 "2019-03-19T08:06:52Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 8:06am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/1 "2019-03-19T08:06:53Z")

</div>

I want to retrieve all available patient from Database using rest api.If this is not possible I want to retrieve minimum 100 patient.Does the currently available Patient Rest api provide this support.

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 9:13am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/2 "2019-03-19T09:13:46Z")

</div>

> [@naveed1228](#):
>
> I want to retrieve all available patient from Database

@naveed1228, that is currently not supported and not encouraged as it may lead to “out of memory issues” , in case there too many patients.

youll want to use some thing like

`"http://localhost:8081/openmrs-standalone/ws/rest/v1/patient?limit=100`

where the `limit` parameter give the maximum number of patients

.to take a look at all the suported endpoints , check this

`http://localhost:***/openmrs-standalone/module/webservices/rest/apiDocs.htm`

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 9:31am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/3 "2019-03-19T09:31:08Z")

</div>

thanks for the reply but the provided url is not working.I have test it before

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 9:53am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/4 "2019-03-19T09:53:39Z")

</div>

[https://demo.openmrs.org/openmrs/module/webservices/rest/test.htm](https://demo.openmrs.org/openmrs/module/webservices/rest/test.htm)

I’m testing the server using this url: [https://demo.openmrs.org/openmrs/ws/rest/v1/patient?limit=100](https://demo.openmrs.org/openmrs/ws/rest/v1/patient?limit=100)

---

<div class="post-metadata">

**Author:** ![wandji69](https://talk.openmrs.org/user_avatar/talk.openmrs.org/wandji69/32/17381_2.png) [@wandji69](https://talk.openmrs.org/u/wandji69)\
**Post date:** [March 19, 2019, 10:54am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/5 "2019-03-19T10:54:51Z")

</div>

@naveed1228 just as @mozzy said this is not supported. i have open the url and the http status is said to be forbidden that means it is not yet supported. and from the look it may cause issues just as @mozzy mentioned.

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 10:57am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/6 "2019-03-19T10:57:32Z")

</div>

Ok I agree on first point.I think the limit should work but why Its not working?

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 10:58am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/7 "2019-03-19T10:58:35Z")

</div>

@naveed1228, another issue is that to fetch many patients at ago,you need to set other params eg `limit=` , `startIndex=` , `q=`

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 11:00am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/8 "2019-03-19T11:00:41Z")

</div>

what should I set q to because I want to get all patient list for example 100.Can you please provide an example url for this.

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 11:01am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/9 "2019-03-19T11:01:27Z")

</div>

eg

```
` "http://localhost:8081/openmrs-standalone/ws/rest/v1/patient?limit=100&startIndex=0&q=hor` 

returned

{
  "results": [
    {
      "uuid": "dd553355-1691-11df-97a5-7038c432aabf",
      "display": "101-6 - Mr. Horatio L Hornblower",
      "links": [
        {
          "rel": "self",
          "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/patient/dd553355-1691-11df-97a5-7038c432aabf"
        }
      ]
    },
    {
      "uuid": "dd753510-1691-11df-97a5-7038c432aabf",
      "display": "2268EG-0 - Horba Shira Ngere",
      "links": [
        {
          "rel": "self",
          "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/patient/dd753510-1691-11df-97a5-7038c432aabf"
        }
      ]
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 11:02am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/10 "2019-03-19T11:02:46Z")

</div>

no you cant get all the patients list @naveed1228 🤗, its not supported , unless its a custom implementation that you made ou self. but its not advisable

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 11:03am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/11 "2019-03-19T11:03:59Z")

</div>

`q` is a query string that represents the "initial characters of a patient name " something like that

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 11:04am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/12 "2019-03-19T11:04:24Z")

</div>

Yes man I understand your point.Consider I want to get 30 to 40 patient which url should I used for it?

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 11:07am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/13 "2019-03-19T11:07:11Z")

</div>

> [@naveed1228](#):
>
> 40minute

wat do u mean 40minute??

---

<div class="post-metadata">

**Author:** ![naveed1228](https://talk.openmrs.org/letter_avatar/naveed1228/32/5_5575768a8748004e209b776fc1b2916d.png) [@naveed1228](https://talk.openmrs.org/u/naveed1228)\
**Post date:** [March 19, 2019, 11:10am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/14 "2019-03-19T11:10:04Z")

</div>

Sorry I mean 40 patient

---

<div class="post-metadata">

**Author:** ![mozzy](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mozzy/32/11815_2.png) [@mozzy](https://talk.openmrs.org/u/mozzy)\
**Post date:** [March 19, 2019, 11:13am UTC](https://talk.openmrs.org/t/how-to-get-all-patient-from-database-using-rest-api/22412/15 "2019-03-19T11:13:28Z")

</div>

no you cant specify the _ **exact number of results you want to get** _ , you can only specify the **maximum number** which you dont want the results to exceed \>\> `limit` of the reults. the actual number will depend on other parameters like the `q`
