Skip to content
Home » API Development Guide

API Development Guide

I. Open API Local Service Development Guide

1.1 API Usage

  • Install and log in to the DICloak browser.
  • Open MoreOpen API – Get Local Interface URL and Key.
  • Obtain sample code and run the script.

1.2 Overview of Interface Usage

  • When the interface request method is POST, the parameter passing method is via the body, passing JSON format data, not form-data, and not URL parameters.
  • The interface returns a JSON object; if code is 0, it indicates success. If there is return data, it will be included in the data object.
  • If code is not 0, it indicates failure, and the failure message will be attached to the msg field.
{
    'code': 0,
    'msg': 'success',
    'data': {
        'serial_number': 2,
        'pid': '27028',
        'debug_port': 17539
    }
}
{
    'code': 500,
    'msg': 'fetch fail'
}
  • All requests must include the request header: X-API-KEY, with the value being the key copied from the DICloak Software.

1.3 Example Code

The Dicloak browser uses the Chrome 120 kernel, so you need to download ChromeDriver first.

import time

import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# port and api key
BASE_URL = "http://127.0.0.1:52140/openapi"
API_KEY = "IvGM26nKG6XoSAtgJ84TAi9jrrwPqY8aWhwyDlY-4opXsqwex-OhLyFYv1e47rR2"

def open_browser(port):
    """
    hold profile
    :param port:
    :return:
    """
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option('debuggerAddress', f"127.0.0.1:{port}")
    s = Service(r"G:\chromedriver.exe")
    browser = webdriver.Chrome(options=chrome_options, service=s)

    browser.get("https://www.zhihu.com")


def get_evn_list():
    headers = {
        "X-API-KEY": API_KEY,
    }

    params = {
        "page_no": 1,
        "page_size": 20
    }

    response = requests.get(f"{BASE_URL}/v1/env/list", params=params, headers=headers)
    return response.json()


def open_env(env_id):
    """
    open profile
    :param env_id:  id
    :return:
    """
    headers = {
        "X-API-KEY": API_KEY,
    }

    response = requests.patch(f"{BASE_URL}/v1/env/{env_id}/open", headers=headers)
    return response.json()


def close_env(env_id):
    """
    close profile
    :param env_id:
    :return:
    """
    headers = {
        "X-API-KEY": API_KEY,
    }

    response = requests.patch(f"{BASE_URL}/v1/env/{env_id}/close", headers=headers)
    return response.json()


if __name__ == '__main__':
    resp = get_evn_list()
    if resp['code'] != 0:
        print(resp.msg)
        exit(0)
    # profile list
    list = resp['data']['list']
    if len(list) == 0:
        print('no profile')
        exit(0)
    print(f"open profile:{list[0]['id']}")

    open_resp = open_env(list[0]['id'])
    if open_resp['code'] != 0:
        print(open_resp['msg'])
        exit(0)

    print(f"open_resp : {open_resp}")

    # Automatic
    open_browser(open_resp['data']['debug_port'])

    time.sleep(3)
    # close profile
    close_env(list[0]['id'])

II. Browser Profile Interface Details

GET Retrieve Browser Profile List

GET /v1/env/{env_id}/open

Request Parameters

NameTypeRequiredDescription
page_nointegerYesPage number, default is 1
page_sizeintegerYesPage size, default is 10
serial_numintegerNoSerial number
namestringNoName
group_idstringNoGroup ID
proxy_hoststringNoProxy host (Method 1)
statusstringNoStatus (DISABLED: Disabled, ENABLED: Normal)
platform_userstringNoPlatform
remarkstringNoRemarks
start_create_timestringNoStart time
end_create_timestringNoEnd time
operate_statusstringNoBrowser profile open status (ENABLED: Open, DISABLED: Closed)
X-API-KEYrequest headerYes

Response Parameters

NameTypeRequiredDescription
idstringYesBrowser Profile ID, env_id
create_timestringNoCreation time
update_timestringNoModification time
serial_numintegerYesSerial number
group_idstringNoGroup ID
group_namestringNoGroup name
namestringYesName
browserstringNoBrowser type (CHROME: Chrome)
ua_typestringNoUA type
uastringNoUser Agent
ua_osstringNoUser Agent OS
cookiestringNoCookie
other_cookiestringNoOther cookie
proxy_waystringNoProxy method (CUSTOM: Custom, SELECT_EXIST: Select Existing)
proxy_idstringNoProxy ID (Method 2)
proxy_typestringNoProxy type (Method 1) (NON_USE: Not used, HTTP, HTTPS, SSH, SOCKS5, IPFLY)
proxy_hoststringNoProxy host (Method 1)
proxy_portinteger (int32)NoProxy port (Method 1)
proxy_user_namestringNoProxy account (Method 1)
proxy_passwdstringNoProxy password (Method 1)
proxy_ip_typestringNoIP query source (Method 1) (IP2LOCATION)
urls[string]NoURL list
configstringNoAdvanced settings JSON
statusstringNoStatus (DISABLED: Disabled, ENABLED: Normal)
remarkstringNoRemarks
last_open_timestringNoLast opened time
operate_statusstringNoOperation status (DISABLED: Closed, ENABLED: Enabled, LOCK: Locked)
account_list[object]NoAccount
font_idstringNoFont ID
data_configstringNoData configuration
browser_configstringNoBrowser configuration
env_mutil_open_typestringNoBrowser profile multi-opening: GLOBAL: Global, ALLOW: Allow, BAN: Ban
operate_members[object]NoCurrent browser profile operator information
config_ext_mapobjectNoExtended fields
totalinteger (int32)YesTotal count

Response Example

{
    "code": 0,
    "msg": "success",
    "data": {
        "list": [
            {
                "id": "1848687666096832515",
                "create_time": "2024-10-22 19:27:41",
                "update_time": "2024-10-23 21:28:15",
                "serial_num": 166,
                "group_id": "1776895967565094913",
                "group_name": null,
                "name": "导入-账户-copy166-20241022192741216",
                "browser": "CHROME",
                "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6005.0 Safari/537.36",
                "ua_os": "MAC",
                "cookie": "",
                "other_cookie": null,
                "urls": [],
                "status": "ENABLED",
                "remark": null,
                "last_open_time": "2024-10-23 21:26:15",
                "operate_status": "DISABLED",
                "account_list": null,
                "font_id": "",
                "data_config": "{\"type\":25,\"dataType\":\"custom\"}",
                "browser_config": "{\"type\":1,\"browserType\":\"custom\"}",
                "env_mutil_open_type": "GLOBAL",
                "config_ext_map": null
            }
        ],
        "total": 65
    }
}

PATCH Open Browser Profile

PATCH /v1/env/{env_id}/open

Request Parameters

NameTypeRequiredDescription
env_idstringYesBrowser profile ID, corresponding to the id in the list.

Response Parameters

NameTypeRequiredDescription
serial_numberinteger (int32)YesBrowser profile serial number
pidstringYesBrowser profile process ID
debug_portintegerYesBrowser profile port

Response Example

{
    'code': 0,
    'msg': 'success',
    'data': {
        'serial_number': 2,
        'pid': '27028',
        'debug_port': 17539
    }
}

PATCH Close Browser Profile

PATCH /v1/env/{env_id}/close

Request Parameters

NameTypeRequiredDescription
env_idstringYesBrowser profile ID, corresponding to the id in the list.

Response Parameters

NameTypeRequiredDescription
serial_numberinteger (int32)YesBrowser profile serial number
pidstringYesBrowser profile process ID
debug_portintegerYesBrowser profile port

Response Example

{
    'code': 0,
    'msg': 'success'
}