Batch parse
Parse up to 100 NIK, KK, plate, NPWP or region values in one request.
リクエスト
POST
https://api.bitaloka.io/v1/batch JSON ボディ→
application/json パラメーター
| 名前 | 型 | 説明 |
|---|---|---|
items必須 | テキスト | Up to 100 items; type is nik, kk, plate, npwp or region.例: [{"type":"nik","value":"3171014501900001"},{"type":"plate","value":"B1… |
コードサンプル
単一のソースから生成し、本番 API でテストしています。
curl -sS -X POST "https://api.bitaloka.io/v1/batch" \
-H "X-API-Key: $BITALOKA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"items":[{"type":"nik","value":"3171014501900001"},{"type":"plate","value":"B1234XYZ"}]}' \
--fail-with-body const apiKey = process.env.BITALOKA_API_KEY ?? ''
const res = await fetch("https://api.bitaloka.io/v1/batch", {
method: 'POST',
headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' },
body: JSON.stringify({
"items": [
{
"type": "nik",
"value": "3171014501900001"
},
{
"type": "plate",
"value": "B1234XYZ"
}
]
}),
})
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`)
const data = await res.json()
console.log(data) type BatchResponse = {
results: {
type: string
value: string
result: {
valid: boolean
input: string
normalized: string
gender: string
birthDate: {
day: number
month: number
yearTwoDigit: number
yearCandidates: number[]
yearResolved: number
yearIsAmbiguous: boolean
}
region: {
province: {
code: string
name: string
}
regency: {
code: string
name: string
}
district: {
code: string
name: string
}
}
serial: string
genderConsistent: boolean
summary: string
errors: string[]
warnings: {
code: string
message: string
}[]
}
}[]
}
const apiKey = process.env.BITALOKA_API_KEY ?? ''
const res = await fetch("https://api.bitaloka.io/v1/batch", {
method: 'POST',
headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' },
body: JSON.stringify({
"items": [
{
"type": "nik",
"value": "3171014501900001"
},
{
"type": "plate",
"value": "B1234XYZ"
}
]
}),
})
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`)
const data = (await res.json()) as BatchResponse
console.log(data) import os
import requests
API_KEY = os.environ.get("BITALOKA_API_KEY", "")
res = requests.post(
"https://api.bitaloka.io/v1/batch",
headers={"X-API-Key": API_KEY},
json={"items": [{"type": "nik", "value": "3171014501900001"}, {"type": "plate", "value": "B1234XYZ"}]},
timeout=30,
)
res.raise_for_status()
print(res.json()) import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Example {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
var apiKey = System.getenv().getOrDefault("BITALOKA_API_KEY", "");
var json = "{\"items\":[{\"type\":\"nik\",\"value\":\"3171014501900001\"},{\"type\":\"plate\",\"value\":\"B1234XYZ\"}]}";
var request = HttpRequest.newBuilder(URI.create("https://api.bitaloka.io/v1/batch"))
.header("X-API-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 400) {
throw new RuntimeException("HTTP " + response.statusCode() + ": " + response.body());
}
System.out.println(response.body());
}
} using System.Net.Http.Json;
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("BITALOKA_API_KEY") ?? "");
var res = await http.PostAsJsonAsync("https://api.bitaloka.io/v1/batch", new { items = new object[] { new { type = "nik", value = "3171014501900001" }, new { type = "plate", value = "B1234XYZ" } } });
if (!res.IsSuccessStatusCode)
throw new HttpRequestException($"HTTP {(int)res.StatusCode}: {await res.Content.ReadAsStringAsync()}");
Console.WriteLine(await res.Content.ReadAsStringAsync()); <?php
$ch = curl_init('https://api.bitaloka.io/v1/batch');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('BITALOKA_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['items' => [['type' => 'nik', 'value' => '3171014501900001'], ['type' => 'plate', 'value' => 'B1234XYZ']]]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($body === false || $status >= 400) {
throw new RuntimeException("HTTP $status: $body");
}
print_r(json_decode($body, true)); package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload, err := json.Marshal(map[string]any{"items": []any{map[string]any{"type": "nik", "value": "3171014501900001"}, map[string]any{"type": "plate", "value": "B1234XYZ"}}})
check(err)
req, err := http.NewRequest("POST", "https://api.bitaloka.io/v1/batch", bytes.NewReader(payload))
check(err)
req.Header.Set("X-API-Key", os.Getenv("BITALOKA_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
check(err)
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
check(err)
if res.StatusCode >= 400 {
panic(fmt.Sprintf("HTTP %d: %s", res.StatusCode, body))
}
fmt.Println(string(body))
}
func check(err error) {
if err != nil {
panic(err)
}
} // build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
fun main() {
val client = OkHttpClient()
val json = "{\"items\":[{\"type\":\"nik\",\"value\":\"3171014501900001\"},{\"type\":\"plate\",\"value\":\"B1234XYZ\"}]}"
val body = json.toRequestBody("application/json".toMediaType())
val request = Request.Builder()
.url("https://api.bitaloka.io/v1/batch")
.header("X-API-Key", System.getenv("BITALOKA_API_KEY") ?: "")
.post(body)
.build()
client.newCall(request).execute().use { res ->
check(res.isSuccessful) { "HTTP ${res.code}: ${res.body?.string()}" }
println(res.body!!.string())
}
} import Foundation
var request = URLRequest(url: URL(string: "https://api.bitaloka.io/v1/batch")!)
request.setValue(ProcessInfo.processInfo.environment["BITALOKA_API_KEY"] ?? "", forHTTPHeaderField: "X-API-Key")
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let payload: [String: Any] = ["items": [["type": "nik", "value": "3171014501900001"], ["type": "plate", "value": "B1234XYZ"]]]
request.httpBody = try JSONSerialization.data(withJSONObject: payload)
let (data, response) = try await URLSession.shared.data(for: request)
guard let http = response as? HTTPURLResponse, http.statusCode < 400 else {
fatalError("Request failed: \(String(decoding: data, as: UTF8.self))")
}
print(String(decoding: data, as: UTF8.self)) // Cargo.toml: reqwest = { version = "0.12", features = ["blocking", "json"] }, serde_json = "1"
fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("BITALOKA_API_KEY").unwrap_or_default();
let client = reqwest::blocking::Client::new();
let res = client
.post("https://api.bitaloka.io/v1/batch")
.header("X-API-Key", api_key)
.json(&serde_json::json!({"items":[{"type":"nik","value":"3171014501900001"},{"type":"plate","value":"B1234XYZ"}]}))
.send()?
.error_for_status()?;
println!("{}", res.text()?);
Ok(())
} レスポンス
例のリクエストに対する本番 API からの実際のレスポンスです。
{
"results": [
{
"type": "nik",
"value": "3171014501900001",
"result": {
"valid": true,
"input": "3171014501900001",
"normalized": "3171014501900001",
"gender": "P",
"birthDate": {
"day": 5,
"month": 1,
"yearTwoDigit": 90,
"yearCandidates": [
1990,
2090
],
"yearResolved": 1990,
"yearIsAmbiguous": false
},
"region": {
"province": {
"code": "31",
"name": "Daerah Khusus Ibukota Jakarta"
},
"regency": {
"code": "3171",
"name": "Kota Administrasi Jakarta Pusat"
},
"district": {
"code": "317101",
"name": "Gambir"
}
},
"serial": "0001",
"genderConsistent": false,
"summary": "Perempuan, lahir 5 Januari 1990, Gambir, Kota Administrasi Jakarta Pusat, Daerah Khusus Ibukota Jakarta",
"errors": [],
"warnings": [
{
"code": "GENDER_MISMATCH",
"message": "Gender from birth-day offset does not match serial parity (last digit). Possible data-entry error."
}
]
}
},
{
"type": "plate",
"value": "B1234XYZ",
"result": {
"valid": true,
"input": "B1234XYZ",
"normalized": "B1234XYZ",
"prefix": "B",
"number": "1234",
"suffix": "XYZ",
"region": {
"code": "B",
"name": "DKI Jakarta",
"area": "Jakarta dan sekitarnya (Depok, Tangerang, Bekasi)"
},
"vehicle": {
"code": "PASSENGER_CAR",
"label": "Mobil penumpang (pribadi)"
},
"suffixDetail": {
"areaCode": "X",
"classCode": "Y",
"serialCode": "Z"
},
"summary": "DKI Jakarta, Jakarta dan sekitarnya (Depok, Tangerang, Bekasi), Mobil penumpang (pribadi)",
"errors": [],
"warnings": [
{
"code": "STNK_VALIDITY_NOT_ENCODED",
"message": "STNK validity month/year is printed directly on the plate; suffix letters are not a reliable source for it."
}
]
}
}
]
} AI エージェントから使う
MCP ツールとしては公開されていません。エージェントは代わりに単一項目用のツールを呼び出せます。