IP2WHOIS #Domain-WHOIS-API: Obtain Domain-Info

IP2WHOIS #Domain-WHOIS-API: Obtain Domain-Info

translate IP2WHOIS #Domain-WHOIS-API: ドメイン情報を取得

Obtains domain information (WHOIS records: “Registered Domain Name” and “Domain Age”) from domain names including subdomains. An error is returned if the domain is not registered. The free API license is limited to a maximum of 500 queries per month.

Auto Step icon
Configs for this Auto Step
AuthzConfU
U: Select HTTP_Authz Setting for API LICENSE KEY (Fixed Value) *
StrConfA
A: Set Domain (eg: “example.com”, “https://sub.example.jp”) *#{EL}
SelectConfB1
B1: Select DATA to store Registered Domain Name (update)
SelectConfB2
B2: Select DATA to store Domain Name Age in Days (update)
SelectConfX
X: Select DATA to store Response JSON (update)
Script (click to open)
// Script Example of Business Process Automation
// for 'engine type: 3' ("GraalJS standard mode")
// cf. 'engine type: 2' ("GraalJS Nashorn compatible mode") (renamed from "GraalJS" at 20230526)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

////// == Config Retrieving / 工程コンフィグの参照 ==
const authApiKey                = configs.getObject( "AuthzConfU" );     /// REQUIRED
const strApiKey                 = authApiKey.getToken();
//  engine.log( " AutomatedTask Config: ApiKey: " + strApiKey );

const strDomainName             = configs.get      ( "StrConfA" );       /// REQUIRED
  if( strDomainName === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: DomainName} is empty \n" );
  }
  let strDomainExtracted        = extractLooseDomain( strDomainName );
  if (strDomainExtracted === null) {
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Could not extract domain from Config {A: DomainName} \n");
  }
const strPocketRegisteredDomain = configs.getObject( "SelectConfB1" );   // not required
const numPocketAgeInDays        = configs.getObject( "SelectConfB2" );   // not required
const strPocketResponseJson     = configs.getObject( "SelectConfX" );    // not required



////// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)



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

//// Domain WHOIS REST API > WHOIS lookup REST API
//// https://www.ip2whois.com/developers-api
//// https://www.ip2location.io/ip2whois-documentation

/// request1, prepare
let request1Uri = "https://api.ip2whois.com/v2";
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.queryParam( "key", strApiKey ); 
    request1 = request1.queryParam( "domain", strDomainExtracted ); 

