Open Government, Indonesia
GovernmentExplore Indonesia's Open Data with the Public API Docs
If you've been looking for a reliable source of open data about Indonesia, you've probably heard about the data portal https://data.go.id. The website hosts a vast collection of datasets, ranging from demographic information to social and economic indicators, making it a valuable resource for researchers, developers, and data enthusiasts.
To make the data more accessible, the portal also offers a public API that allows developers to fetch data programmatically. In this article, we'll explore the API and show you some examples of how to use it in your JavaScript projects.
Getting Started
To use the API, you need to first register for an API key on the data portal. After that, you can start making requests to the API endpoints using your favorite programming language.
For this tutorial, we'll be using JavaScript with the fetch
method to make the API requests. Here's a simple example code that fetches the data from the 'pendidikan' endpoint of the API:
const API_KEY = '<your-api-key>';
const API_URL = 'https://data.go.id/api';
fetch(`${API_URL}/pendidikan?api-key=${API_KEY}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
In the code above, we first define our API key and the API endpoint URL. We then use the fetch
method to make a GET request to the 'pendidikan' endpoint with our API key as a query parameter. We then chain the response.json()
method to the promise to parse the response data as JSON. Finally, we log the data to the console.
Examples
Now that we have a basic understanding of how to fetch data with the API, let's take a look at some more advanced examples.
Example 1: Fetching All Regions Data
This example demonstrates how to fetch data from the 'wilayah/administratif' endpoint, which provides information about all the regions in Indonesia, including the provinces and the cities/regencies. Here's the code:
const API_KEY = '<your-api-key>';
const API_URL = 'https://data.go.id/api';
fetch(`${API_URL}/wilayah/administratif?level=1&api-key=${API_KEY}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
In the code above, we pass the parameter level=1
to the endpoint to fetch data for the provinces only. If you want to fetch data for the cities/regencies, change the parameter to level=2
.
Example 2: Fetching Population Data
This example demonstrates how to fetch data from the 'penduduk' endpoint, which provides information about the population in Indonesia. Here's the code:
const API_KEY = '<your-api-key>';
const API_URL = 'https://data.go.id/api';
fetch(`${API_URL}/penduduk?tahun=2020&api-key=${API_KEY}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
In the code above, we pass the parameter tahun=2020
to the endpoint to fetch population data for the year 2020. You can change the year parameter according to your needs.
Example 3: Fetching Healthcare Facilities Data
This example demonstrates how to fetch data from the 'fasilitas-kesehatan' endpoint, which provides information about the healthcare facilities in Indonesia. Here's the code:
const API_KEY = '<your-api-key>';
const API_URL = 'https://data.go.id/api';
fetch(`${API_URL}/fasilitas-kesehatan?prov=32&api-key=${API_KEY}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
In the code above, we pass the parameter prov=32
to the endpoint to fetch healthcare facilities data specifically for the province of East Java. You can change the province parameter to fetch data for other provinces in Indonesia.
Conclusion
The public API docs for https://data.go.id provide a convenient way to access open data about Indonesia. By using the examples presented in this article, you can leverage the API to fetch datasets that are relevant to your research or project needs. Happy coding!