1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LINE WORKS の外部連携ユーザーをリスト化する

Posted at

LINE WORKS の Contact API の連絡先リストの取得を使って、LINE WORKS でつながっている外部の LINE WORKS ユーザー、LINE ユーザーをリスト化します。

会社全体での外部連携ユーザー数や、LINE WORKS ユーザーごとの外部連携ユーザー数を集計する、期間ごとの増加状況を把握するなどに利用できると思います。

連絡先リスト取得 API のリファレンス ページは以下です。
https://developers.worksmobile.com/jp/reference/contact-list?lang=ja

Response は Cursor 型のページネーションで複数ページ渡って返されます。以下の記事の手順でページネーションの処理を行います。

PowerAutomate でカーソル型ページネーションを使う
https://qiita.com/iwaohig/items/9f06b188c1898a722192

Power Automate のクラウドフロー

手動でフローをトリガー

ここでは手動でフローをトリガーを利用しています。要件に応じてタイマーで定期的に実行するなども可能です。
l_147288799_90_b17b389d7a3d8115830e0dac2215d3d2.png

cursor と Do until を抜けるための変数

cursor の情報を格納する変数を初期化します。
また、最後のページの情報を取得した際に、Do until を抜けるのに用いる変数も初期化します。
l_1517737_2424_7d3b744ceb068877ce71150f0a4151da.png
l_1517737_2425_561598bcdbbb4b9c707ee2bb1c0d7f61.png

Do until のコントロールで複数ページの情報を取得

l_1517737_2426_c33092ecb19fcb0264882a2ba73f4eb2.png
Do until を抜けるための条件を設定します。
l_147288799_92_938f9efa0a679e7f8d1062b1418b75b7.png
HTTP コネクタで連絡先リスト取得 API のリクエストを設定します。クエリに nextCursor を指定します。その他のクエリはリファレンスに沿って適宜設定します。
image.png
JSON の解析で連絡先リスト取得 API のレスポンスを処理します。JSON スキーマは以下です。

{
    "type": "object",
    "properties": {
        "contacts": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "contactId": {
                        "type": "string"
                    },
                    "contactTagIds": {
                        "type": "array"
                    },
                    "linkedExternalUser": {},
                    "permission": {
                        "type": "object",
                        "properties": {
                            "masterUserId": {},
                            "isCoEditing": {
                                "type": "boolean"
                            },
                            "accessibleRange": {
                                "type": "string"
                            },
                            "accessibleMembers": {
                                "type": "array"
                            }
                        }
                    },
                    "createdTime": {
                        "type": "string"
                    },
                    "modifiedTime": {
                        "type": "string"
                    },
                    "contactName": {
                        "type": "object",
                        "properties": {
                            "lastName": {
                                "type": "string"
                            },
                            "firstName": {
                                "type": "string"
                            },
                            "phoneticLastName": {},
                            "phoneticFirstName": {},
                            "prefix": {},
                            "suffix": {},
                            "middleName": {},
                            "nickName": {}
                        }
                    },
                    "emails": {
                        "type": "array"
                    },
                    "telephones": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "type": "string"
                                },
                                "telephone": {
                                    "type": "string"
                                },
                                "customType": {},
                                "primary": {
                                    "type": "boolean"
                                }
                            },
                            "required": [
                                "type",
                                "telephone",
                                "customType",
                                "primary"
                            ]
                        }
                    },
                    "organizations": {
                        "type": "array"
                    },
                    "locations": {
                        "type": "array"
                    },
                    "events": {
                        "type": "array"
                    },
                    "messengers": {
                        "type": "array"
                    },
                    "websites": {
                        "type": "array"
                    },
                    "memo": {}
                },
                "required": [
                    "contactId",
                    "contactTagIds",
                    "linkedExternalUser",
                    "permission",
                    "createdTime",
                    "modifiedTime",
                    "contactName",
                    "emails",
                    "telephones",
                    "organizations",
                    "locations",
                    "events",
                    "messengers",
                    "websites",
                    "memo"
                ]
            }
        },
        "responseMetaData": {
            "type": "object",
            "properties": {
                "nextCursor": {}
            }
        }
    }
}

l_147288799_95_05e4ad969701b0094bdca786f4e24537.png
さらに LinkedExternalUser 内の項目を取得するための JSON の解析を設定します。スキーマは以下です。

{
    "type": "object",
    "properties": {
        "id": {
            "type": "string"
        },
        "type": {
            "type": "string"
        },
        "buddyUserIds": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}

l_147288799_99_0c3c8ec6866004885e322aa2c45c3f63.png

Excel Online に書き出します。出力した項目を設定したテーブルを作成します。

l_147288799_96_04e29c78792efa1a5f0d1a776f3b5131.png

表に行を追加のアクションで BuudyUserIds ごとのデータを書き出します。Apply to each で処理されます。

条件のコントロール

l_1517737_2429_905ce6a96f8e37a750328ac1715b8d48.png
最終ページに到達しカーソルの値が null の場合は Do until を抜けるための変数の値を変更します。
image.png

次ページのためのカーソルの情報が存在する場合は cursor の変数に値を設定します。

これによりページネーションされた情報の取得が可能です。

フローは以上です。

手動でフローを開始すると、HTTP アクションに設定したクエリに基づいてデータを出力し Excel に出力されます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?