第三方部门同步 API

接口路径

POST /third_api/update/code

接口描述

用于第三方修改部门相关信息。

请求参数

  • key :字符串类型,必填。用于验证身份的密钥。
  • dept_list :数组类型,必填。包含多个部门信息的对象数组,每个对象包含以下字段:
    • dept_code :字符串类型,部门代码。
    • dept_name :字符串类型,部门名称。

调用示例

请求代码(Python)

import requests
import json

url = "http://your-domain/third_api/update/code"
data = {
    "key": "your_real_key",
    "dept_list": [
        {
            "dept_code": "001",
            "dept_name": "更新后的部门名称 1"
        },
        {
            "dept_code": "002",
            "dept_name": "新的部门名称 2"
        }
    ]
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.json())

请求代码(JavaScript - Axios)

import axios from 'axios';

const url = 'http://your-domain/third_api/update/code';
const data = {
    key: 'your_real_key',
    dept_list: [
        {
            dept_code: '001',
            dept_name: '更新后的部门名称 1'
        },
        {
            dept_code: '002',
            dept_name: '新的部门名称 2'
        }
    ]
};

axios.post(url, data)
    .then(response => {
        console.log(response.data);
    })
    .catch(error => {
        console.error(error);
    });

返回结果

成功返回

{
    "code": 200,
    "message": "Success",
    "data": null
}

密钥错误返回

{
    "detail": "密钥错误"
}

备注

  • 该接口会先验证传入的密钥是否正确,若密钥错误则返回 500 状态码及相应错误信息。
  • 对于 dept_list 中的部门,若其 dept_code 已存在,则更新对应的部门名称;若不存在,则创建新的部门。