Skip to main content

API Reference

wilayah-indonesia is a CLI, not a library. This page documents its commands and output shape, generated from src/.

CLI Flags

FlagAliasDescription
--fetch-fFetch raw data from the BPS API into data/raw/
--transform <type>-tTransform raw data into data/transformed/<type>/. type is json, csv, or sql
--version-VPrint CLI version
--help-hPrint help

Source: src/index.js

Fetch

--fetch pulls from the BPS bridging API (sig.bps.go.id) in order, each level scoped to its parent, with up to 100 concurrent requests:

  1. Provinces
  2. Regencies (per province)
  3. Districts (per regency)
  4. Subdistricts (per district)
  5. Postal codes (per province, separate getwilayah pos endpoint)

Raw output is written to data/raw/{1..5}-<type>.json, matching the BPS response shape (kode_bps, nama_bps, ...).

Source: src/fetch-data.js

Transform

--transform <type> reads data/raw/ and writes relational records to data/transformed/<type>/. All five entities are transformed in parallel.

Provinces

{ "code": "11", "name": "Aceh" }

Regencies

{ "code": "1101", "name": "Simeulue", "province_code": "11" }

Districts

{ "code": "1101010", "name": "Teupah Selatan", "regency_code": "1101" }

Subdistricts

{ "code": "1101010001", "name": "Latiung", "district_code": "1101010" }

Postal Codes

{ "code": 1, "postcode": "23891", "postname": "Latiung", "subdistrict_code": "1101010001" }

code fields are derived by slicing the parent's BPS code (province: 2 digits, regency: 4, district: 7). Names are title-cased. Postal code code is a sequential index, not a BPS code.

Output formats:

  • json: JSON.stringify(data, null, 2)
  • csv: via objects-to-csv
  • sql: INSERT INTO <type> (...) VALUES (...); statements, one per row

Source: src/transform-data.js, src/helper/sql.js