padam-api
v1.0.0
Published
Official Node.js SDK for Padam.id PLN Outage API
Maintainers
Readme
@padam/api
Official Node.js SDK for the Padam.id PLN Outage API - the first PLN outage API in Indonesia.
Installation
npm install @padam/apiQuick Start
const { PadamClient } = require('@padam/api');
const client = new PadamClient({
apiKey: 'your_api_key'
});
// Check power outage at a location
const outage = await client.checkOutage(-6.2088, 106.8456);
console.log(outage.data.summary);
// Get meter billing and token estimate
const meter = await client.getMeterSummary({ meter_id: '566601485354' });
console.log(meter.data.consumer_name);Usage
Initialize Client
const { PadamClient } = require('@padam/api');
const client = new PadamClient({
apiKey: 'your_api_key',
baseUrl: 'https://padam.id/api', // optional
timeout: 10000 // optional, default 10 seconds
});Check Power Outage
Check for power outages within 500m radius of a location.
const result = await client.checkOutage(-6.2088, 106.8456);
console.log(result.data.summary.total_poles); // Total poles found
console.log(result.data.summary.poles_on); // Poles with power
console.log(result.data.summary.poles_off); // Poles without power
console.log(result.data.summary.has_outage); // true if any pole is off
// Iterate through poles
result.data.poles.forEach(pole => {
console.log(`${pole.name}: ${pole.status}`);
});Get Meter Summary
Get billing history and token estimate for a meter.
// Using meter ID (recommended)
const result = await client.getMeterSummary({ meter_id: '566601485354' });
// Or using account ID
const result = await client.getMeterSummary({ account_id: '8651306' });
console.log(result.data.consumer_name);
console.log(result.data.energy_type);
console.log(result.data.energy);
// Token estimate (prepaid meters)
if (result.data.token_estimate) {
console.log(`Remaining days: ${result.data.token_estimate.remaining_days}`);
console.log(`Remaining kWh: ${result.data.token_estimate.remaining_kwh}`);
console.log(`Daily usage: ${result.data.token_estimate.daily_usage_kwh} kWh`);
}
// Billing history
result.data.billing_history.forEach(entry => {
console.log(`${entry.date}: Rp ${entry.amount} (${entry.kwh} kWh)`);
});Error Handling
const { PadamClient, PadamAPIError } = require('@padam/api');
try {
const result = await client.checkOutage(-6.2088, 106.8456);
} catch (error) {
if (error instanceof PadamAPIError) {
console.log(error.code); // Error code (e.g., 'INSUFFICIENT_CREDITS')
console.log(error.message); // Error message
console.log(error.statusCode); // HTTP status code
}
}TypeScript
This package includes TypeScript definitions.
import { PadamClient, OutageCheckResponse, MeterSummaryResponse } from '@padam/api';
const client = new PadamClient({ apiKey: 'your_api_key' });
const outage: OutageCheckResponse = await client.checkOutage(-6.2088, 106.8456);
const meter: MeterSummaryResponse = await client.getMeterSummary({ meter_id: '566601485354' });API Reference
PadamClient
Constructor
new PadamClient(config: PadamConfig)| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | required | Your API key |
| baseUrl | string | https://padam.id/api | API base URL |
| timeout | number | 10000 | Request timeout in ms |
Methods
checkOutage(latitude: number, longitude: number)- Check power outage at locationgetMeterSummary(options: { meter_id?: string, account_id?: string })- Get meter summary
License
MIT
Author
Akbar Naufal Awalin