/// request1, try
const response1     = request1.get( request1Uri );     // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";  // JavaNum to string
const response1Body = response1.getResponseAsString();
engine.log( " AutomatedTask ApiResponse1 Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
// engine.log( response1Body ); // debug
/* response sample
{
  "domain": "google.com",
  "domain_id": "2138514_DOMAIN_COM-VRSN",
  "status": "clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited)",
  "create_date": "1997-09-15T07:00:00+0000",
  "update_date": "2024-08-02T02:17:33+0000",
  "expire_date": "2028-09-13T07:00:00+0000",
  "domain_age": 10179,
  "whois_server": "whois.markmonitor.com",
  "registrar": { ... },
  "registrant": { ... },
  "admin": { ... },
  "tech": { ... },
  "billing": { ... },
  "nameservers: [
    "ns4.google.com",
    "ns1.google.com",
    "ns2.google.com",
    "ns3.google.com"
  ]
}
*/

// response1, parse
const response1Obj = JSON.parse( response1Body );


////// == Data Updating / ワークフローデータへの代入 ==
if( strPocketRegisteredDomain !== null ){
  engine.setData( strPocketRegisteredDomain, response1Obj.domain  );
}
if( numPocketAgeInDays !== null ){
  engine.setData( numPocketAgeInDays, new java.math.BigDecimal(response1Obj.domain_age)  );
}
if( strPocketResponseJson !== null ){
  engine.setData( strPocketResponseJson, response1Body  );
}


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


/**
 * From the given text, extract the first domain string (a string that looks like a domain, including subdomains).
 *
 * @param {string} text - The string from which you want to extract the domain.
 * @returns {string|null} - Returns the first domain string found, or null if there is no match.
 *
 * @example
 * // Basic Domain Extraction
 * extractLooseDomain("My website is example.com."); // 'example.com'
 *
 * @example
 * // Extracts a domain, including subdomains.
 * extractLooseDomain("My website is example.com."); // 'sub.domain.co.jp' Returns a domain name.
 *
 * @example
 * // Extracting domains included as part of a URL
 * extractLooseDomain("The URL is https://www.google.com/search?q=test."); // 'www.google.com' Returns the domain.
 *
 * @example
 * // Returns a Punycode-formatted domain extract.
 * extractLooseDomain("Punycode domain: xn--abc-xyz.jp."); // 'xn--abc-xyz.jp' 
 *
 * @example
 * // Returns null if the domain is not found
 * extractLooseDomain("It is a sentence without a domain."); //
 */
function extractLooseDomain(text) {
  const emailMatch = text.match(/[a-zA-Z0-9._%+-]+@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/);
  if (emailMatch) {
    return emailMatch[1]; // @の右側のドメイン部を返す
  }

  // A regular expression that extracts "domain-like strings" including subdomains.
  // It supports TLD length, hyphens, numbers, Punycode format, and is case-insensitive.
  const domainRegex = /(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{2,20}|xn--[a-zA-Z0-9]{1,61})(?:\.[a-zA-Z]{2})?/i;
  
  const match = text.match(domainRegex);

  if (match) {
    return match[0]; // Returns the entire matched string (domain part)
  }

  return null; // If there is no match, returns null
}




/*
Notes:
- By placing this [Automated Step] in the workflow diagram, the API request will occur every time a process arrives.
    - A request is made from the Questetra BPM Suite server to the IP2WHOIS server.
- This [Automated Step] obtains the Domain Information via IP2WHOIS API.
    - Registered domain name (officially registered and available for use)
    - Number of days since the domain was created
    - The full JSON response can be stored as a string.
- [HTTP Authz Settings] is required for workflow apps that include this [Automated Step].
    - An API key is required to use IP2WHOIS API. Please obtain an API key in advance.
        - `https://www.ip2location.io/dashboard`
    - Set 'Secret API Key' as the communication token. [HTTP Authz Settings] > [Token Fixed Value]

APPENDIX
- The queries for 1221 TLDs and 634 ccTLDs are supported. (by IP2WHOIS as of 202507)
- Matches domain names in the format 'example.com' or 'subdomain.example.co.jp'.
    - output: `example.com`
    - output: `subdomain.example.co.jp`
- Extracts the registered domain portion even from strings like 'http://example.com/.' or 'suzuki@subdomain.example.co.jp'.
    - output: `example.com`
    - output: `subdomain.example.co.jp`

Notes-ja:
- この[自動工程]をワークフロー図に配置すれば、案件が到達するたびにAPIリクエストが発生します。
    - Questetra BPM Suite サーバから IP2WHOIS サーバに対してリクエストします。
- この[自動工程]は、IP2WHOIS API を通じて、ドメイン情報を取得します。
    - 登録済みドメイン名(正式に登録され利用可能な状態になっているドメイン)
    - ドメインが生成されてからの日数
    - JSON response の全文も格納可能です。
- この[自動工程]を含むワークフローアプリには、[HTTP 認証設定]が必要です。
    - IP2WHOIS API の利用には API key が必要です。あらかじめ API Key を取得しておいてください。
        - `https://www.ip2location.io/dashboard`
    - 'Secret API Key' を通信トークンとしてセットします。[HTTP 認証設定]>[トークン直接指定]

APPENDIX-ja
- 1221のTLDと634のccTLDのクエリをサポートしています。 (by IP2WHOIS as of 202507)
- 'example.com' や 'subdomain.example.co.jp' のような形式のドメイン名にマッチします。
    - output: `example.com`
    - output: `subdomain.example.co.jp`
- 'http://example.com/.' や 'suzuki@subdomain.example.co.jp' のような文字列でも登録ドメイン部を抽出します。
    - output: `example.com`
    - output: `subdomain.example.co.jp`
*/

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • By placing this [Automated Step] in the workflow diagram, the API request will occur every time a process arrives.
    • A request is made from the Questetra BPM Suite server to the IP2WHOIS server.
  • This [Automated Step] obtains the Domain Information via IP2WHOIS API.
    • Registered domain name (officially registered and available for use)
    • Number of days since the domain was created
    • The full JSON response can be stored as a string.
  • [HTTP Authz Settings] is required for workflow apps that include this [Automated Step].
    • An API key is required to use IP2WHOIS API. Please obtain an API key in advance.
      • https://www.ip2location.io/dashboard
    • Set ‘Secret API Key’ as the communication token. [HTTP Authz Settings] > [Token Fixed Value]

Capture

Appendix

  • The queries for 1221 TLDs and 634 ccTLDs are supported. (by IP2WHOIS as of 202507)
  • Matches domain names in the format ‘example.com’ or ‘subdomain.example.co.jp’.
    • output: example.com
  • Extracts the registered domain portion even from strings like `http://example.com/.` or `suzuki@subdomain.example.co.jp`.
    • output: example.com

See Also

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading