Corp Num Web-API: Organizations, Search Name with ID
Corp Num Web-API: Organizations, Search Name with ID
Searches the corporate name, furigana, address, history, etc, using a 13-digit identifier, accessing the Corporate Number System Web-API (about 5 million companies registered with the National Tax Agency Japan). An application ID is required in advance.
Configs
  • A: Set Application Id (Access Key) for Houjin Web-API *#{EL}
  • B: Set 13-digit Corporate Number *#{EL}
  • C: Select STRING DATA for Latest Name
  • C2: Select STRING DATA for Latest FuriganaName
  • D: Select STRING DATA for Latest PostCode
  • E: Select STRING DATA for Latest Address
  • F: Select STRING DATA for Latest ChangeCause
  • G: Select STRING DATA that stores History TSV (update)
  • H: Select STRING DATA for Detail URL
Script (click to open)
// GraalJS Script (engine type: 2)
/*
NOTES
- Change history TSV sorts the latest information at the top.
    - TSV format: Change Date, Name, Zip, Address, URL, Change Cause (mostly empty)
- This automated step ends with an error in case of no search result.
- History records before the number law enforcement date (2015-10-05) is not listed.
- Accesses the "Corporate Number Web-API" (v4) of the National Tax Agency Japan.
    - Depends on the Web-API function of Corporate Number System by National Tax Agency
    - The contents of this Addon is not guaranteed by National Tax Agency
NOTE-ja
- 変更履歴TSVは最新情報が上位にソートされます(新しい順)
    - 変更履歴TSV: 変更年月日, 名称, 郵便番号, 所在地, 詳細URL, 変更事由(多くは空)
- 検索結果がゼロ件の場合、この自動処理工程はエラー終了します。
- 番号法施行日(2015-10-05)以前の変更履歴は表示されません。
- 日本国の国税庁システム「法人番号 Web-API」(v4)にアクセスします。
    - 国税庁法人番号システムのWeb-API機能を利用して取得した情報をもとに作成されます。
    - Addon の内容が国税庁によって保証されているものではありません。
*/

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAccessKey         = configs.get( "StrConfA" )  + ""; // required
const strCorpNum           = configs.get( "StrConfB" )  + ""; // required
const strPocketLatestName  = configs.getObject( "SelectConfC" );
const strPocketLatestFuri  = configs.getObject( "SelectConfC2");
const strPocketLatestZip   = configs.getObject( "SelectConfD" );
const strPocketLatestAddr  = configs.getObject( "SelectConfE" );
const strPocketLatestCause = configs.getObject( "SelectConfF" );
const strPocketTsv         = configs.getObject( "SelectConfG" );
const strPocketUrl         = configs.getObject( "SelectConfH" );
if( strAccessKey === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {A:ApplicationId} is empty \n" );
}
const regCorpNum = /^\d{13}$/; // RegExp
if( ! regCorpNum.test( strCorpNum ) ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {B:CorpNum} must be 13-digit \n" );
}
engine.log( " AutomatedTask CorpNum: " + strCorpNum );


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==

// prepare request1
// ref) 第六編 Web-APIのリクエストの設定方法及び提供データの内容について
// https://www.houjin-bangou.nta.go.jp/webapi/kyuusiyousyo.html
// https://www.houjin-bangou.nta.go.jp/documents/k-web-api-kinou-ver4.pdf
// ref) 第二編 Web-APIのリクエストの設定方法及び提供データの内容について(概要編)
// https://www.houjin-bangou.nta.go.jp/webapi/index.html#web-api03
// https://www.houjin-bangou.nta.go.jp/documents/k-web-api-kinou-gaiyo.pdf

let uri1     = "https://api.houjin-bangou.nta.go.jp/4/num"; // num: Number to Info
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.queryParam( "id",     strAccessKey );
    request1 = request1.queryParam( "number", strCorpNum );
    request1 = request1.queryParam( "type",   "12" ); // 応答形式12:XML
    request1 = request1.queryParam( "history", "1" ); // 変更履歴1:あり
engine.log( " AutomatedTask ApiRequest1 Prepared" );

// post request1
const response1     = request1.get( uri1 );       // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + uri1 );
const response1Code = response1.getStatusCode() + ""; // (primitive string)
const response1Body = response1.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}

// parse response1
// engine.log( " AutomatedTask ApiResponse Body: \n" + response1Body );
/// parse XML
// com.questetra.bpms.core.event.scripttask.XPathWrapper
// - https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#XPathWrapper
// com.questetra.bpms.core.event.scripttask.XPathWrapper.NodeWrapper
// com.questetra.bpms.core.event.scripttask.XPathWrapper.NodeListWrapper

