Node.js
Server-side Node.js examples for both JKT48 and KLP48 APIs using fetch and axios.
Node.js
Node.js is ideal for building bots, cron jobs, and backend services that consume both APIs.
Base URL: https://v2.jkt48connect.com/api
JKT48 API — Fetch Members (Native fetch, Node 18+)
const JKT48_KEY = process.env.JKT48_API_KEY || 'YOUR_API_KEY';
async function getJKT48Members() {
const res = await fetch(
`https://v2.jkt48connect.com/api/jkt48/members?apikey=${JKT48_KEY}`
);
const members = await res.json();
console.log(`JKT48: ${members.length} members found`);
members.filter(m => !m.is_graduate).forEach(m => {
console.log(` - ${m.name} (${m.generation})`);
});
}
getJKT48Members();JKT48 API — Live Stream Monitor (Polling)
async function monitorJKT48Live() {
while (true) {
try {
const res = await fetch(
`https://v2.jkt48connect.com/api/jkt48/live?apikey=${JKT48_KEY}`
);
const streams = await res.json();
if (streams.length > 0) {
console.log(`🔴 ${streams.length} members are live!`);
streams.forEach(s => console.log(` ${s.name} on ${s.type}`));
} else {
console.log('No active streams.');
}
} catch (err) {
console.error('Poll error:', err.message);
}
// Wait 60 seconds between polls to avoid rate limiting
await new Promise(r => setTimeout(r, 60000));
}
}KLP48 API — Using Axios Interceptors
// npm install axios
const axios = require('axios');
const PRIORITY_TOKEN = process.env.KLP48_TOKEN || 'P-ABCD1234';
// Create a reusable Axios instance for KLP48
const klp48 = axios.create({
baseURL: 'https://v2.jkt48connect.com/api/klp48',
timeout: 10000,
headers: { 'x-priority-token': PRIORITY_TOKEN }
});
// Fetch members
async function getKLP48Members() {
const { data } = await klp48.get('/members');
if (data.success) {
console.log(`KLP48: ${data.total} members`);
data.data.forEach(m => console.log(` - ${m.name}`));
}
}
// Fetch schedule
async function getKLP48Schedule(status = 'upcoming') {
const { data } = await klp48.get('/schedule', { params: { status } });
if (data.success) {
console.log(`📅 ${data.total} ${status} events`);
data.data.forEach(e => console.log(` - ${e.title} on ${e.date}`));
}
}
// Fetch news with pagination
async function getKLP48News(page = 1, perpage = 5) {
const { data } = await klp48.get('/news', { params: { page, perpage } });
if (data.success) {
data.data.forEach(n => console.log(`📰 ${n.headline}`));
}
}
// Fetch specific news by ID
async function getKLP48NewsById(id) {
const { data } = await klp48.get(`/news/${id}`);
if (data.success && data.data.length > 0) {
console.log(`Title: ${data.data[0].headline}`);
console.log(`Content: ${data.data[0].content}`);
}
}
// Fetch releases
async function getKLP48Releases() {
const { data } = await klp48.get('/releases');
if (data.success) {
data.data.forEach(r => console.log(`🎵 ${r.title} (${r.type})`));
}
}
// Fetch birthdays
async function getKLP48Birthdays(month = null) {
const url = month ? `/birthdays/${month}` : '/birthdays';
const { data } = await klp48.get(url);
if (data.success) {
data.data.forEach(m => console.log(`🎂 ${m.name} — ${m.birthdate}`));
}
}
// Run them all
(async () => {
await getJKT48Members();
await getKLP48Members();
await getKLP48Schedule('today');
await getKLP48News(1, 3);
await getKLP48Releases();
await getKLP48Birthdays(4);
})();