以提供一个增量获取组织数据的接口为例:

1、新建类型为“动态OpenAPI”的云函数,按指定业务将代码编写完成。并通过“云函数测试”按钮测试正常。
class PrivateAPIService(BasePrivateApiService):
    def execute(self, **kwargs):
        page_index = kwargs.get("page_index") or 1
        page_size = kwargs.get("page_size") or 100
        operate_time = kwargs.get("operate_time")
        if not operate_time:
            operate_time = datetime.datetime.now().strftime("%Y-%m-%d") + " 00:00:00"
        api_param = {"model": "OrgDepartmentHistory",
                     "page_index": page_index,
                     "page_size": page_size,
                     "filter_dict": {"operate_time": {"gte": operate_time},
                                     "org_type": [10, 20]},
                     "extra_property": {
                         "sorts": [{"key": "id", "type": "asc"}],
                         "fields": [{"field": ["origin_id"]},
                                    {"field": ["begin_date"]},
                                    {"field": ["end_date"]},
                                    {"field": ["org_type"]},
                                    {"field": ["number"]},
                                    {"field": ["name"]},
                                    {"field": ["org_full_name"]},
                                    {"field": ["parent_id"]},
                                    {"field": ["subordinate_unit_id"]},
                                    {"field": ["enabled"]},
                                    {"field": ["operate_time"]}]}}
        result = CustomerUtil.call_open_api("hcm.model.list", api_param)
        return result
2、申请访问令牌。【系统设置】→【集成管理】→【访问令牌管理】。

点击【新增】填写对应描述;

可授权访问api列表】按实际填写,即此令牌可以访问哪些api,可填多个;

允许访问的ip列表】出于安全考虑,尽量填写,填写后,只有从指定ip地址服务器上发起的请求才能访问此接口,其他服务器即使拥有令牌也无法访问此接口。

                                    实在不知道的可以不填。然后点击【生成令牌】,列表页面上就会多一条记录,点开此记录,最下方就会有令牌信息。

3、postman(接口调试工具)调用测试。

请求地址:https://mingcloud.hcmcloud.com/api/private.hcm_organize_outer(即在系统内点击“云函数测试”打开的地址)

请求头:Authorization:Bearer 访问令牌                   注意Bearer和访问令牌中间有个空格

请求体:云函数需要传入的指定格式的json数据

如下截图所示,返回的数据是2024-01-05 00:00:00之后发生变化的组织数据,按50条一页进行分页,取第2页的数据。



  • 无标签