案例:如何把用户添加至域平台(用接口方式)

注:目前saas版本不支持集成。

以公开环境为例

案例:如何把用户添加至域平台(用接口方式) - 图1

接口网址:https://netease.youdata.163.com/

接口后缀:api/dash/user/batchImport

请求方式:post

提交内容:

字段名称参数类型参数说明
tokenString(Optional)鉴权token,申请人必须是域管理员
userarray用户列表
projectIdInt(Optional)项目ID,可选。默认是系统
groupIdsArray(Optional)用户组ID。可选
defaultPasswordString(Optional)默认密码。可选,不填无法直接登入,单点登入不需要
roleNamesArray(Optional)一级角色。可选,默认根目录一级角色
delRoleNamesArray(Optional)删除一级角色
permissionRoleNamesArray(Optional)指定行权限,可选,默认根目录行级权限
delPermissionRoleNamesArray(Optional)删除行级权限
user列表
emailString(Optional)登入邮箱
phoneString(Optional)手机号码
uniqueIdString唯一字段
passwordString(Optional)登入密码
nickString(Optional)昵称
departmentString(Optional)所属部门
companyString(Optional)所属公司
positionString(Optional)职位
networkConfigObject(Optional)是否允许外网访问,必须部署开启网络限制开关,才会生效
ifLeaveInt(Optional)是否离职。1离职,0在职
attrsArray(Optional)权限属性
attrs列表
attrIdInt属性id
attrNameString属性名称(与attrId任选其一)
attrValueArray或null属性值

示例:

import requests as re
import json


def get_token(host, post_json):
    data = json.dumps(post_json)
    headers = {
        "content-type": "application/json; charset=UTF-8",
        "user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36",
        "x-requested-with": "XMLHttpRequest",
        "accept": "text/plain, */*; q=0.01",
        "accept-encoding": "gzip, deflate, br"
    }
    api_url = 'api/dash/util/genToken'
    if "https://" in host:
        url = host + api_url
    else:
        url = "https://" + host + api_url
    back = json.loads(re.post(url=url, headers=headers, data=data).text)
    return back


# 接口网址
host = 'https://netease.youdata.163.com/'
# 提交内容
post_json = {
    "token": "1620291533326289dcad975f13d149988432e",
    "users": [{
        "email": "zhangsan@test.com",
        "phone": 110,
        "uniqueId": "20",
        "nick": "api测试张三",
        "department": "youdata",
        "networkConfig": {
            "allowExternal": "true"
        },
        "ifLeave": 0,
        "attrs": [
            {
                "attrId": 1,
                "attrValue": ["东北", "܏华北"]
            },
            {
                "attrId": 2,
                "attrValue": ["男"]
            },
            {
                "attrId": 5,
                "attrValue": []
            },
            {
                "attrId": 8,
                "attrValue": "null"
            }
        ]
    }],
    "projectId": "700227416",
    "groupIds": [845],
    "roleNames": ["api测试"],
    "permissionRoleNames": ["api测试"]
}

result = batch_import(host, post_json)
print(result)