Incorrect Paging on Filtering Organisation Units with `maxLevel` and `withinUserHiearchy` Query Parameters

Hello,
I’m trying to query organisation Units using the parameters maxLevel and withinUserHiearchy as indicated in the documentation. The challenge I’m facing is that the response comes with the correct list of organisation units but the paging on the response seems to be for the total organisation units in the instance.

Example the query:

https://play.dhis2.org/2.36.3/api/organisationUnits.json?maxLevel=2&fields=id,level&pageSize=50&withinUserHierarchy=true&totalPages=true,page=2 

Only has 13 organisation units but the response is (note the pager)

{
  "pager": {
    "page": 1,
    "pageCount": 27,
    "total": 1332,
    "pageSize": 50,
    "nextPage": "https://play.dhis2.org/2.36.3/api/organisationUnits.json?page=2&maxLevel=2&totalPages=true%2Cpage%3D2&fields=id%2Clevel&withinUserHierarchy=true"
  },
  "organisationUnits": [
    {
      "level": 2,
      "id": "O6uvpzGd5pu"
    },
    {
      "level": 2,
      "id": "fdc6uOvgoji"
    },
    {
      "level": 2,
      "id": "lc3eMKXaEfw"
    },
    {
      "level": 2,
      "id": "jUb8gELQApl"
    },
    {
      "level": 2,
      "id": "PMa2VCrupOd"
    },
    {
      "level": 2,
      "id": "kJq2mPyFEHo"
    },
    {
      "level": 2,
      "id": "qhqAxPSTUXp"
    },
    {
      "level": 2,
      "id": "Vth0fbpFcsO"
    },
    {
      "level": 2,
      "id": "jmIPBj66vD6"
    },
    {
      "level": 2,
      "id": "TEQlaapDQoK"
    },
    {
      "level": 2,
      "id": "bL4ooGhyHRQ"
    },
    {
      "level": 1,
      "id": "ImspTQPwCqd"
    },
    {
      "level": 2,
      "id": "eIQbndfxQMb"
    },
    {
      "level": 2,
      "id": "at6UHUQatSo"
    }
  ]
}

moving to the next page only results in the last organisation unit being returned

//https://play.dhis2.org/2.36.3/api/organisationUnits.json?page=2&maxLevel=2&totalPages=true%2Cpage%3D2&fields=id%2Clevel&withinUserHierarchy=true

{
  "pager": {
    "page": 2,
    "pageCount": 27,
    "total": 1332,
    "pageSize": 50,
    "nextPage": "https://play.dhis2.org/2.36.3/api/organisationUnits.json?page=3&maxLevel=2&totalPages=true%2Cpage%3D2&fields=id%2Clevel&withinUserHierarchy=true",
    "prevPage": "https://play.dhis2.org/2.36.3/api/organisationUnits.json?maxLevel=2&totalPages=true%2Cpage%3D2&fields=id%2Clevel&withinUserHierarchy=true"
  },
  "organisationUnits": [
    {
      "level": 2,
      "id": "at6UHUQatSo"
    }
  ]
}

Is this a bug or is there something I’m missing?

Thanks.

Regards

Gift Nnko

1 Like

@nnkogift changing the ‘pageSize’ to be equal to the ‘total’ solves the number so that the whole list appears in one page. I’m not sure either if this is a bug but I’ll ask. Thank you! (:

@nnkogift this is indeed a bug! Thank you! Would you like to create a Jira bug issue for this?

Hello @Gassim

Thank you for confirming. I have created a jira issue

Thanks.

1 Like