gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/admin/v1/api.go (about)

     1  // Package admin code generated by oapi sdk gen
     2  /*
     3   * MIT License
     4   *
     5   * Copyright (c) 2022 Lark Technologies Pte. Ltd.
     6   *
     7   * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
     8   *
     9   * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
    10   *
    11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    12   */
    13  
    14  package larkadmin
    15  
    16  import (
    17  	"context"
    18  	"net/http"
    19  
    20  	"gitee.com/larksuite/oapi-sdk-go/v3/core"
    21  )
    22  
    23  func NewService(config *larkcore.Config) *AdminService {
    24  	a := &AdminService{config: config}
    25  	a.AdminDeptStat = &adminDeptStat{service: a}
    26  	a.AdminUserStat = &adminUserStat{service: a}
    27  	a.Badge = &badge{service: a}
    28  	a.BadgeGrant = &badgeGrant{service: a}
    29  	a.BadgeImage = &badgeImage{service: a}
    30  	a.Password = &password{service: a}
    31  	return a
    32  }
    33  
    34  type AdminService struct {
    35  	config        *larkcore.Config
    36  	AdminDeptStat *adminDeptStat // 部门维度的数据报表
    37  	AdminUserStat *adminUserStat // 用户维度的数据报表
    38  	Badge         *badge         // 勋章
    39  	BadgeGrant    *badgeGrant    // 勋章授予名单
    40  	BadgeImage    *badgeImage    // 勋章图片
    41  	Password      *password      // 密码
    42  }
    43  
    44  type adminDeptStat struct {
    45  	service *AdminService
    46  }
    47  type adminUserStat struct {
    48  	service *AdminService
    49  }
    50  type badge struct {
    51  	service *AdminService
    52  }
    53  type badgeGrant struct {
    54  	service *AdminService
    55  }
    56  type badgeImage struct {
    57  	service *AdminService
    58  }
    59  type password struct {
    60  	service *AdminService
    61  }
    62  
    63  // 获取部门维度的用户活跃和功能使用数据
    64  //
    65  // - 该接口用于获取部门维度的用户活跃和功能使用数据,即IM(即时通讯)、日历、云文档、音视频会议功能的使用数据。
    66  //
    67  // - - 只有企业自建应用才有权限调用此接口;;- 当天的数据会在第二天的早上九点半产出(UTC+8)
    68  //
    69  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/admin_dept_stat/list
    70  //
    71  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/list_adminDeptStat.go
    72  func (a *adminDeptStat) List(ctx context.Context, req *ListAdminDeptStatReq, options ...larkcore.RequestOptionFunc) (*ListAdminDeptStatResp, error) {
    73  	// 发起请求
    74  	apiReq := req.apiReq
    75  	apiReq.ApiPath = "/open-apis/admin/v1/admin_dept_stats"
    76  	apiReq.HttpMethod = http.MethodGet
    77  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    78  	apiResp, err := larkcore.Request(ctx, apiReq, a.service.config, options...)
    79  	if err != nil {
    80  		return nil, err
    81  	}
    82  	// 反序列响应结果
    83  	resp := &ListAdminDeptStatResp{ApiResp: apiResp}
    84  	err = apiResp.JSONUnmarshalBody(resp)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  	return resp, err
    89  }
    90  
    91  // 获取用户维度的用户活跃和功能使用数据
    92  //
    93  // - 用于获取用户维度的用户活跃和功能使用数据,即IM(即时通讯)、日历、云文档、音视频会议功能的使用数据。
    94  //
    95  // - - 只有企业自建应用才有权限调用此接口;;- 当天的数据会在第二天的早上九点半产出(UTC+8)
    96  //
    97  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/admin_user_stat/list
    98  //
    99  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/list_adminUserStat.go
   100  func (a *adminUserStat) List(ctx context.Context, req *ListAdminUserStatReq, options ...larkcore.RequestOptionFunc) (*ListAdminUserStatResp, error) {
   101  	// 发起请求
   102  	apiReq := req.apiReq
   103  	apiReq.ApiPath = "/open-apis/admin/v1/admin_user_stats"
   104  	apiReq.HttpMethod = http.MethodGet
   105  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   106  	apiResp, err := larkcore.Request(ctx, apiReq, a.service.config, options...)
   107  	if err != nil {
   108  		return nil, err
   109  	}
   110  	// 反序列响应结果
   111  	resp := &ListAdminUserStatResp{ApiResp: apiResp}
   112  	err = apiResp.JSONUnmarshalBody(resp)
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  	return resp, err
   117  }
   118  
   119  // 创建勋章
   120  //
   121  // - 使用该接口可以创建一枚完整的勋章信息,一个租户下最多可创建1000枚勋章。
   122  //
   123  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge/create
   124  //
   125  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/create_badge.go
   126  func (b *badge) Create(ctx context.Context, req *CreateBadgeReq, options ...larkcore.RequestOptionFunc) (*CreateBadgeResp, error) {
   127  	// 发起请求
   128  	apiReq := req.apiReq
   129  	apiReq.ApiPath = "/open-apis/admin/v1/badges"
   130  	apiReq.HttpMethod = http.MethodPost
   131  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   132  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   133  	if err != nil {
   134  		return nil, err
   135  	}
   136  	// 反序列响应结果
   137  	resp := &CreateBadgeResp{ApiResp: apiResp}
   138  	err = apiResp.JSONUnmarshalBody(resp)
   139  	if err != nil {
   140  		return nil, err
   141  	}
   142  	return resp, err
   143  }
   144  
   145  // 获取勋章详情
   146  //
   147  // - 可以通过该接口查询勋章的详情
   148  //
   149  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge/get
   150  //
   151  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/get_badge.go
   152  func (b *badge) Get(ctx context.Context, req *GetBadgeReq, options ...larkcore.RequestOptionFunc) (*GetBadgeResp, error) {
   153  	// 发起请求
   154  	apiReq := req.apiReq
   155  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id"
   156  	apiReq.HttpMethod = http.MethodGet
   157  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   158  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   159  	if err != nil {
   160  		return nil, err
   161  	}
   162  	// 反序列响应结果
   163  	resp := &GetBadgeResp{ApiResp: apiResp}
   164  	err = apiResp.JSONUnmarshalBody(resp)
   165  	if err != nil {
   166  		return nil, err
   167  	}
   168  	return resp, err
   169  }
   170  
   171  // 获取勋章列表
   172  //
   173  // - 可以通过该接口列出租户下所有的勋章,勋章的排列顺序是按照创建时间倒序排列。
   174  //
   175  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge/list
   176  //
   177  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/list_badge.go
   178  func (b *badge) List(ctx context.Context, req *ListBadgeReq, options ...larkcore.RequestOptionFunc) (*ListBadgeResp, error) {
   179  	// 发起请求
   180  	apiReq := req.apiReq
   181  	apiReq.ApiPath = "/open-apis/admin/v1/badges"
   182  	apiReq.HttpMethod = http.MethodGet
   183  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   184  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   185  	if err != nil {
   186  		return nil, err
   187  	}
   188  	// 反序列响应结果
   189  	resp := &ListBadgeResp{ApiResp: apiResp}
   190  	err = apiResp.JSONUnmarshalBody(resp)
   191  	if err != nil {
   192  		return nil, err
   193  	}
   194  	return resp, err
   195  }
   196  func (b *badge) ListByIterator(ctx context.Context, req *ListBadgeReq, options ...larkcore.RequestOptionFunc) (*ListBadgeIterator, error) {
   197  	return &ListBadgeIterator{
   198  		ctx:      ctx,
   199  		req:      req,
   200  		listFunc: b.List,
   201  		options:  options,
   202  		limit:    req.Limit}, nil
   203  }
   204  
   205  // 修改勋章信息
   206  //
   207  // - 通过该接口可以修改勋章的信息
   208  //
   209  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge/update
   210  //
   211  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/update_badge.go
   212  func (b *badge) Update(ctx context.Context, req *UpdateBadgeReq, options ...larkcore.RequestOptionFunc) (*UpdateBadgeResp, error) {
   213  	// 发起请求
   214  	apiReq := req.apiReq
   215  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id"
   216  	apiReq.HttpMethod = http.MethodPut
   217  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   218  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   219  	if err != nil {
   220  		return nil, err
   221  	}
   222  	// 反序列响应结果
   223  	resp := &UpdateBadgeResp{ApiResp: apiResp}
   224  	err = apiResp.JSONUnmarshalBody(resp)
   225  	if err != nil {
   226  		return nil, err
   227  	}
   228  	return resp, err
   229  }
   230  
   231  // 创建勋章的授予名单
   232  //
   233  // - 通过该接口可以为特定勋章创建一份授予名单,一枚勋章下最多可创建1000份授予名单。
   234  //
   235  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge-grant/create
   236  //
   237  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/create_badgeGrant.go
   238  func (b *badgeGrant) Create(ctx context.Context, req *CreateBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*CreateBadgeGrantResp, error) {
   239  	// 发起请求
   240  	apiReq := req.apiReq
   241  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id/grants"
   242  	apiReq.HttpMethod = http.MethodPost
   243  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   244  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   245  	if err != nil {
   246  		return nil, err
   247  	}
   248  	// 反序列响应结果
   249  	resp := &CreateBadgeGrantResp{ApiResp: apiResp}
   250  	err = apiResp.JSONUnmarshalBody(resp)
   251  	if err != nil {
   252  		return nil, err
   253  	}
   254  	return resp, err
   255  }
   256  
   257  // 删除授予名单
   258  //
   259  // - 通过该接口可以删除特定授予名单的信息
   260  //
   261  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge-grant/delete
   262  //
   263  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/delete_badgeGrant.go
   264  func (b *badgeGrant) Delete(ctx context.Context, req *DeleteBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*DeleteBadgeGrantResp, error) {
   265  	// 发起请求
   266  	apiReq := req.apiReq
   267  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id/grants/:grant_id"
   268  	apiReq.HttpMethod = http.MethodDelete
   269  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   270  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   271  	if err != nil {
   272  		return nil, err
   273  	}
   274  	// 反序列响应结果
   275  	resp := &DeleteBadgeGrantResp{ApiResp: apiResp}
   276  	err = apiResp.JSONUnmarshalBody(resp)
   277  	if err != nil {
   278  		return nil, err
   279  	}
   280  	return resp, err
   281  }
   282  
   283  // 获取授予名单的信息
   284  //
   285  // - 通过该接口可以获取特定授予名单的信息
   286  //
   287  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge-grant/get
   288  //
   289  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/get_badgeGrant.go
   290  func (b *badgeGrant) Get(ctx context.Context, req *GetBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*GetBadgeGrantResp, error) {
   291  	// 发起请求
   292  	apiReq := req.apiReq
   293  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id/grants/:grant_id"
   294  	apiReq.HttpMethod = http.MethodGet
   295  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   296  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   297  	if err != nil {
   298  		return nil, err
   299  	}
   300  	// 反序列响应结果
   301  	resp := &GetBadgeGrantResp{ApiResp: apiResp}
   302  	err = apiResp.JSONUnmarshalBody(resp)
   303  	if err != nil {
   304  		return nil, err
   305  	}
   306  	return resp, err
   307  }
   308  
   309  // 获取勋章的授予名单列表
   310  //
   311  // - 通过该接口可以获取特定勋章下的授予名单列表,授予名单的排列顺序按照创建时间倒序排列。
   312  //
   313  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge-grant/list
   314  //
   315  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/list_badgeGrant.go
   316  func (b *badgeGrant) List(ctx context.Context, req *ListBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*ListBadgeGrantResp, error) {
   317  	// 发起请求
   318  	apiReq := req.apiReq
   319  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id/grants"
   320  	apiReq.HttpMethod = http.MethodGet
   321  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   322  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   323  	if err != nil {
   324  		return nil, err
   325  	}
   326  	// 反序列响应结果
   327  	resp := &ListBadgeGrantResp{ApiResp: apiResp}
   328  	err = apiResp.JSONUnmarshalBody(resp)
   329  	if err != nil {
   330  		return nil, err
   331  	}
   332  	return resp, err
   333  }
   334  func (b *badgeGrant) ListByIterator(ctx context.Context, req *ListBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*ListBadgeGrantIterator, error) {
   335  	return &ListBadgeGrantIterator{
   336  		ctx:      ctx,
   337  		req:      req,
   338  		listFunc: b.List,
   339  		options:  options,
   340  		limit:    req.Limit}, nil
   341  }
   342  
   343  // 修改授予名单
   344  //
   345  // - 通过该接口可以修改特定授予名单的相关信息
   346  //
   347  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge-grant/update
   348  //
   349  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/update_badgeGrant.go
   350  func (b *badgeGrant) Update(ctx context.Context, req *UpdateBadgeGrantReq, options ...larkcore.RequestOptionFunc) (*UpdateBadgeGrantResp, error) {
   351  	// 发起请求
   352  	apiReq := req.apiReq
   353  	apiReq.ApiPath = "/open-apis/admin/v1/badges/:badge_id/grants/:grant_id"
   354  	apiReq.HttpMethod = http.MethodPut
   355  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   356  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   357  	if err != nil {
   358  		return nil, err
   359  	}
   360  	// 反序列响应结果
   361  	resp := &UpdateBadgeGrantResp{ApiResp: apiResp}
   362  	err = apiResp.JSONUnmarshalBody(resp)
   363  	if err != nil {
   364  		return nil, err
   365  	}
   366  	return resp, err
   367  }
   368  
   369  // 上传勋章图片
   370  //
   371  // - 通过该接口可以上传勋章详情图、挂饰图的文件,获取对应的文件key
   372  //
   373  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/badge_image/create
   374  //
   375  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/create_badgeImage.go
   376  func (b *badgeImage) Create(ctx context.Context, req *CreateBadgeImageReq, options ...larkcore.RequestOptionFunc) (*CreateBadgeImageResp, error) {
   377  	options = append(options, larkcore.WithFileUpload())
   378  	// 发起请求
   379  	apiReq := req.apiReq
   380  	apiReq.ApiPath = "/open-apis/admin/v1/badge_images"
   381  	apiReq.HttpMethod = http.MethodPost
   382  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   383  	apiResp, err := larkcore.Request(ctx, apiReq, b.service.config, options...)
   384  	if err != nil {
   385  		return nil, err
   386  	}
   387  	// 反序列响应结果
   388  	resp := &CreateBadgeImageResp{ApiResp: apiResp}
   389  	err = apiResp.JSONUnmarshalBody(resp)
   390  	if err != nil {
   391  		return nil, err
   392  	}
   393  	return resp, err
   394  }
   395  
   396  // 重置密码
   397  //
   398  // - 重置用户的企业邮箱密码,仅当用户的邮箱和企业邮箱(别名)一致时生效,可用于处理飞书企业邮箱登录死锁的问题。;;邮箱死锁:当用户的登录凭证与飞书企业邮箱一致时,目前飞书登录流程要求用户输入验证码,由于飞书邮箱无单独的帐号体系,则未登录时无法收取邮箱验证码,即陷入死锁
   399  //
   400  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/admin-v1/password/reset
   401  //
   402  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/adminv1/reset_password.go
   403  func (p *password) Reset(ctx context.Context, req *ResetPasswordReq, options ...larkcore.RequestOptionFunc) (*ResetPasswordResp, error) {
   404  	// 发起请求
   405  	apiReq := req.apiReq
   406  	apiReq.ApiPath = "/open-apis/admin/v1/password/reset"
   407  	apiReq.HttpMethod = http.MethodPost
   408  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   409  	apiResp, err := larkcore.Request(ctx, apiReq, p.service.config, options...)
   410  	if err != nil {
   411  		return nil, err
   412  	}
   413  	// 反序列响应结果
   414  	resp := &ResetPasswordResp{ApiResp: apiResp}
   415  	err = apiResp.JSONUnmarshalBody(resp)
   416  	if err != nil {
   417  		return nil, err
   418  	}
   419  	return resp, err
   420  }