Sekolah Search + Detail #2
by RFour · Jul 21, 2026 ·javascript
I use this for my api stuff, Soo don't expect anything, it works perfectly fine for me and pretty good, I like thi cuz it's making it easier for me to do stuff :p
InfoSearchSekolahSchool
| 1 | // join le channel bro https://whatsapp.com/channel/0029Vb8QWWl1yT1znzYESZ3b |
| 2 | async function cari(body) { |
| 3 | const res = await fetch("https://sekolah.data.kemendikdasmen.go.id/v1/sekolah-service/sekolah/cari-sekolah", { |
| 4 | method: 'POST', |
| 5 | headers: { |
| 6 | 'Accept': 'application/json, text/plain, */*', |
| 7 | 'Content-Type': 'application/json', |
| 8 | 'Origin': 'https://sekolah.data.kemendikdasmen.go.id', |
| 9 | 'Referer': 'https://sekolah.data.kemendikdasmen.go.id/sekolah', |
| 10 | 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36' |
| 11 | }, |
| 12 | body: JSON.stringify(body) |
| 13 | }); |
| 14 | return res.json(); |
| 15 | } |
| 16 | |
| 17 | async function detail(id) { |
| 18 | const res = await fetch(`https://sekolah.data.kemendikdasmen.go.id/v1/sekolah-service/sekolah/full-detail/${id}`, { |
| 19 | headers: { |
| 20 | 'Accept': 'application/json, text/plain, */*', |
| 21 | 'Referer': `https://sekolah.data.kemendikdasmen.go.id/profil-sekolah/${id}`, |
| 22 | 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36' |
| 23 | } |
| 24 | }); |
| 25 | return res.json(); |
| 26 | } |
| 27 | |
| 28 | async function wilayah(keyword) { |
| 29 | const res = await fetch("https://sekolah.data.kemendikdasmen.go.id/v1/sekolah-service/referensi/wilayah", { |
| 30 | method: 'POST', |
| 31 | headers: { |
| 32 | 'Accept': 'application/json, text/plain, */*', |
| 33 | 'Content-Type': 'application/json', |
| 34 | 'Origin': 'https://sekolah.data.kemendikdasmen.go.id', |
| 35 | 'Referer': 'https://sekolah.data.kemendikdasmen.go.id/sekolah', |
| 36 | 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36' |
| 37 | }, |
| 38 | body: JSON.stringify({ keyword }) |
| 39 | }); |
| 40 | return res.json(); |
| 41 | } |
| 42 | |
| 43 | export async function sekolah2(req) { |
| 44 | const { searchParams: sp } = new URL(req.url); |
| 45 | const q = sp.get('q'); |
| 46 | const id = sp.get('id'); |
| 47 | const mode = sp.get('mode') || 'search'; |
| 48 | const page = Number(sp.get('page') || 0); |
| 49 | const size = Number(sp.get('size') || 12); |
| 50 | const kab = sp.get('kab') || ''; |
| 51 | const bentuk = sp.get('bentuk') || ''; |
| 52 | const status = sp.get('status') || ''; |
| 53 | const wkey = sp.get('wilayah'); |
| 54 | |
| 55 | if (mode === 'wilayah') { |
| 56 | if (!wkey) return { error: "missing wilayah, /sekolah2?mode=wilayah&wilayah=Probolinggo" }; |
| 57 | try { |
| 58 | const data = await wilayah(wkey); |
| 59 | return { status: true, params: { wilayah: wkey }, data: data.data || [] }; |
| 60 | } catch (err) { |
| 61 | return { error: err.message }; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (mode === 'detail' && id) { |
| 66 | try { |
| 67 | const raw = await detail(id); |
| 68 | const d = raw.data || {}; |
| 69 | |
| 70 | return { |
| 71 | status: true, |
| 72 | params: { id }, |
| 73 | data: { |
| 74 | profil: d.sekolah?.[0] || {}, |
| 75 | foto: d.foto_sekolah || [], |
| 76 | ruang: d.ruang?.[0] || {}, |
| 77 | ptk: d.ptk?.[0] || {}, |
| 78 | kurikulum: d.kurikulum?.[0] || {}, |
| 79 | rasio_siswa: d.rasio_siswa?.[0] || {}, |
| 80 | rasio_rombel: d.rasio_rombel_ruang_kelas?.[0] || {}, |
| 81 | rasio_guru: d.rasio_siswa_guru?.[0] || {}, |
| 82 | persentase_guru: d.persentase_guru?.[0] || {}, |
| 83 | persentase_kelas_layak: d.persentase_ruang_kelas_layak?.[0] || {}, |
| 84 | sekolah_sekitar: d.sekolah_sekitar || [], |
| 85 | instansi_sekitar: d.instansi_sekitar || [] |
| 86 | } |
| 87 | }; |
| 88 | } catch (err) { |
| 89 | return { error: err.message }; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (!q) { |
| 94 | return { |
| 95 | error: "missing keyword", |
| 96 | usage: { |
| 97 | search: "/sekolah2?q=anwar", |
| 98 | filter: "/sekolah2?q=anwar&status=SWASTA&bentuk=MTs, MI&kab=Kab. Probolinggo", |
| 99 | page: "/sekolah2?q=anwar&page=1&size=12", |
| 100 | wilayah: "/sekolah2?mode=wilayah&wilayah=Karawang", |
| 101 | detail: "/sekolah2?mode=detail&id=A9B4AA6C-9093-4210-83D0-9F6AB175DBB5" |
| 102 | }, |
| 103 | params: { |
| 104 | q: "keyword", |
| 105 | page: "halaman (0)", |
| 106 | size: "per halaman (12)", |
| 107 | kab: "Kab. Karawang", |
| 108 | bentuk: "SMA, SMK, MTs, MI", |
| 109 | status: "NEGERI, SWASTA" |
| 110 | } |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | try { |
| 115 | const body = { |
| 116 | page, |
| 117 | size, |
| 118 | keyword: q, |
| 119 | kabupaten_kota: kab, |
| 120 | bentuk_pendidikan: bentuk, |
| 121 | status_sekolah: status |
| 122 | }; |
| 123 | const raw = await cari(body); |
| 124 | return { |
| 125 | status: true, |
| 126 | params: { q, page, size, kab, bentuk, status }, |
| 127 | total: raw.total || 0, |
| 128 | data: raw.data || [] |
| 129 | }; |
| 130 | } catch (err) { |
| 131 | return { error: err.message }; |
| 132 | } |
| 133 | } |