Pull Geocodes for Facilities Using API

Dear All,
Is there a way to pull facility geo coordinates using the API or any other method in DHIS2?

Would appreciate your help.

Thank you.

1 Like

Hi Dr. Okoye,

You can use the below api to pull facility geo coordinates:

baseUrl+“api/organisationUnits.json?fields=id,code,name,latitude,longitude,coordinates”

In React JS you can fetch:
const fetchOptions = {
headers: {
Accept: ‘application/json’,
Authorization: Basic ${btoa('admin:district')}
}
};
return new Promise( (resolve, reject) => {
fetch(baseUrl+“api/organisationUnits.json?fields=id,code,name,latitude,longitude,coordinates”, fetchOptions)
.then(r => resolve(r.json()))
.catch(err => reject(err));
});

Thanks

1 Like

Thank you. Will get back to you on this.

1 Like

Hi Dr Okoye,

It might also be helpful to add ‘featureType’, which helps you distinguish points from polygons/areas. See a similar discussion here.

Cheers, Sam.

1 Like

Thank you @SamuelJohnson. Is there a way to add the org unit level as well?

1 Like

Sure, just add ‘,level’ to the list of fields. To see a full list of all fields available, you can do ?fields=* - this will return every available field (but I’d remove ‘&paging=false’ before you do that, as otherwise it will return a lot of data!).

1 Like

Thank you so much @SamuelJohnson

1 Like