案例:如何把用户添加至域平台(用接口方式)
更新时间: 2022-07-22 14:18:13
阅读 1790
案例:如何把用户添加至域平台(用接口方式)
注:目前saas版本不支持集成。
以公开环境为例
接口网址:https://netease.youdata.163.com/
接口后缀:api/dash/user/batchImport
请求方式:post
提交内容:
字段名称 | 参数类型 | 参数说明 |
token | String(Optional) | 鉴权token,申请人必须是域管理员 |
user | array | 用户列表 |
projectId | Int(Optional) | 项目ID,可选。默认是系统 |
groupIds | Array(Optional) | 用户组ID。可选 |
defaultPassword | String(Optional) | 默认密码。可选,不填无法直接登入,单点登入不需要 |
roleNames | Array(Optional) | 一级角色。可选,默认根目录一级角色 |
delRoleNames | Array(Optional) | 删除一级角色 |
permissionRoleNames | Array(Optional) | 指定行权限,可选,默认根目录行级权限 |
delPermissionRoleNames | Array(Optional) | 删除行级权限 |
user列表 | ||
String(Optional) | 登入邮箱 | |
phone | String(Optional) | 手机号码 |
uniqueId | String | 唯一字段 |
password | String(Optional) | 登入密码 |
nick | String(Optional) | 昵称 |
department | String(Optional) | 所属部门 |
company | String(Optional) | 所属公司 |
position | String(Optional) | 职位 |
networkConfig | Object(Optional) | 是否允许外网访问,必须部署开启网络限制开关,才会生效 |
ifLeave | Int(Optional) | 是否离职。1离职,0在职 |
attrs | Array(Optional) | 权限属性 |
attrs列表 | ||
attrId | Int | 属性id |
attrName | String | 属性名称(与attrId任选其一) |
attrValue | Array或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)
文档反馈
以上内容对您是否有帮助?