Houjin-Bango Corporate Info Retrieve
Access the National Tax Agency corporate number Web-API v3 and obtain the business name, address and reading data corresponding to the corporate number (13 digit number). “Application ID” from the National Tax Agency (free) needed.
2018 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set Application Id (Access Key) for Houjin Web-API *
  • B: Select STRING/SELECT for a Corporate Number *
  • C: Select STRING DATA for Corporate Name (update)
  • D: Select STRING DATA for Corporate PostCode (update)
  • E: Select STRING DATA for Corporate Address (update)
  • F: Select STRING DATA for Corporate Furigana (update)
  • G: Select DATE DATA for Last Update Date (update)
Script
// Rhino engine (engine type: 0) to use E4X

//////// START "main()" ////////
main();
function main(){

//// == Config Retrieving ==
var appId   = configs.get( "conf_AppId" )   + ""; // required
var dataIdB = configs.get( "conf_DataIdB" ) + ""; // required
var dataIdC = configs.get( "conf_DataIdC" ) + "";
var dataIdD = configs.get( "conf_DataIdD" ) + "";
var dataIdE = configs.get( "conf_DataIdE" ) + "";
var dataIdF = configs.get( "conf_DataIdF" ) + "";
var dataIdG = configs.get( "conf_DataIdG" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'

//// == Data Retrieving ==
var strCorpNum = "";
  if( engine.findDataDefinitionByNumber( dataIdB ).matchDataType( "SELECT_SINGLE" ) ){
    strCorpNum = engine.findDataByNumber( dataIdB ).get(0).getValue() + "";
  }else{
    strCorpNum = engine.findDataByNumber( dataIdB ) + "";
  }

//// == Calculating ==
// prepare API Request
var apiRequest = httpClient.begin(); // HttpRequestWrapper
  // - com.questetra.bpms.core.event.scripttask.HttpClientWrapper
apiRequest     = apiRequest.queryParam( "id", appId );
apiRequest     = apiRequest.queryParam( "number", strCorpNum );
apiRequest     = apiRequest.queryParam( "type", 12 ); // Response Format: XML
apiRequest     = apiRequest.queryParam( "history", 0 );

// access API (with get())
var response    = apiRequest.get( "https://api.houjin-bangou.nta.go.jp/3/num" );
var httpStatus  = response.getStatusCode() + ""; // HttpResponseWrapper
var responseStr = response.getResponseAsString() + "";
engine.log( "GET [Corp Info]: " + httpStatus );
engine.log( " responseStr: \n" + responseStr ); // for debug
if( httpStatus !== "200" ){
  var errorMessage = "\n- HTTP STATUS is not 200, Service Task stopped. -\n";
  errorMessage += responseStr + "\n";
  throw new Error( errorMessage );
}

// parse XML (ECMAScript for XML (E4X))
responseStr = responseStr.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");
// E4X bug 336551
var xmlObj = new XML( responseStr );
var strCorpName     = xmlObj.corporation[0].name + "";
var strCorpPostCode = xmlObj.corporation[0].postCode + "";
var strCorpAddress  = xmlObj.corporation[0].prefectureName + "";
    strCorpAddress += xmlObj.corporation[0].cityName + "";
    strCorpAddress += xmlObj.corporation[0].streetNumber + "";
var strCorpFurigana = xmlObj.corporation[0].furigana + "";
var strCorpUpdate   = xmlObj.corporation[0].updateDate + "";

//// == Data Updating ==
if( dataIdC !== "" ){
  engine.setDataByNumber( dataIdC, strCorpName );
}
if( dataIdD !== "" ){
  engine.setDataByNumber( dataIdD, strCorpPostCode );
}
if( dataIdE !== "" ){
  engine.setDataByNumber( dataIdE, strCorpAddress );
}
if( dataIdF !== "" ){
  engine.setDataByNumber( dataIdF, strCorpFurigana );
}
if( dataIdG !== "" ){
  engine.setDataByNumber( dataIdG, java.sql.Date.valueOf(strCorpUpdate) );
}

} //////// END "main()" ////////

Download

Capture

Notes

  • Update data with information obtained by the Web – API function of the National Tax Agency corporate number system
  • It is desirable that “This service itself is not guaranteed by the National Tax Service Agency” is explicit against users.

Additional Info: Example of XML Response

<?xml version="1.0" encoding="UTF-8"?><corporations><lastUpdateDate>2018-10-15</lastUpdateDate><count>1</count><divideNumber>1</divideNumber><divideSize>1</divideSize>
<corporation><sequenceNumber>1</sequenceNumber><corporateNumber>6130001031686</corporateNumber><process>01</process><correct>1</correct><updateDate>2018-07-13</updateDate><changeDate>2015-10-05</changeDate>
<name>株式会社クエステトラ</name><nameImageId/><kind>301</kind><prefectureName>京都府</prefectureName><cityName>京都市中京区</cityName><streetNumber>御池通間之町東入高宮町206</streetNumber>
<addressImageId/><prefectureCode>26</prefectureCode><cityCode>104</cityCode><postCode>6040835</postCode>
<addressOutside/><addressOutsideImageId/><closeDate/><closeCause/><successorCorporateNumber/><changeCause/><assignmentDate>2015-10-05</assignmentDate><latest>1</latest>
<enName/><enPrefectureName/><enCityName/><enAddressOutside/>
<furigana>クエステトラ</furigana></corporation></corporations>

See also

1 thought on “Houjin-Bango Corporate Info Retrieve”

  1. Pingback: My-Number String, Test Check Digit – Questetra Support

Comments are closed.

%d bloggers like this: