The platform provides access to data compiled through the UN System in preparation for the Secretary-General’s annual report on “Progress towards the Sustainable Development Goals”. Data can be downloaded from the databse through an interactive interface (https://unstats.un.org/sdgs/indicators/database/).
UNSD also hosts an SDG API (https://unstats.un.org/SDGAPI/swagger/). Here’s how to get data from there.
The home page will help you build the URLs for the data you are looking for.
Scroll down to the “Series” section and click on “/v1/sdg/Series/Data”. Here you will be able to enter parameters to get to the data that you want.
At the very least you’ll have to know the country code and the series code. M49 country codes can be found here https://unstats.un.org/unsd/methodology/m49/ Series code can be found in the UNSD Global SDG Indicators Database (https://unstats.un.org/sdgs/indicators/database/).
Once you enter the information, you will get a URL under “Requested URL”. Copy this URL.
#you only need jsonlite to get data from API
library(jsonlite)
## Warning: package 'jsonlite' was built under R version 3.5.3
#make an object and paste the URL you got from above
url <- c("https://unstats.un.org/SDGAPI/v1/sdg/Series/Data?seriesCode=EG_ELC_ACCS&areaCode=4")
datcall <- fromJSON(url) #depending on the data you are calling, you will get a list
names(datcall)
## [1] "size" "totalElements" "totalPages" "pageNumber"
## [5] "attributes" "dimensions" "data"
dat <- datcall$data #select the data table from the list
DT::datatable(dat, extensions = 'FixedColumns',
options = list(
dom = 't',
scrollX = TRUE,
scrollCollapse = TRUE
))