Files
CKB-Interface/application/store/move_to_agent_folder.py
2026-03-24 10:39:16 +08:00

70 lines
1.9 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""移动Agent接口到指定目录"""
import sys
import requests
sys.stdout.reconfigure(encoding='utf-8')
TOKEN = "afxp_fa4137GfIzJtlOCeQHjpCXc83SFWmeAOrZnq"
PROJECT_ID = "6037107"
AGENT_API_IDS = [415861964, 415861967]
headers = {
"X-Apifox-Api-Version": "2024-03-28",
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json; charset=utf-8"
}
print("=" * 80)
print("移动Agent接口到Agent管理目录")
print("=" * 80)
if len(sys.argv) < 2:
print("\n用法: python move_to_agent_folder.py <Agent管理目录ID>")
print("\n步骤:")
print("1. 在Apifox中创建'Agent管理'目录(在'门店端-新版'下)")
print("2. 右键'Agent管理'目录 → 查看目录ID")
print("3. 运行: python move_to_agent_folder.py <目录ID>")
sys.exit(1)
folder_id = sys.argv[1]
print(f"\n目标目录ID: {folder_id}")
print("-" * 80)
success = 0
failed = 0
for i, api_id in enumerate(AGENT_API_IDS, 1):
print(f"\n[{i}/{len(AGENT_API_IDS)}] 移动接口 {api_id}...")
try:
response = requests.patch(
f"https://api.apifox.com/api/v1/projects/{PROJECT_ID}/http-apis/{api_id}",
headers=headers,
json={"folderId": int(folder_id)}
)
if response.status_code == 200:
result = response.json()
if result.get('success'):
success += 1
print(f" ✓ 成功")
else:
failed += 1
print(f" ✗ 失败: {result.get('errorMessage')}")
else:
failed += 1
print(f" ✗ HTTP {response.status_code}")
except Exception as e:
failed += 1
print(f" ✗ 异常: {e}")
print("\n" + "=" * 80)
print(f"完成!成功: {success}, 失败: {failed}")
print("=" * 80)
if success > 0:
print(f"\n✨ 查看结果: https://app.apifox.com/project/{PROJECT_ID}")