import axios from "axios";
export interface CorporateInfo {
name: string;
prefecture: string;
city: string;
address: string;
type?: string;
}
export class CorporateNumberClient {
private apiKey: string;
private baseUrl = "https://api.houjin-bangou.nta.go.jp/4";
constructor(apiKey: string) {
this.apiKey = apiKey;
}
async getCorporateInfo(corporateNumber: string): Promise<CorporateInfo | null> {
try {
// https://www.houjin-bangou.nta.go.jp/web/api/
// num-only method: /num
const url = `${this.baseUrl}/num`;
const response = await axios.get(url, {
params: {
id: this.apiKey,
number: corporateNumber,
type: "12", // JSON
history: "0", // No history
},
});
if (response.data && response.data.corporation) {
const corp = response.data.corporation;
return {
name: corp.name,
prefecture: corp.prefectureName,
city: corp.cityName,
address: `${corp.prefectureName}${corp.cityName}${corp.streetNumber}`,
type: corp.kind, // This might need mapping to human readable string
};
}
return null;
} catch (error) {
console.error("Error fetching corporate info:", error);
throw error;
}
}
}