Quick start with client library

Catalog


Node.js

npm init
npm install idanalyzer2

Add "type": "module" to package.json under the folder. Full content below:

//package.json

{
  "name": "js",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "type": "module",
  "dependencies": {
    "idanalyzer2": "^1.0.2"
  }
}

Create a index.js. Full content below:

Change 05.png to the file name of the image you wish to scan.

Obtain the API Key from Portal2 backend and replace the Scanner constructor parameter.

import IdAnalyzer from "idanalyzer2"
let {Profile, Scanner, SetEndpoint, APIError, InvalidArgumentException} = IdAnalyzer
import fs from "node:fs/promises"

let scanDemo = async () => {
    try {
        // create profile
        let profile = new Profile(Profile.SECURITY_MEDIUM)
        
        // create a Scanner (P.S. Get Api key from)
        let s = new Scanner('Your API Key from portal2')
        
        // throw exception
        s.throwApiException(true)
      
        // use quickScan to scan image (change 05.png to your image filenam
        let quickResult = await s.quickScan("05.png", "", true)
        
        // write out result
        await fs.writeFile("./quickscan.json", JSON.stringify(quickResult))
        
        // Set the profile into the Scanner
        s.setProfile(profile)
        
      	// use standard Scan to scan image (change 05.png to your image filename)
        let scanResult = await s.scan("05.png")
        
        // write out result
        await fs.writeFile("./scan.json", JSON.stringify(scanResult))
    } catch (e) {
        if(e instanceof InvalidArgumentException) {
            console.log("InvalidArgumentException => ", e.message)
        } else if(e instanceof APIError) {
            console.log("APIError => ", e.code, e.msg)
        } else {
            console.log("unknown error => ", e.message)
        }
    }
}

scanDemo()

Then execute the command below:

node index.js

If the execution was correct, there will be two files "quickscan.json" and "scan.json" under the catalog. They are the scanning results of quickScan and Scan.


Python

pip install idanalyzer2
pip install validators

Create a main.py file. Content as below:

Change 05.png to the file name of the image you wish to scan.

Obtain the API Key from Portal2 backend and replace the Scanner constructor parameter.

from idanalyzer2 import *
import traceback
import json


try:
    # create profile
    profile = Profile(Profile.SECURITY_MEDIUM)
    
    # create a Scanner (P.S. Get Api key from)
    s = Scanner('Your API Key from portal2')
    
    # throw exception
    s.throwApiException(True)
    
    # use quickScan to scan image (change 05.png to your image filenam
    resp = s.quickScan('05.png', "", True)
    
    # write out result
    with open('quickScan.json', 'w') as f:
        f.write(json.dumps(resp, indent=4))
        
    # Set the profile into the Scanner
    s.setProfile(profile)
    
    # use standard Scan to scan image (change 05.png to your image filename)
    resp = s.scan("05.png")
    
    # write out result
    with open('scan.json', 'w') as f:
        f.write(json.dumps(resp, indent=4))
        
except APIError as e:
    print(traceback.format_exc())
    print(e.args[0])
except InvalidArgumentException as e:
    print(traceback.format_exc())
    print(e.args[0])
except Exception as e:
    print(traceback.format_exc())
    print(e.args[0])

Then execute the command below:

python main.py

If the execution was correct, there will be two files "quickscan.json" and "scan.json" under the catalog. They are the scanning results of quickScan and Scan.


PHP

Create a Composer project.

composer init
// Press Enter until it's done.

composer install

Next, install the idanalyzer-v2 PHP SDK.

composer require idanalyzer/id-analyzer-v2-php-sdk

After completing the command operations, here is the directory structure:

\src
\vendor
composer.json
composer.lock

Copy the entire example folder over.

For example, if you want to test the Scan function, copy the entire Scan folder over.

And name the image to be scanned as 1.jpg and place it under the directory.

As follows ↓

\src
  \Scan
    QuickScan.php
    StdScan.php
\vendor
1.jpg
composer.json
composer.lock

Open QuickScan.php or Scan.php to update the API key. (Get API Key from here)

After executing the following command, you will see the result's JSON file written in

php src/Scan/StdScan.php

CSharp (C#)

Refer to C# client library section for examples