Pull Geocodes for Facilities Using API

(Dr. Ifeanyi Okoye) #1

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
(Julhas Sujan) #2

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
(Dr. Ifeanyi Okoye) #3

Thank you. Will get back to you on this.

1 Like
(Samuel Johnson) #4

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
(Dr. Ifeanyi Okoye) #5

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

1 Like
(Samuel Johnson) #6

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
(Dr. Ifeanyi Okoye) #7

Thank you so much @SamuelJohnson

1 Like