Snippets

Back to snippets

Indonesian Ministry of Education School Search and Detail Complete

Updated 2026-11-01
Node.js scraper for the Indonesian Ministry of Education school API. Pass a school name and it prints a list of matching schools with NPSN, location, and internal UUID. Pass a UUID and it fetches the school's full profile from eight endpoints. details, class groups, accreditation, staff, facilities, sanitation, ICT, report card, and prints them.
const API = 'https://sekolah.data.kemendikdasmen.go.id/v1/sekolah-service';const H = {  accept: 'application/json, text/plain, */*',  'content-type': 'application/json',  origin: 'https://sekolah.data.kemendikdasmen.go.id',  referer: 'https://sekolah.data.kemendikdasmen.go.id/sekolah',  'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 Chrome/137 Mobile Safari/537.36'};const isUuid = (s) => /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i.test(s);async function search(q, size = 20) {  const res = await fetch(API + '/sekolah/cari-sekolah', {    method: 'POST',    headers: H,    body: JSON.stringify({ page: 0, size, keyword: q, kabupaten_kota: '', bentuk_pendidikan: '', status_sekolah: '' })  });  return res.json();}async function detail(id) {  const ref = 'https://sekolah.data.kemendikdasmen.go.id/profil-sekolah/' + id;  const h = { accept: 'application/json', referer: ref, 'user-agent': H['user-agent'] };  const get = (p) => fetch(API + '/sekolah' + p, { headers: h }).then((r) => r.json()).catch(() => null);  const [full, rombel, akre, ptk, sarpras, sanitasi, tik, rapor] = await Promise.all([    get('/full-detail/' + id),    get('/rombongan-belajar/' + id),    get('/akreditasi/' + id),    get('/ptk/' + id),    get('/sarana-prasarana/' + id),    get('/sanitasi/' + id),    get('/tik/' + id),    get('/rapor/' + id)  ]);  return { id, full, rombel, akre, ptk, sarpras, sanitasi, tik, rapor };}function ask(q) {  return new Promise((resolve) => {    process.stdout.write(q);    process.stdin.once('data', (d) => resolve(d.toString().trim()));  });}(async () => {  let arg = process.argv.slice(2).join(' ').trim();  if (!arg) arg = await ask('Cari sekolah / ID: ');  if (!arg) return;  if (isUuid(arg)) {    console.log(JSON.stringify(await detail(arg), null, 2));    return;  }  const d = await search(arg);  const rows = d.data || [];  if (!rows.length) {    console.log('gada hasil le.');    return;  }  for (const r of rows) console.log(`${r.nama} | ${r.npsn} | ${r.kabupaten || '-'}, ${r.provinsi || '-'} | ${r.sekolah_id}`);})();