Corp Num Web-API: Organizations, Search ID with Name
Corp Num Web-API: Organizations, Search ID with Name
Searches the 13-digit identifier with the corporate name, etc., accessing the Corporate Number System Web-API (about 5 million companies registered by 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 Search Term of Corporate Name *#{EL}
  • B2: Set Prefecture if filtering with registered location (eg京都府)#{EL}
  • C1: Select STRING DATA for Num of first search result
  • C2: Select STRING DATA for Name of first search result
  • D1: Select STRING DATA for list of Numbers (update)
  • D2: Select STRING DATA for list of Names-Addresses (update)
  • E: Select STRING DATA that stores search result TSV (update)
Script (click to open)
// GraalJS Script (engine type: 2)
/*
NOTES
- The search is ambiguous in the "partial match".
     - The midpoint "・" and double-byte space in the search term will be deleted.
- The maximum number of search result lists is 1000.
     - Can be used as Options for Select (Choice IDs / Display Labels).
     - https://questetra.zendesk.com/hc/en-us/articles/360002260151-M208
- list of Names-Addresses: "{Number}: {Name} ({Address})"
- TSV format: Number, Name, Change Date, Zip, Address, URL, Change Cause (mostly empty)
- This automated step ends with an error in case of no search result.
- 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
- 検索は「部分一致方式」にて「あいまい検索」されます。
    - 検索語で指定した「中点」や「全角スペース」は削除されます。
- 検索結果リストの最大数は1000件です。
    - 選択候補(選択肢ID/表示ラベル)として利用できます。
    - https://questetra.zendesk.com/hc/ja/articles/360002260151-M208
- 法人名称+住所のリスト: "{番号}: {名称} ({所在地})"
- 検索結果TSV: 番号, 名称, 変更年月日, 郵便番号, 所在地, 詳細URL, 変更事由(多くは空)
- 検索結果がゼロ件の場合、この自動処理工程はエラー終了します。
- 日本国の国税庁システム「法人番号 Web-API」(v4)にアクセスします。
    - 国税庁法人番号システムのWeb-API機能を利用して取得した情報をもとに作成されます。
    - Addon の内容が国税庁によって保証されているものではありません。
*/

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAccessKey       = configs.get( "StrConfA" )  + ""; // required
const strSearchTerm      = configs.get( "StrConfB" )  + ""; // required
const strSearchFilter    = configs.get( "StrConfB2" ) + "";
const strPocketFirstNum  = configs.getObject( "SelectConfC1" );
const strPocketFirstName = configs.getObject( "SelectConfC2" );
const strPocketListNums  = configs.getObject( "SelectConfD1" );
const strPocketListNames = configs.getObject( "SelectConfD2" );
const strPocketTsv       = configs.getObject( "SelectConfE" );
if( strAccessKey === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {A:ApplicationId} is empty \n" );
}
if( strSearchTerm === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {B:SearchTerm} is empty \n" );
}
engine.log( " AutomatedTask SearchTerm: " + strSearchTerm );

const japanPrefCodes = {
 "北海道":"01", 
 "青森県":"02","岩手県":"03","宮城県":"04","秋田県":"05","山形県":"06","福島県":"07",
 "茨城県":"08","栃木県":"09","群馬県":"10","埼玉県":"11","千葉県":"12","東京都":"13","神奈川県":"14",
 "新潟県":"15","富山県":"16","石川県":"17","福井県":"18","山梨県":"19","長野県":"20",
 "岐阜県":"21","静岡県":"22","愛知県":"23","三重県":"24",
 "滋賀県":"25","京都府":"26","大阪府":"27","兵庫県":"28","奈良県":"29","和歌山県":"30",
 "鳥取県":"31","島根県":"32","岡山県":"33","広島県":"34","山口県":"35",
 "徳島県":"36","香川県":"37","愛媛県":"38","高知県":"39",
 "福岡県":"40","佐賀県":"41","長崎県":"42","熊本県":"43","大分県":"44","宮崎県":"45","鹿児島県":"46",
 "沖縄県":"47"
};
let strSearchFilterCode = "";
if( strSearchFilter !== "" ){
  if( japanPrefCodes[strSearchFilter] ){
    strSearchFilterCode = japanPrefCodes[strSearchFilter];
  }
}
engine.log( " AutomatedTask SearchFilter: " + strSearchFilter );
engine.log( " AutomatedTask SearchFilterCode: " + strSearchFilterCode );


//// == 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/name";
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.queryParam( "id",     strAccessKey );
    request1 = request1.queryParam( "name",   strSearchTerm );
    request1 = request1.queryParam( "mode",   "2" );  // 検索方式2:部分一致
    request1 = request1.queryParam( "target", "1" );  // 検索対象1:JIS2あいまい
    if( strSearchFilterCode !== "" ){                 // 都道府県フィルタ
      request1 = request1.queryParam( "address", strSearchFilterCode );
    }
    request1 = request1.queryParam( "change", "0" );  // 変更履歴0:なし
    request1 = request1.queryParam( "close",  "1" );  // 登記閉鎖1:含める
    request1 = request1.queryParam( "type",   "12" ); // 応答形式12:XML
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 '" + strSearchTerm + "'\n" );
}
engine.log( " AutomatedTask #ofSearchResult: " + numSearchedCorp );
let numCorpList = numSearchedCorp > 1000 ? 1000 : numSearchedCorp;