/// extract Search Result info
const numSearchedCorp = xpath.findNodeText( response1Body, "/corporations/count" ) - 0;
if( numSearchedCorp === 0 ){
  throw new Error( "\n AutomatedTask UnexpectedSearchResultError: " +
                    "No results for '" + strCorpNum + "'\n" );
}
engine.log( " AutomatedTask #ofSearchResult: " + numSearchedCorp );
let numCorpList = numSearchedCorp > 1000 ? 1000 : numSearchedCorp;

/// store into array (Change Date, Name, Zip, Address, Change Cause)
let arrCorps = new Array( numCorpList );
for( let i = 0; i < numCorpList; i++ ){ // Oldest First (古い順)
  let xpathCorp = "/corporations/corporation[" + (i+1) + "]";
  arrCorps[i] = {};
  arrCorps[i].cdate  = xpath.findNodeText( response1Body, xpathCorp + "/changeDate" );
  arrCorps[i].name   = xpath.findNodeText( response1Body, xpathCorp + "/name" );
  arrCorps[i].furi   = xpath.findNodeText( response1Body, xpathCorp + "/furigana" );
  arrCorps[i].zip    = xpath.findNodeText( response1Body, xpathCorp + "/postCode" );
  arrCorps[i].addr   = xpath.findNodeText( response1Body, xpathCorp + "/prefectureName" ) +
                       xpath.findNodeText( response1Body, xpathCorp + "/cityName" ) +
                       xpath.findNodeText( response1Body, xpathCorp + "/streetNumber" );
  arrCorps[i].ccause = xpath.findNodeText( response1Body, xpathCorp + "/changeCause" );
}

// output
let strLatestName  = arrCorps[ numCorpList - 1 ].name;
let strLatestFuri  = arrCorps[ numCorpList - 1 ].furi;
let strLatestZip   = arrCorps[ numCorpList - 1 ].zip;
let strLatestAddr  = arrCorps[ numCorpList - 1 ].addr;
let strLatestCause = arrCorps[ numCorpList - 1 ].ccause;
let strUrl         = "https://www.houjin-bangou.nta.go.jp/henkorireki-johoto.html?selHouzinNo=" +
                     strCorpNum;
let strTsv         = "";
for( let i = 0; i < numCorpList; i++ ){ // Newest First (新しい順)
  strTsv          += arrCorps[ numCorpList - 1 - i ].cdate + "\t" +
                     arrCorps[ numCorpList - 1 - i ].name + "\t" +
                     arrCorps[ numCorpList - 1 - i ].zip + "\t" +
                     arrCorps[ numCorpList - 1 - i ].addr + "\t" +
                     arrCorps[ numCorpList - 1 - i ].ccause;
  if( i !== numCorpList - 1 ){
    strTsv        += "\n";
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketLatestName !== null ){
  engine.setData( strPocketLatestName, strLatestName );
}
if( strPocketLatestFuri !== null ){
  engine.setData( strPocketLatestFuri, strLatestFuri );
}
if( strPocketLatestZip !== null ){
  engine.setData( strPocketLatestZip,  strLatestZip );
}
if( strPocketLatestAddr !== null ){
  engine.setData( strPocketLatestAddr, strLatestAddr );
}
if( strPocketLatestCause !== null ){
  engine.setData( strPocketLatestCause,strLatestCause );
}
if( strPocketTsv !== null ){
  engine.setData( strPocketTsv,        strTsv );
}
if( strPocketUrl !== null ){
  engine.setData( strPocketUrl,        strUrl );
}

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


/*
APPENDIX
- response sample
<?xml version="1.0" encoding="UTF-8"?>
<corporations>
  <lastUpdateDate>2020-10-20</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>
    <hihyoji>0</hihyoji>
  </corporation>
</corporations>
*/


Download

2020-10-20 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/corp-num-web-api-organizations-search-name-with-id/
The Addon-import feature is available with Professional edition.

Notes

  • Change history TSV sorts the latest information at the top
    • TSV format: Change Date, Name, Zip, Address, URL, Change Cause (mostly empty)
  • This automated step ends with an error in the event of no search results
  • History records before the effective date of the number law (2015-10-05) are not listed
  • Accesses the Corporate Number Web-API (v4) of the National Tax Agency Japan
    • Depends on the Web-API function of the National Tax Agency’s Corporate Number System
    • The content of this Add-on is not guaranteed by the National Tax Agency

Capture

Searches the corporate name, furigana, address, history, etc, with the 13-digit identifier, accessing to the Corporate Number System Web-API, about 5 million companies registered by National Tax Agency Japan. "Application ID" is required in advance.

See also

5 thoughts on “Corp Num Web-API: Organizations, Search Name with ID”

  1. Pingback: Corp Num Web-API: Organizations, Search ID with Name – Questetra Support

  2. Pingback: Houjin-Bango Corporate Info Retrieve – Questetra Support

  3. Pingback: Corporate-Number String, Test Check Digit – Questetra Support

  4. Pingback: Get Info via Corporate Number API – Questetra Support

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: