ファイルとフォルダの転送
ファイルとフォルダの転送
ユーザーアカウントのプロビジョニング解除における一般的な要件の1つが、ユーザーアカウント内に保存されているすべてのファイルとフォルダを別のユーザーアカウント、またはサービスアカウントなどの長期保存用の場所に転送することです。
Box内でこれを実行するのに使用される一般的な方法は以下の2つです。
- すべてのコンテンツをあるユーザーから別のユーザーに直接移動する、所有フォルダの移動APIを使用する。
- コラボレーション転送の方法を使用して、一度に1つのファイルまたはフォルダの所 有権を、あるユーザーから別のユーザーに変更する。
所有フォルダの移動APIの使用
所有フォルダの移動エンドポイントは、あるユーザーが所有するコンテンツ全体を別のユーザーに移動することを目的に設計されています。
転送エンドポイントを呼び出すには、転送元のユーザーIDと転送先のユーザ ーIDを指定します。
await client.transfer.transferOwnedFolder(
sourceUser.id,
{
ownedBy: {
id: targetUser.id,
} satisfies TransferOwnedFolderRequestBodyOwnedByField,
} satisfies TransferOwnedFolderRequestBody,
{
queryParams: { notify: false } satisfies TransferOwnedFolderQueryParams,
} satisfies TransferOwnedFolderOptionalsInput,
);client.transfer.transfer_owned_folder(
source_user.id, TransferOwnedFolderOwnedBy(id=target_user.id), notify=False
)await client.Transfer.TransferOwnedFolderAsync(userId: sourceUser.Id, requestBody: new TransferOwnedFolderRequestBody(ownedBy: new TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.Id)), queryParams: new TransferOwnedFolderQueryParams() { Notify = false });try await client.transfer.transferOwnedFolder(userId: sourceUser.id, requestBody: TransferOwnedFolderRequestBody(ownedBy: TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.id)), queryParams: TransferOwnedFolderQueryParams(notify: false))client.getTransfer().transferOwnedFolder(sourceUser.getId(), new TransferOwnedFolderRequestBody(new TransferOwnedFolderRequestBodyOwnedByField(targetUser.getId())), new TransferOwnedFolderQueryParams.Builder().notify(false).build())await client.Transfer.TransferOwnedFolderAsync(userId: sourceUser.Id, requestBody: new TransferOwnedFolderRequestBody(ownedBy: new TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.Id)), queryParams: new TransferOwnedFolderQueryParams() { Notify = false });await client.transfer.transferOwnedFolder(
sourceUser.id,
{
ownedBy: {
id: targetUser.id,
} satisfies TransferOwnedFolderRequestBodyOwnedByField,
} satisfies TransferOwnedFolderRequestBody,
{
queryParams: { notify: false } satisfies TransferOwnedFolderQueryParams,
} satisfies TransferOwnedFolderOptionalsInput,
);コラボレーション転送の使用
コラボレーション転送は、コラボレーションエンドポイントを使用して、単一のファイルまたはフォルダの所有権をあるユーザーから別のユーザーに即座に変更するプロセスです。
transfer_from_userからtransfer_to_userへの転送の一般的なプロセスは以下の手順に従います。
転送先ユーザーを共同所有者として追加
最初の手順は、転送するファイルまたはフォルダへのco-ownerアクセス権限を持つコラボレータとして、transfer_to_userアカウントを追加することです。
transfer_from_userアカウントとして呼び出しを行い、コラボレーションを追加エンドポイントを使用してtransfer_to_userを共同所有者として追加します。
curl -i -X POST "https://api.box.com/2.0/collaborations" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-H "content-type: application/json" \
-d '{
"item": {
"type": "file",
"id": "11446498"
},
"accessible_by": {
"type": "user",
"login": "user@example.com"
},
"role": "editor"
}'await client.userCollaborations.createCollaboration({
item: {
type: 'folder' as CreateCollaborationRequestBodyItemTypeField,
id: folder.id,
} satisfies CreateCollaborationRequestBodyItemField,
accessibleBy: {
type: 'user' as CreateCollaborationRequestBodyAccessibleByTypeField,
id: user.id,
} satisfies CreateCollaborationRequestBodyAccessibleByField,
role: 'editor' as CreateCollaborationRequestBodyRoleField,
} satisfies CreateCollaborationRequestBody);client.user_collaborations.create_collaboration(
CreateCollaborationItem(type=CreateCollaborationItemTypeField.FOLDER, id=folder.id),
CreateCollaborationAccessibleBy(
type=CreateCollaborationAccessibleByTypeField.USER, id=user.id
),
CreateCollaborationRole.EDITOR,
)await client.UserCollaborations.CreateCollaborationAsync(requestBody: new CreateCollaborationRequestBody(item: new CreateCollaborationRequestBodyItemField() { Type = CreateCollaborationRequestBodyItemTypeField.Folder, Id = folder.Id }, accessibleBy: new CreateCollaborationRequestBodyAccessibleByField(type: CreateCollaborationRequestBodyAccessibleByTypeField.User) { Id = user.Id }, role: CreateCollaborationRequestBodyRoleField.Editor));try await client.userCollaborations.createCollaboration(requestBody: CreateCollaborationRequestBody(item: CreateCollaborationRequestBodyItemField(type: CreateCollaborationRequestBodyItemTypeField.folder, id: folder.id), accessibleBy: CreateCollaborationRequestBodyAccessibleByField(type: CreateCollaborationRequestBodyAccessibleByTypeField.user, id: user.id), role: CreateCollaborationRequestBodyRoleField.editor))client.getUserCollaborations().createCollaboration(new CreateCollaborationRequestBody(new CreateCollaborationRequestBodyItemField.Builder().type(CreateCollaborationRequestBodyItemTypeField.FOLDER).id(folder.getId()).build(), new CreateCollaborationRequestBodyAccessibleByField.Builder(CreateCollaborationRequestBodyAccessibleByTypeField.USER).id(user.getId()).build(), CreateCollaborationRequestBodyRoleField.EDITOR))await client.UserCollaborations.CreateCollaborationAsync(requestBody: new CreateCollaborationRequestBody(item: new CreateCollaborationRequestBodyItemField() { Type = CreateCollaborationRequestBodyItemTypeField.Folder, Id = folder.Id }, accessibleBy: new CreateCollaborationRequestBodyAccessibleByField(type: CreateCollaborationRequestBodyAccessibleByTypeField.User) { Id = user.Id }, role: CreateCollaborationRequestBodyRoleField.Editor));await client.userCollaborations.createCollaboration({
item: {
type: 'folder' as CreateCollaborationRequestBodyItemTypeField,
id: folder.id,
} satisfies CreateCollaborationRequestBodyItemField,
accessibleBy: {
type: 'user' as CreateCollaborationRequestBodyAccessibleByTypeField,
id: user.id,
} satisfies CreateCollaborationRequestBodyAccessibleByField,
role: 'editor' as CreateCollaborationRequestBodyRoleField,
} satisfies CreateCollaborationRequestBody);転送先ユーザーとしてコラボレーションIDを取得
次の手順では、コラボレーション情報を取得するリクエストをtransfer_to_userアカウントとして実行します。返されるコラボレーションオブジェクトには、最後の手順で使用するコラボレーションIDが含まれます。
transfer_to_userアカウントとして呼び出しを実行し、コラボレーションを取得エンドポイントを使用して、転送するファイルまたはフォルダのIDのコラボレーションを取得します。コラボレーションIDをキャプチャします。
転送元ユーザーを所有者として削除
最後の手順は、ファイルまたはフォルダの所有者としてtransfer_from_userアカウントを削除することです。これは、コラボレーションを削除エンドポイントを使用して行います。
transfer_to_userアカウントとして呼び出しを実行し、ファイルまたはフォルダのコラボレータとしてtransfer_from_userを削除します。
これにより、ファイルまたはフォルダの所有者はtransfer_to_userアカウントになり、transfer_from_userアカウントはアクセスできなくなります。