/// store into array (Number, Name, Change Date, Zip, Address, Change Cause)
let arrCorps = new Array( numCorpList );
for( let i = 0; i < numCorpList; i++ ){
  let xpathCorp = "/corporations/corporation[" + (i+1) + "]";
  arrCorps[i] = {};
  arrCorps[i].number = xpath.findNodeText( response1Body, xpathCorp + "/corporateNumber" );
  arrCorps[i].name   = xpath.findNodeText( response1Body, xpathCorp + "/name" );
  arrCorps[i].cdate  = xpath.findNodeText( response1Body, xpathCorp + "/changeDate" );
  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 strFirstNum  = arrCorps[0].number;
let strFirstName = arrCorps[0].name;
let strListNums  = "";
let strListNames = "";
let strTsv       = "";
for( let i = 0; i < numCorpList; i++ ){
  strListNums  += arrCorps[i].number;
  strListNames += arrCorps[i].number + ": " +
                  arrCorps[i].name + " (" + arrCorps[i].addr + ")";
  strTsv       += arrCorps[i].number + "\t" +
                  arrCorps[i].name + "\t" +
                  arrCorps[i].cdate + "\t" +
                  arrCorps[i].zip + "\t" +
                  arrCorps[i].addr + "\t" +
                  "https://www.houjin-bangou.nta.go.jp/henkorireki-johoto.html?selHouzinNo=" +
                  arrCorps[i].number + "\t" +
                  arrCorps[i].ccause;
  if( i !== numCorpList - 1 ){
    strListNums  += "\n";
    strListNames += "\n";
    strTsv       += "\n";
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( strPocketFirstNum !== null ){
  engine.setData( strPocketFirstNum, strFirstNum );
}
if( strPocketFirstName !== null ){
  engine.setData( strPocketFirstName, strFirstName );
}
if( strPocketListNums !== null ){
  engine.setData( strPocketListNums, strListNums );
}
if( strPocketListNames !== null ){
  engine.setData( strPocketListNames, strListNames );
}
if( strPocketTsv !== null ){
  engine.setData( strPocketTsv, strTsv );
}

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


/*
APPENDIX
- 応答形式 (&type=12)
    - 01: CSV 形式/Shift‐JIS (JIS 第一・第二水準)
    - 02: CSV 形式/Unicode (JIS 第一水準から第四水準)
    - 12: XML 形式/Unicode (JIS 第一水準から第四水準)
- 検索方式【任意】 (&mode=2)
    - 1: 前方一致 (法人種別を除く必要あり)
    - 2: 部分一致
- 検索対象【任意】 (&target=1)
    - 1: JIS 第一・第二水準 (あいまい検索)中点や全角スペースは補正
    - 2: JIS 第一~第四水準 (完全一致検索)
    - 3: 英語表記 (英語表記登録情報検索)
- 変更履歴要否【任意】 (&history=0)
    - 0: 公表情報の変更履歴なし(リクエスト時点の最新情報のみ応答)
    - 1: 公表情報の変更履歴あり
- 登記記録の閉鎖等【任意】 (&close=1)
    - 0: 登記記録の閉鎖等を含めない。
    - 1: 登記記録の閉鎖等を含める。
- 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-id-with-name/
The Addon-import feature is available with Professional edition.

Notes

  • Searches use the partial match and fuzzy search methods
    • The midpoint “・” and double-byte space in the search term will be deleted
  • The maximum number of search results is 1000
  • List of Names-Addresses: “{Number}: {Name} ({Address})”
  • TSV format: Number, Name, Change Date, Zip, Address, URL, Change Cause (mostly empty)
  • This automated step ends with an error in the event of no search results
  • 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 13-digit identifier with the corporate name, etc., 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

1 thought on “Corp Num Web-API: Organizations, Search ID with Name”

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

Leave a Reply

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

%d bloggers like this: