ここ最近Power Platformの城の登壇動画編集Clipchampを使っているんですが、毎度同じフォーマットで作成しているのでフォルダコピーしてから動画編集をしています。

地味にこれが面倒なのでフォルダコピーをPower Automateで自動化しようとしたところ、SharePointでは「フォルダのコピー」アクションがあるのに対し、OneDriveには存在しませんでした。


代替手段としてGraph APIを使ってフォルダコピーを自動化したので備忘です。
OneDrive API & HTTPリクエスト
以下を参考にHTTPリクエスト(非推奨)を用いてOneDrive APIを実行します。
Copy a file or folder - OneDrive API - OneDrive dev center | Microsoft Learn
Office 365 Groupsの「HTTP 要求を送信します」アクションでAPIを実行しますが、こちらは非推奨となっているためマネする場合は自己責任で実行をお願いします。
↓クラシックデザイナーにペーストすれば利用可能です。
{"id":"022189c7-e71e-4b88-9e7e-b8cbf46bc368","brandColor":"#EB3C00","connectionReferences":{"shared_office365groups_1":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_office365groups/connections/shared-office365grou-6b56f974-29a6-4a98-93ff-092b9de4116e"}},"shared_office365groups":{"connection":{"id":"/new_sharedoffice365groups_149bb"}}},"connectorDisplayName":"Office 365 グループ","icon":"https://connectoricons-prod.azureedge.net/releases/v1.0.1654/1.0.1654.3410/office365groups/icon.png","isTrigger":false,"operationName":"HTTP_要求を送信します","operationDefinition":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_office365groups_1","operationId":"HttpRequest","apiId":"/providers/Microsoft.PowerApps/apis/shared_office365groups"},"parameters":{"Uri":"","Method":"","ContentType":"application/json"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"operationMetadataId":"16b6956c-8454-426e-8564-426e46fdde45"}}}
作り方
コピペ用
以下をクラシックデザイナーでコピペすれば簡単に作れます。
コピー元、コピー先のフォルダは後述の方法で取得してください。
{"id":"398de42e-530a-4b74-9383-0cfd1e6c8fd0","brandColor":"#8C3900","connectionReferences":{"shared_onedriveforbusiness":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-c46f4e2b-fa21-4c97-8775-5504f9c33169"}},"shared_office365groups_2":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_office365groups/connections/d7fa7c68b55e4f398cbebe4bd32d31e5"}}},"connectorDisplayName":"制御","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"スコープ","operationDefinition":{"type":"Scope","actions":{"コピー元":{"type":"Compose","inputs":"@null","runAfter":{}},"HTTP_要求を送信します":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_office365groups_2","operationId":"HttpRequest","apiId":"/providers/Microsoft.PowerApps/apis/shared_office365groups"},"parameters":{"Uri":"https://graph.microsoft.com/v1.0/me/drive/items/@{outputs('コピー元')}/copy","Method":"POST","Body":"{\n \"parentReference\": {\n \"driveId\": \"me\",\n \"id\": \"@{outputs('コピー先')}\"\n },\n \"name\": \"@{outputs('ファイル名')}\"\n}","ContentType":"application/json"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"ファイル名":["Succeeded"]},"metadata":{"operationMetadataId":"16b6956c-8454-426e-8564-426e46fdde45"}},"コピー先":{"type":"Compose","inputs":"@null","runAfter":{"コピー元":["Succeeded"]}},"ファイル名":{"type":"Compose","inputs":"@null","runAfter":{"コピー先":["Succeeded"]}}},"runAfter":{}}}
コピー元、コピー先のフォルダ(Item)IDを取得する
OneDrive APIのパラメーターとしてコピー元、コピー先のフォルダIDが必要なので、以下の方法で取得します。
まず「フォルダー内のファイルのリスト」などのフォルダを選択するアクションを選択します。

次にコピー元のフォルダを選択します。

…→コードのプレビューを選択します。

metadata下にこのアクションでこれまでに選択したフォルダのIDが一覧で存在しているので、該当フォルダの赤枠部分(.から"まで)をコピーします。この部分がフォルダ(Item)IDとなります。


HTTPリクエスト
繰り返しになりますが、非推奨のアクションであるため自己責任で実行をお願いします。

1番目の出力部分がコピー元フォルダID、2番目がコピー先フォルダID、3番目がコピー後のフォルダ名です。
実行結果
以下で紹介したフローの後続アクションとして設定しました。
Teamsでイベントを作成すると、以下の通りイベント名でフォルダがコピーされました。


フォルダの中身もコピーされています。

SharePointのアクションを使用する方法
おいしみさんにSharePointのアクションを使用する方法を紹介していただきました。
非推奨のアクションを利用しないので、こちらを使用しましょう。