Skip to content

部门列表

接口信息

  • 接口: /agent-api/user/{user_id}/department
  • 请求方式: GET

路由参数

参数类型示例解释必填
user_idstring5433b412-07d5-44e6-9fa4-deb65e43bc93用户 id

请求参数

参数类型示例解释必填
pageint1页码

请求示例

cURL
curl -X GET "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/department?page=1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"
Go
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/department?page=1"

    req, _ := http.NewRequest("GET", url, nil)
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", "Bearer YOUR_TOKEN")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
JavaScript
const userId = "5433b412-07d5-44e6-9fa4-deb65e43bc93";
const url = `https://ai.api.longlonglong.cn/agent-api/user/${userId}/department?page=1`;

fetch(url, {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN"
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));
Java
import java.net.URI;
import java.net.http.*;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/department?page=1"))
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer YOUR_TOKEN")
            .GET()
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/department?page=1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Content-Type: application/json",
        "Authorization: Bearer YOUR_TOKEN"
    ],
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;
Python
import requests

user_id = "5433b412-07d5-44e6-9fa4-deb65e43bc93"
url = f"https://ai.api.longlonglong.cn/agent-api/user/{user_id}/department"

params = {
    "page": 1
}

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN"
}

response = requests.get(url, params=params, headers=headers)

print(response.json())
C++
#include <iostream>
#include <curl/curl.h>

size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main() {
    CURL* curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if(curl) {
        struct curl_slist* headers = NULL;
        headers = curl_slist_append(headers, "Content-Type: application/json");
        headers = curl_slist_append(headers, "Authorization: Bearer YOUR_TOKEN");

        curl_easy_setopt(curl, CURLOPT_URL, "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/department?page=1");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        else
            std::cout << readBuffer << std::endl;

        curl_easy_cleanup(curl);
    }
    return 0;
}

返回示例

json
{
    "code": 200,
    "status": "success",
    "message": "查看部门列表成功",
    "data": [
        {
            "id": 10007,
            "pid": 0,
            "name": "测试",
            "user_id": "e8cca468-33c6-4885-aa4f-a400a022641a",
            "description": null,
            "sort": 0,
            "depth": 1,
            "path": "0",
            "number": null,
            "status": true,
            "deleted_at": null,
            "created_at": "2023-02-16 19:04:53",
            "updated_at": "2023-02-16 19:04:53",
            "leader_members": [],
            "parent": null,
            "members": [
                {
                    "type": 8,
                    "id": "fba145ab-6a10-445a-b04f-043a7b50a685",
                    "name": "测试3",
                    "email": "1232131331231@telrobot.net",
                    "phone": "12313132133",
                    "type_note": "子账户",
                    "pivot": {
                        "department_id": 10007,
                        "user_id": "fba125ab-6a00-445a-b04f-043a7b50a685",
                        "is_leader": 0,
                        "created_at": "2023-03-27 11:49:30",
                        "updated_at": "2023-03-27 11:49:30"
                    }
                }
            ]
        }
    ]
}

字段说明

字段说明
id部门ID
pid上级部门ID
name部门名称
user_id所属用户ID
depth部门层级深度
path部门路径
parent上级部门信息
members部门成员列表

基于 MIT 许可发布