Skip to content

数据转发

概述

数据转发功能支持两种方式:PostData(通过webhook发送到外部系统)和MongoDB存储。

PostData配置

获取PostData配置

http
GET /api/v2/post-data/

接口说明

获取当前组织的PostData配置信息。

响应

返回数据 (200 OK)

json
{
    "success": true,
    "data": {
        "url": "https://example.com/webhook",
        "secret_key": "your-secret-key",
        "enabled": true
    },
    "error": null
}

代码示例

Python
python
def get_post_data_config():
    """获取PostData配置
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}"
    }
    
    url = f"{API_BASE}/post-data/"
    response = requests.get(url, headers=headers)
    return response.json()

# 使用示例
config = get_post_data_config()
if config['success']:
    print(f"PostData URL: {config['data']['url']}")
    print(f"是否启用: {'是' if config['data']['enabled'] else '否'}")
cURL
bash
curl -X GET "https://ums.holdingbyte.com/api/v2/post-data/" \
     -H "Authorization: Bearer your_access_token"

保存PostData配置

http
POST /api/v2/post-data/save/

接口说明

创建或更新PostData配置。

请求参数

参数类型必填说明
urlstringwebhook接收数据的URL
secret_keystring用于签名验证的密钥
enabledboolean是否启用,默认false

请求示例

请求数据

json
{
    "url": "https://example.com/webhook",
    "secret_key": "your-secret-key",
    "enabled": true
}

响应

返回数据 (200 OK)

json
{
    "success": true,
    "data": {
        "url": "https://example.com/webhook",
        "secret_key": "your-secret-key",
        "enabled": true
    },
    "error": null
}

代码示例

Python
python
def save_post_data_config(url, secret_key=None, enabled=False):
    """保存PostData配置
    
    Args:
        url: webhook接收数据的URL
        secret_key: 用于签名验证的密钥,不传则使用现有密钥
        enabled: 是否启用
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    
    data = {
        "url": url,
        "enabled": enabled
    }
    
    if secret_key:
        data["secret_key"] = secret_key
    
    url = f"{API_BASE}/post-data/save/"
    response = requests.post(url, headers=headers, json=data)
    return response.json()

# 使用示例
result = save_post_data_config(
    url="https://example.com/webhook",
    secret_key="my-secret-key",
    enabled=True
)
print(f"配置保存{'成功' if result['success'] else '失败'}")
cURL
bash
curl -X POST "https://ums.holdingbyte.com/api/v2/post-data/save/" \
     -H "Authorization: Bearer your_access_token" \
     -H "Content-Type: application/json" \
     -d '{
         "url": "https://example.com/webhook",
         "secret_key": "your-secret-key",
         "enabled": true
     }'

重置密钥

http
POST /api/v2/post-data/reset-secret-key/

接口说明

重置PostData的secret key。

响应

返回数据 (200 OK)

json
{
    "success": true,
    "data": {
        "url": "https://example.com/webhook",
        "secret_key": "new-generated-secret-key",
        "enabled": true
    },
    "error": null
}

代码示例

Python
python
def reset_post_data_secret_key():
    """重置PostData密钥
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}"
    }
    
    url = f"{API_BASE}/post-data/reset-secret-key/"
    response = requests.post(url, headers=headers)
    return response.json()

# 使用示例
result = reset_post_data_secret_key()
if result['success']:
    print(f"新的密钥: {result['data']['secret_key']}")
cURL
bash
curl -X POST "https://ums.holdingbyte.com/api/v2/post-data/reset-secret-key/" \
     -H "Authorization: Bearer your_access_token"

测试PostData

http
POST /api/v2/post-data/test/

接口说明

测试PostData配置是否可用。

请求参数

参数类型必填说明
urlstring要测试的URL,不填则使用已保存的配置
secret_keystring要测试的密钥,不填则使用已保存的配置

请求示例

请求数据

json
{
    "url": "https://example.com/webhook",
    "secret_key": "test-secret-key"
}

响应

返回数据 (200 OK)

json
{
    "success": true
}

代码示例

Python
python
def test_post_data(url=None, secret_key=None):
    """测试PostData配置
    
    Args:
        url: 要测试的URL,不填则使用已保存的配置
        secret_key: 要测试的密钥,不填则使用已保存的配置
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    
    data = {}
    if url:
        data["url"] = url
    if secret_key:
        data["secret_key"] = secret_key
    
    url = f"{API_BASE}/post-data/test/"
    response = requests.post(url, headers=headers, json=data)
    return response.json()

# 使用示例
test_result = test_post_data(
    url="https://example.com/webhook",
    secret_key="test-secret-key"
)
print(f"测试{'成功' if test_result['success'] else '失败'}")
cURL
bash
curl -X POST "https://ums.holdingbyte.com/api/v2/post-data/test/" \
     -H "Authorization: Bearer your_access_token" \
     -H "Content-Type: application/json" \
     -d '{
         "url": "https://example.com/webhook",
         "secret_key": "test-secret-key"
     }'

MongoDB配置

获取MongoDB配置

http
GET /api/v2/save-to-mongodb/

接口说明

获取当前组织的MongoDB配置信息。

响应

返回数据 (200 OK)

json
{
    "success": true,
    "data": {
        "uri": "mongodb://username:password@host:port/database",
        "collection": "collection_name",
        "enabled": true
    },
    "error": null
}

代码示例

Python
python
def get_mongodb_config():
    """获取MongoDB配置
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}"
    }
    
    url = f"{API_BASE}/save-to-mongodb/"
    response = requests.get(url, headers=headers)
    return response.json()

# 使用示例
config = get_mongodb_config()
if config['success']:
    print(f"MongoDB URI: {config['data']['uri']}")
    print(f"集合名称: {config['data']['collection']}")
    print(f"是否启用: {'是' if config['data']['enabled'] else '否'}")
cURL
bash
curl -X GET "https://ums.holdingbyte.com/api/v2/save-to-mongodb/" \
     -H "Authorization: Bearer your_access_token"

保存MongoDB配置

http
POST /api/v2/save-to-mongodb/save/

接口说明

创建或更新MongoDB配置。

请求参数

参数类型必填说明
uristringMongoDB连接URI
collectionstring集合名称
enabledboolean是否启用,默认false

请求示例

请求数据

json
{
    "uri": "mongodb://username:password@host:port/database",
    "collection": "collection_name",
    "enabled": true
}

响应

返回数据 (200 OK)

json
{
    "success": true,
    "data": {
        "uri": "mongodb://username:password@host:port/database",
        "collection": "collection_name",
        "enabled": true
    },
    "error": null
}

代码示例

Python
python
def save_mongodb_config(uri, collection, enabled=False):
    """保存MongoDB配置
    
    Args:
        uri: MongoDB连接URI
        collection: 集合名称
        enabled: 是否启用
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    
    data = {
        "uri": uri,
        "collection": collection,
        "enabled": enabled
    }
    
    url = f"{API_BASE}/save-to-mongodb/save/"
    response = requests.post(url, headers=headers, json=data)
    return response.json()

# 使用示例
result = save_mongodb_config(
    uri="mongodb://username:password@host:port/database",
    collection="data_collection",
    enabled=True
)
print(f"配置保存{'成功' if result['success'] else '失败'}")
cURL
bash
curl -X POST "https://ums.holdingbyte.com/api/v2/save-to-mongodb/save/" \
     -H "Authorization: Bearer your_access_token" \
     -H "Content-Type: application/json" \
     -d '{
         "uri": "mongodb://username:password@host:port/database",
         "collection": "collection_name",
         "enabled": true
     }'