### Python SDK Example for Listing Feishu Applications Source: https://github.com/ichendev/feishu-server-api/blob/main/应用信息/应用管理/获取企业安装的应用.md Demonstrates how to use the Feishu Python SDK to list installed enterprise applications. Includes client setup, request construction with various parameters, and response handling. ```Python import json import lark_oapi as lark from lark_oapi.api.application.v6 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: ListApplicationRequest = ListApplicationRequest.builder() \ .page_size(50) \ .page_token("AQD9/Rn9eij9Pm39ED40/dk53s4Ebp882DYfFaPFbz00L4CMZJrqGdzNyc8BcZtDbwVUvRmQTvyMYicnGWrde9X56TgdBuS+JKiSIkdexPw=") \ .user_id_type("open_id") \ .lang("zh_cn") \ .status(0) \ .payment_type(0) \ .owner_type(0) \ .build() # 发起请求 response: ListApplicationResponse = client.application.v6.application.list(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.application.v6.application.list failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Feishu Python SDK Setup Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/候选人管理/人才/创建人才.md This section provides instructions and an example import statement for using the Feishu Python SDK. It guides developers on how to prepare for development with the SDK, referencing official documentation for detailed setup. ```python import json import lark_oapi as lark from lark_oapi.api.hire.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Feishu SDK Preparation (Python) Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/候选人管理/投递流程/Offer/获取 Offer 详情.md Provides setup instructions and a placeholder for using the Feishu Python SDK to interact with the hire API. It highlights the need to replace placeholders with actual application credentials. ```python import json import lark_oapi as lark from lark_oapi.api.hire.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Get Message Resource - Python SDK Example Source: https://github.com/ichendev/feishu-server-api/blob/main/消息/消息管理/获取消息中的资源文件.md Example demonstrating how to use the Python SDK to retrieve a resource file from a Feishu message. Includes necessary imports and setup. ```python import json import lark_oapi as lark from lark_oapi.api.im.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Start Helpdesk Service with Golang SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/工单/工单管理/创建服务台对话.md Example of initiating a helpdesk conversation using the Feishu Golang SDK. This snippet demonstrates how to construct the request with user and service details and handle the API response. ```Go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/helpdesk/v1" ) func main() { client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") req := larkhelpdesk.NewStartServiceTicketReqBuilder(). Body(larkhelpdesk.NewStartServiceTicketReqBodyBuilder(). HumanService(false). AppointedAgents([]string{`ou_7dab8a3d3cdcc9da365777c7ad535d62`}). OpenId(`ou_7dab8a3d3cdcc9da365777c7ad535d62`). CustomizedInfo(`测试自定义字段信息`). Build()). Build() resp, err := client.Helpdesk.V1.Ticket.StartService(context.Background(), req) if err != nil { fmt.Println(err) return } if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Start Helpdesk Service with Python SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/工单/工单管理/创建服务台对话.md Demonstrates how to use the Feishu Python SDK to create a helpdesk conversation. This example covers setting up the client, constructing the request body with necessary parameters, and processing the response. ```Python import json import lark_oapi as lark from lark_oapi.api.helpdesk.v1 import * def main(): client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() request: StartServiceTicketRequest = StartServiceTicketRequest.builder() \ .request_body(StartServiceTicketRequestBody.builder() .human_service(False) .appointed_agents(["ou_7dab8a3d3cdcc9da365777c7ad535d62"]) .open_id("ou_7dab8a3d3cdcc9da365777c7ad535d62") .customized_info("测试自定义字段信息") .build()) .build() response: StartServiceTicketResponse = client.helpdesk.v1.ticket.start_service(request) if not response.success(): lark.logger.error( f"client.helpdesk.v1.ticket.start_service failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Get User Flow - Python SDK Example Source: https://github.com/ichendev/feishu-server-api/blob/main/考勤打卡/打卡信息管理/查询打卡流水.md Example of how to use the Feishu Python SDK to retrieve a user flow record. Refer to the SDK documentation for setup and usage details. ```Python import json import lark_oapi as lark from lark_oapi.api.attendance.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Get Resume Sources (Golang SDK) Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/候选人管理/简历来源/获取简历来源列表.md Example of using the Feishu Open Platform Golang SDK to list resume sources. Shows client initialization, request building, and response handling. ```Golang package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/hire/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkhire.NewListResumeSourceReqBuilder(). PageSize(10). PageToken(`"6794694704606185741"`). Build() // 发起请求 resp, err := client.Hire.V1.ResumeSource.List(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Get Record Details - Python SDK Example Source: https://github.com/ichendev/feishu-server-api/blob/main/飞书低代码平台/对象/获取记录详情.md Example demonstrating how to retrieve record details using the Feishu Python SDK. Covers client setup, request object construction with necessary parameters, and response processing. ```Python import json import lark_oapi as lark from lark_oapi.api.apaas.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: QueryApplicationObjectRecordRequest = QueryApplicationObjectRecordRequest.builder() \ .namespace("package_test__c") \ .object_api_name("user") \ .id("1764024447556775") \ .request_body(QueryApplicationObjectRecordRequestBody.builder() .select(["_id"]) .build()) .build() # 发起请求 response: QueryApplicationObjectRecordResponse = client.apaas.v1.application_object_record.query(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.apaas.v1.application_object_record.query failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Complete PreHire with Golang SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/飞书人事(企业版)/入职/操作员工完成入职.md Provides an example of completing a pre-hire using the official Feishu Golang SDK. It includes client initialization, request building, and response handling, with instructions for replacing placeholders. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/corehr/v2" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkcorehr.NewCompletePreHireReqBuilder(). PreHireId(`7345005664477775407`). Build() // 发起请求 resp, err := client.Corehr.V2.PreHire.Complete(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Feishu Task Activity Subscription Example (Go) Source: https://github.com/ichendev/feishu-server-api/blob/main/任务/清单动态订阅/获取动态订阅.md This Go code snippet demonstrates how to initialize the Feishu SDK client, create a request to get a task activity subscription, and handle the response. It requires your application's App ID and App Secret. The example shows how to set tasklist GUID, activity subscription GUID, and user ID type. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/task/v2" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larktask.NewGetTasklistActivitySubscriptionReqBuilder(). TasklistGuid(`33991879-704f-444f-81d7-55a6aa7be80c`). ActivitySubscriptionGuid(`33991879-704f-444f-81d7-55a6aa7be80c`). UserIdType(`open_id`). Build() // 发起请求 resp, err := client.Task.V2.TasklistActivitySubscription.Get(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### List Feishu Helpdesk FAQs (Golang SDK) Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/知识库/知识库管理/获取全部知识库详情.md Demonstrates how to list FAQs from the Feishu Helpdesk API using the Golang SDK. It covers client initialization, request building with parameters, sending the request, and handling responses and errors. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/helpdesk/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkhelpdesk.NewListFaqReqBuilder(). CategoryId(`6856395522433908739`). Status(`1`). Search(`点餐`). PageToken(`6856395634652479491`). PageSize(10). Build() // 发起请求 resp, err := client.Helpdesk.V1.Faq.List(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Python SDK Example - Get Task Collaborators Source: https://github.com/ichendev/feishu-server-api/blob/main/历史版本(不推荐)/任务/执行者/获取执行者列表.md Illustrates fetching task collaborators using the Feishu Python SDK, covering client setup and request construction. ```python import json import lark_oapi as lark from lark_oapi.api.task.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: ListTaskCollaboratorRequest = ListTaskCollaboratorRequest.builder() \ .task_id("0d38e26e-190a-49e9-93a2-35067763ed1f") \ .page_size(50) \ .page_token("「上次返回的page_token」") \ .user_id_type("open_id") \ .build() # 发起请求 response: ListTaskCollaboratorResponse = client.task.v1.task_collaborator.list(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.task.v1.task_collaborator.list failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Install Feishu Go SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/服务端 SDK/Golang SDK 指南/开发前准备.md This command installs the latest version of the Feishu Go SDK using the go get command. Ensure you have Go installed and configured in your environment. ```bash go get -u github.com/larksuite/oapi-sdk-go/v3@latest ``` -------------------------------- ### Golang SDK Example for Get Interview Minutes Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/候选人管理/投递流程/面试/获取面试速记明细.md Provides a Golang code example for interacting with the Feishu Hire API to get interview minutes. Shows how to initialize the client, build the request, and handle the response. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/hire/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkhire.NewGetMinutesReqBuilder(). InterviewId(`7085989097067563300`). PageToken(`NzM5MTgyNjQyNDY2MDc4OTU0OA==`). PageSize(10). Build() // 发起请求 resp, err := client.Hire.V1.Minutes.Get(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Get Talent Information - Java SDK Example Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/候选人管理/人才/获取人才详情.md Demonstrates fetching talent information using the Feishu Java SDK. This example covers client setup with application credentials, creating the GetTalentReq object, executing the API call, and handling potential server-side errors and successful responses. ```java package com.lark.oapi.sample.apiall.hirev2; import com.google.gson.JsonParser; import com.lark.oapi.Client; import com.lark.oapi.core.utils.Jsons; import com.lark.oapi.service.hire.v2.model.*; import java.util.HashMap; import com.lark.oapi.core.request.RequestOptions; import java.nio.charset.StandardCharsets; // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/java-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 public class GetTalentSample{ public static void main(String arg[]) throws Exception { // 构建client Client client = Client.newBuilder("YOUR_APP_ID", "YOUR_APP_SECRET").build(); // 创建请求对象 GetTalentReq req = GetTalentReq.newBuilder() .talentId("6960663240925956555") .userIdType("open_id") .build(); // 发起请求 GetTalentResp resp = client.hire().v2().talent().get(req); // 处理服务端错误 if (!resp.success()) { System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))) return; } // 业务数据处理 System.out.println(Jsons.DEFAULT.toJson(resp.getData())); } } ``` -------------------------------- ### List Applications (Golang SDK) Source: https://github.com/ichendev/feishu-server-api/blob/main/应用信息/应用管理/获取企业安装的应用.md Provides a Golang example for listing Feishu applications using the Lark SDK. It shows how to initialize the client, build the request with various parameters, send the request, and handle success or error responses. Ensure to replace placeholders with your actual App ID and App Secret. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/application/v6" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkapplication.NewListApplicationReqBuilder(). PageSize(50). PageToken(`AQD9/Rn9eij9Pm39ED40/dk53s4Ebp882DYfFaPFbz00L4CMZJrqGdzNyc8BcZtDbwVUvRmQTvyMYicnGWrde9X56TgdBuS+JKiSIkdexPw=`). UserIdType(`open_id`). Lang(`zh_cn`). Status(0). PaymentType(0). OwnerType(0). Build() // 发起请求 resp, err := client.Application.V6.Application.List(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Feishu Lingo API - Get Classifications (Python SDK) Source: https://github.com/ichendev/feishu-server-api/blob/main/飞书词典/分类/获取词典分类.md Example of using the Feishu Python SDK to retrieve classifications. Demonstrates client setup, request construction, and response processing. ```python import json import lark_oapi as lark from lark_oapi.api.lingo.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: ListClassificationRequest = ListClassificationRequest.builder() \ .page_size(20) \ .page_token("408ecac018b2e3518db37275e812aad7bb8ad3e755fc886f322ac6c430ba") \ .repo_id("7202510112396640276") \ .build() # 发起请求 response: ListClassificationResponse = client.lingo.v1.classification.list(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.lingo.v1.classification.list failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Feishu Helpdesk API Preparation (Python SDK) Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/知识库/知识库管理/获取全部知识库详情.md Provides the initial setup and import statements for using the Feishu Helpdesk API with the Python SDK. It guides users on where to find SDK usage documentation and emphasizes replacing placeholder values. ```python import json import lark_oapi as lark from lark_oapi.api.helpdesk.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Get Alerts using Python SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/视频会议/告警中心/获取告警记录.md Provides an example of using the Feishu Python SDK to retrieve alert records. Covers client setup, request construction, and response processing. ```python import json import lark_oapi as lark from lark_oapi.api.vc.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: ListAlertRequest = ListAlertRequest.builder() \ .start_time("1608888867") \ .end_time("1608888867") \ .query_type(1) \ .query_value("omm_4de32cf10a4358788ff4e09e37ebbf9b") \ .page_size(100) \ .page_token("100") \ .build() # 发起请求 response: ListAlertResponse = client.vc.v1.alert.list(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.vc.v1.alert.list failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Create FAQ Entry - Golang SDK Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/知识库/知识库管理/创建知识库.md This Go code snippet demonstrates how to create a new FAQ entry using the Feishu Helpdesk SDK. It shows how to initialize the client, build the request with category ID, question, answer, and tags, and handle the API response. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/helpdesk/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkhelpdesk.NewCreateFaqReqBuilder(). Body(larkhelpdesk.NewCreateFaqReqBodyBuilder(). Faq(larkhelpdesk.NewFaqCreateInfoBuilder(). CategoryId(`6836004780707807251`). Question(`问题`). Answer(`答案`). AnswerRichtext(`[{"content":"答案","type":"text"},{"content":"这只是一个测试,医保问题","type":"text"}]`). Tags([]string{`问`, `题`}). Build()). Build()). Build() // 发起请求 resp, err := client.Helpdesk.V1.Faq.Create(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Python SDK Example for Get File Statistics Source: https://github.com/ichendev/feishu-server-api/blob/main/云文档/云空间/文件/获取文件统计信息.md Illustrates how to use the Feishu Python SDK to fetch file statistics. Covers client setup, request construction, and response processing. ```python import json import lark_oapi as lark from lark_oapi.api.drive.v1 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 # 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. def main(): # 创建client client = lark.Client.builder() \ .app_id("YOUR_APP_ID") \ .app_secret("YOUR_APP_SECRET") \ .log_level(lark.LogLevel.DEBUG) \ .build() # 构造请求对象 request: GetFileStatisticsRequest = GetFileStatisticsRequest.builder() \ .file_token("doccnfYZzTlvXqZIGTdAHKabcef") \ .file_type("doc") \ .build() # 发起请求 response: GetFileStatisticsResponse = client.drive.v1.file_statistics.get(request) # 处理失败返回 if not response.success(): lark.logger.error( f"client.drive.v1.file_statistics.get failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}") return # 处理业务结果 lark.logger.info(lark.JSON.marshal(response.data, indent=4)) if __name__ == "__main__": main() ``` -------------------------------- ### Golang SDK Example for Feishu Lingo Highlight Source: https://github.com/ichendev/feishu-server-api/blob/main/飞书词典/词条/词条高亮.md Example demonstrating how to use the Feishu Golang SDK to call the Lingo V1 Entities Highlight API. Includes client creation, request building, and response handling. ```go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/lingo/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larklingo.NewHighlightEntityReqBuilder(). Body(larklingo.NewHighlightEntityReqBodyBuilder(). Text(`词典是飞书提供的一款知识管理工具`). Build()). Build() // 发起请求 resp, err := client.Lingo.V1.Entity.Highlight(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Golang SDK Example Source: https://github.com/ichendev/feishu-server-api/blob/main/招聘/招聘相关配置/地址/获取地址列表.md Provides a Go example using the Feishu Open Platform SDK to list locations. It shows how to initialize the client, build the request with pagination and usage parameters, and handle the response. ```Go package main import ( "context" "fmt" "github.com/larksuite/oapi-sdk-go/v3" "github.com/larksuite/oapi-sdk-go/v3/core" "github.com/larksuite/oapi-sdk-go/v3/service/hire/v1" ) // SDK 使用文档:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/golang-sdk-guide/preparations // 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET. // 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 func main() { // 创建 Client client := lark.NewClient("YOUR_APP_ID", "YOUR_APP_SECRET") // 创建请求对象 req := larkhire.NewListLocationReqBuilder(). PageToken(`eyJvZmZzZXQiOjEwLCJ0aW1lc3RhbXAiOjE2Mjc1NTUyMjM2NzIsImlkIjpudWxsfQ==`). PageSize(100). Usage(`interview_location`). Build() // 发起请求 resp, err := client.Hire.V1.Location.List(context.Background(), req) // 处理错误 if err != nil { fmt.Println(err) return } // 服务端错误处理 if !resp.Success() { fmt.Printf("logId: %s, error response: \n%s", resp.RequestId(), larkcore.Prettify(resp.CodeError)) return } // 业务处理 fmt.Println(larkcore.Prettify(resp)) } ``` -------------------------------- ### Python SDK Example: Get Department Info Source: https://github.com/ichendev/feishu-server-api/blob/main/通讯录/部门/获取单个部门信息.md Illustrates how to use the Feishu Python SDK to retrieve department information. This snippet shows the necessary imports and setup for making the API call. ```python import json import lark_oapi as lark from lark_oapi.api.contact.v3 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 ``` -------------------------------- ### Python SDK - Batch Get Department Information Source: https://github.com/ichendev/feishu-server-api/blob/main/通讯录/部门/批量获取部门信息.md Example of how to use the Feishu Python SDK to batch retrieve department information. Ensure the SDK is installed and configured with your tenant access token. ```Python import json import lark_oapi as lark from lark_oapi.api.contact.v3 import * # SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development # 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用 client = lark.Client.default() # 假设 department_ids 是一个包含部门 ID 的列表 department_ids = ["od-4e6ac4d14bcd5071a37a39de902c7141", "od-xxxxxxxxxxxxxxxxx"] req = GetBatchDepartmentReq() req.department_ids = department_ids resp = client.contact.v3.department.batch(req) # 处理响应 if resp.code == 0: print(json.dumps(resp.data, indent=4)) else: print(f"Error: {resp.code} - {resp.msg}") ``` -------------------------------- ### PHP Guzzle Example for Creating FAQ Source: https://github.com/ichendev/feishu-server-api/blob/main/服务台/知识库/知识库管理/创建知识库.md This code snippet demonstrates how to use the PHP Guzzle HTTP client to create a knowledge base entry via the Feishu Helpdesk API. It includes setting up the client, headers, and the request body. ```PHP 'Bearer t-7f1b******8e560', 'Content-Type' => 'application/json' ]; $body = '{ "faq": { "category_id": "6836004780707807251", "question": "问题", "answer": "答案", "answer_richtext": "[{\"content\":\"答案\",\"type\":\"text\"},{\"content\":\"这只是一个测试,医保问题\",\"type\":\"text\"}]", "tags": [ "问", "题" ] } }'; $request = new Request('POST', 'https://open.feishu.cn/open-apis/helpdesk/v1/faqs', $headers, $body); $res = $client->sendAsync($request)->wait(); echo $res->getBody(); ?> ```