Root Organization Unit


While importing new organization units, I missed to add the Parent UID for 5 organization units.
Yet, they are not showing in the hierarchy to change their level, they are appearing as a root organization unit when trying to create a new user and assign them an org unit.
How can I delete them?
Here’s a screenshot, Lebanon is supposed to be only the Root Organization unit.



Hello @Sdn
You sound to be a super user, that said, do you see the created orgunits in the maintenance app under orgunits? If you don’t, I would suggest that you use the database level deletion if you have access to the database.

1 Like


No it does not show in the Organization unit in the Maintenance app.
Can I know the SQL statement used?

1 Like

I understand you know the period when the orgunits where created since you created them. So you can run something like

FROM organisationunit
WHERE created BETWEEN '2023-01-01' AND '2023-01-31';

with the column that contains the dates you want to filter. '2023-01-01' and '2023-01-31' represent the start and end dates respectively.

Make sure to format the dates according to the YYYY-MM-DD format, which is the standard date format in PostgreSQL.

You can further customize the query to include additional conditions or join other tables as per your specific requirements.

Note that the BETWEEN operator is inclusive, meaning it includes the start and end dates in the result set. If you want to exclude the end date, you can use the < (less than) operator instead.

FROM organisationunit
WHERE created >= '2023-01-01' AND date_column < '2023-02-01';

once you have a list of orgs created, you can delete them one at a time or at multiple.

  1. One at a time
DELETE FROM organisationunit WHERE uid= 'ryrtutitit';
  1. Multiple delete
DELETE FROM organisationunit  WHERE uid IN ('value1', 'value2', 'value3');

Alternatively if you don’t have database access, you can use API to delete. Below are the instructions.

  1. Obtain an access token: Authenticate yourself and obtain an access token to authorize API requests. The specific authentication process may vary depending on your DHIS2 setup and configuration.

  2. Identify the metadata you want to delete: Determine the specific metadata object you wish to delete, such as a data element, organization unit, indicator, etc. This time list all the orginits and get the ID’s of those you wish to delete

  3. Make a DELETE request: Use the appropriate endpoint and specify the ID of the metadata object you want to delete. The general format of the request will be:

    DELETE /api/{version}/{metadata}/{id}

    Replace {version} with the DHIS2 API version you are using (e.g., 2.35, 2.36, etc.). Replace {metadata} with the specific metadata type (e.g., dataElements, organisationUnits, etc.), and {id} with the ID of the metadata object you wish to delete.

  4. Include the access token: Ensure that you include the access token in the headers of your API request for authentication.

  5. Send the request: Execute the DELETE request using your preferred programming language or API testing tool. Upon successful execution, the specified metadata object will be deleted from the DHIS2 instance.

It’s essential to exercise caution when deleting metadata using the DHIS2 API, as it can have significant implications on the system’s configuration and data. Make sure to have appropriate backups and confirm that you are deleting the correct metadata before proceeding.

Please refer to the DHIS2 API documentation for further details on specific endpoints and parameters related to metadata deletion.

Let us know if you need further guidance.

  • Moses
1 Like