Box Developerドキュメント

Box Developerドキュメントの新しいベータ版サイトがまもなくリリースされる予定です。最新の開発者向けガイド、APIリファレンス、AI搭載の検索により、Boxを使用した迅速な開発をサポートします。更新情報については今しばらくお待ちください。

ファイルとフォルダの転送

ファイルとフォルダの転送

ユーザーアカウントのプロビジョニング解除における一般的な要件の1つが、ユーザーアカウント内に保存されているすべてのファイルとフォルダを別のユーザーアカウント、またはサービスアカウントなどの長期保存用の場所に転送することです。

Box内でこれを実行するのに使用される一般的な方法は以下の2つです。

  • すべてのコンテンツをあるユーザーから別のユーザーに直接移動する、所有フォルダの移動APIを使用する。
  • コラボレーション転送の方法を使用して、一度に1つのファイルまたはフォルダの所有権を、あるユーザーから別のユーザーに変更する。

転送中は、ユーザーが所有するファイルにアクセスできなくなります。また、移動中もユーザーが所有する共有コンテンツにアクセスできない可能性があります。

コンテンツの量によっては、この操作にかなりの時間がかかる場合があります。

所有フォルダの移動APIの使用

所有フォルダの移動エンドポイントは、あるユーザーが所有するコンテンツ全体を別のユーザーに移動することを目的に設計されています。

所有フォルダの移動APIは、同期プロセスとして実行されるため、ソースユーザーのフォルダ全体に多数の項目がある場合、レスポンスが遅くなる可能性があります。

転送エンドポイントを呼び出すには、転送元のユーザーIDと転送先のユーザーIDを指定します。

Node/TypeScript v10
await client.transfer.transferOwnedFolder(
  sourceUser.id,
  {
    ownedBy: {
      id: targetUser.id,
    } satisfies TransferOwnedFolderRequestBodyOwnedByField,
  } satisfies TransferOwnedFolderRequestBody,
  {
    queryParams: { notify: false } satisfies TransferOwnedFolderQueryParams,
  } satisfies TransferOwnedFolderOptionalsInput,
);
Python v10
client.transfer.transfer_owned_folder(
    source_user.id, TransferOwnedFolderOwnedBy(id=target_user.id), notify=False
)
.NET v10
await client.Transfer.TransferOwnedFolderAsync(userId: sourceUser.Id, requestBody: new TransferOwnedFolderRequestBody(ownedBy: new TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.Id)), queryParams: new TransferOwnedFolderQueryParams() { Notify = false });
Swift v10
try await client.transfer.transferOwnedFolder(userId: sourceUser.id, requestBody: TransferOwnedFolderRequestBody(ownedBy: TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.id)), queryParams: TransferOwnedFolderQueryParams(notify: false))
Java v10
client.getTransfer().transferOwnedFolder(sourceUser.getId(), new TransferOwnedFolderRequestBody(new TransferOwnedFolderRequestBodyOwnedByField(targetUser.getId())), new TransferOwnedFolderQueryParams.Builder().notify(false).build())
.NET v6
await client.Transfer.TransferOwnedFolderAsync(userId: sourceUser.Id, requestBody: new TransferOwnedFolderRequestBody(ownedBy: new TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.Id)), queryParams: new TransferOwnedFolderQueryParams() { Notify = false });
Node v4
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
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"
     }'
Node/TypeScript v10
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);
Python v10
client.user_collaborations.create_collaboration(
    CreateCollaborationItem(type=CreateCollaborationItemTypeField.FOLDER, id=folder.id),
    CreateCollaborationAccessibleBy(
        type=CreateCollaborationAccessibleByTypeField.USER, id=user.id
    ),
    CreateCollaborationRole.EDITOR,
)
.NET v10
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));
Swift v10
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))
Java v10
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))
.NET v6
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));
Node v4
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アカウントはアクセスできなくなります。