> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

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

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = localizeLink(href);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

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

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

* すべてのコンテンツをあるユーザーから別のユーザーに直接移動する、<Link href="/reference/put-users-id-folders-0">所有フォルダの移動</Link>APIを使用する。
* コラボレーション転送の方法を使用して、一度に1つのファイルまたはフォルダの所有権を、あるユーザーから別のユーザーに変更する。

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

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

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

<Link href="/reference/put-users-id-folders-0">所有フォルダの移動エンドポイント</Link>は、あるユーザーが所有するコンテンツ全体を別のユーザーに移動することを目的に設計されています。

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

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

<CodeGroup>
  ```typescript Node/TypeScript v10 theme={null}
  await client.transfer.transferOwnedFolder(
    sourceUser.id,
    {
      ownedBy: {
        id: targetUser.id,
      } satisfies TransferOwnedFolderRequestBodyOwnedByField,
    } satisfies TransferOwnedFolderRequestBody,
    {
      queryParams: { notify: false } satisfies TransferOwnedFolderQueryParams,
    } satisfies TransferOwnedFolderOptionalsInput,
  );
  ```

  ```python Python v10 theme={null}
  client.transfer.transfer_owned_folder(
      source_user.id, TransferOwnedFolderOwnedBy(id=target_user.id), notify=False
  )
  ```

  ```cs .NET v10 theme={null}
  await client.Transfer.TransferOwnedFolderAsync(userId: sourceUser.Id, requestBody: new TransferOwnedFolderRequestBody(ownedBy: new TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.Id)), queryParams: new TransferOwnedFolderQueryParams() { Notify = false });
  ```

  ```swift Swift v10 theme={null}
  try await client.transfer.transferOwnedFolder(userId: sourceUser.id, requestBody: TransferOwnedFolderRequestBody(ownedBy: TransferOwnedFolderRequestBodyOwnedByField(id: targetUser.id)), queryParams: TransferOwnedFolderQueryParams(notify: false))
  ```

  ```java Java v10 theme={null}
  client.getTransfer().transferOwnedFolder(sourceUser.getId(), new TransferOwnedFolderRequestBody(new TransferOwnedFolderRequestBodyOwnedByField(targetUser.getId())), new TransferOwnedFolderQueryParams.Builder().notify(false).build())
  ```

  ```java Java v5 theme={null}
  String sourceUserID = "11111";
  String destinationUserID = "22222";
  BoxUser sourceUser = new BoxUser(api, sourceUserID);
  BoxFolder.Info transferredFolderInfo = sourceUser.transferContent(destinationUserID);
  ```

  ```python Python v4 theme={null}
  source_user_id = '33333'
  destination_user_id = '44444'

  user = client.user(source_user_id)
  destination_user = client.user(destination_user_id)

  folder = user.transfer_content(destination_user)
  print(f'Created new folder "{folder.name}" in the account of user {destination_user.id}')
  ```

  ```cs .NET v6 theme={null}
  var sourceUserId = "33333";
  var destinationUserId = "44444";
  BoxFolder movedFolder = await client.MoveUserFolderAsync(sourceUserId, destinationUserId);
  ```

  ```javascript Node v4 theme={null}
  var sourceUserID = '33333';
  var destinationUserID = '44444';
  client.enterprise.transferUserContent(sourceUserID, destinationUserID)
  	.then(movedFolder => {
  		/* movedFolder -> {
  			type: 'folder',
  			id: '123456789',
  			sequence_id: '1',
  			etag: '1',
  			name: 'Other User's Files and Folders',
  			created_at: '2018-04-23T11:00:07-07:00',
  			modified_at: '2018-04-23T11:00:07-07:00',
  			description: 'This folder contains files previously owned by Other User, and were transferred to you by your enterprise administrator. If you have any questions, please contact Enterprise Admin (admin@example.com).',
  			size: 0,
  			path_collection: 
  			{ total_count: 1,
  				entries: 
  				[ { type: 'folder',
  					id: '0',
  					sequence_id: null,
  					etag: null,
  					name: 'All Files' } ] },
  			created_by: 
  			{ type: 'user',
  				id: '99999',
  				name: 'Enterprise Admin',
  				login: 'admin@example.com' },
  			modified_by: 
  			{ type: 'user',
  				id: '99999',
  				name: 'Enterprise Admin',
  				login: 'admin@example.com' },
  			trashed_at: null,
  			purged_at: null,
  			content_created_at: '2018-04-23T11:00:07-07:00',
  			content_modified_at: '2018-04-23T11:00:07-07:00',
  			owned_by: 
  			{ type: 'user',
  				id: '33333',
  				name: 'Example User',
  				login: 'user@example.com' },
  			shared_link: null,
  			folder_upload_email: null,
  			parent: 
  			{ type: 'folder',
  				id: '0',
  				sequence_id: null,
  				etag: null,
  				name: 'All Files' },
  			item_status: 'active' }
  		*/
  	});
  ```
</CodeGroup>

## コラボレーション転送の使用

コラボレーション転送は、<Link href="/reference/post-collaborations">コラボレーションエンドポイント</Link>を使用して、単一のファイルまたはフォルダの所有権をあるユーザーから別のユーザーに即座に変更するプロセスです。

<Note>
  この方法では、単一のファイルまたはフォルダの所有権を即時に転送します。ただし、この方法でルート (すべてのファイルおよびフォルダ) を別のユーザーに転送することは**できません**。
</Note>

`transfer_from_user`から`transfer_to_user`への転送の一般的なプロセスは以下の手順に従います。

### 転送先ユーザーを共同所有者として追加

最初の手順は、転送するファイルまたはフォルダへの`co-owner`アクセス権限を持つコラボレータとして、`transfer_to_user`アカウントを追加することです。

`transfer_from_user`アカウントとして呼び出しを行い、<Link href="/reference/post-collaborations">コラボレーションを追加</Link>エンドポイントを使用して`transfer_to_user`を共同所有者として追加します。

<CodeGroup>
  ```sh cURL theme={null}
  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"
       }'
  ```

  ```typescript Node/TypeScript v10 theme={null}
  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 Python v10 theme={null}
  client.user_collaborations.create_collaboration(
      CreateCollaborationItem(type=CreateCollaborationItemTypeField.FOLDER, id=folder.id),
      CreateCollaborationAccessibleBy(
          type=CreateCollaborationAccessibleByTypeField.USER, id=user.id
      ),
      CreateCollaborationRole.EDITOR,
  )
  ```

  ```cs .NET v10 theme={null}
  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 Swift v10 theme={null}
  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 Java v10 theme={null}
  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))
  ```

  ```java Java v5 theme={null}
  BoxCollaborator user = new BoxUser(api, "user-id")
  BoxFolder folder = new BoxFolder(api, "folder-id");
  folder.collaborate(user, BoxCollaboration.Role.EDITOR);
  ```

  ```python Python v4 theme={null}
  from boxsdk.object.collaboration import CollaborationRole

  user = client.user(user_id='11111')
  collaboration = client.folder(folder_id='22222').collaborate(user, CollaborationRole.VIEWER)

  collaborator = collaboration.accessible_by
  item = collaboration.item
  has_accepted = 'has' if collaboration.status == 'accepted' else 'has not'
  print(f'{collaborator.name} {has_accepted} accepted the collaboration to folder "{item.name}"')
  ```

  ```cs .NET v6 theme={null}
  // collaborate folder 11111 with user 22222
  BoxCollaborationRequest requestParams = new BoxCollaborationRequest()
  {
      Item = new BoxRequestEntity()
      {
          Type = BoxType.folder,
          Id = "11111"
      },
      Role = "editor",
      AccessibleBy = new BoxCollaborationUserRequest()
      {
          Type = BoxType.user,
          Id = "22222"
      }
  };
  BoxCollaboration collab = await client.CollaborationsManager.AddCollaborationAsync(requestParams);
  ```

  ```javascript Node v4 theme={null}
  // Invite user 123456 to collaborate on folder 987654
  client.collaborations.createWithUserID('123456', '987654', client.collaborationRoles.EDITOR)
  	.then(collaboration => {
  		/* collaboration -> {
  			type: 'collaboration',
  			id: '11111',
  			created_by: 
  			{ type: 'user',
  				id: '22222',
  				name: 'Inviting User',
  				login: 'inviter@example.com' },
  			created_at: '2016-11-16T21:33:31-08:00',
  			modified_at: '2016-11-16T21:33:31-08:00',
  			expires_at: null,
  			status: 'accepted',
  			accessible_by: 
  			{ type: 'user',
  				id: '123456',
  				name: 'Collaborator User',
  				login: 'collaborator@example.com' },
  			role: 'editor',
  			acknowledged_at: '2016-11-16T21:33:31-08:00',
  			item: 
  			{ type: 'folder',
  				id: '987654',
  				sequence_id: '0',
  				etag: '0',
  				name: 'Collaborated Folder' } }
  		*/
  	});
  ```
</CodeGroup>

### 転送先ユーザーとしてコラボレーションIDを取得

次の手順では、コラボレーション情報を取得するリクエストを`transfer_to_user`アカウントとして実行します。返されるコラボレーションオブジェクトには、最後の手順で使用するコラボレーションIDが含まれます。

`transfer_to_user`アカウントとして呼び出しを実行し、<Link href="/reference/get-collaborations-id">コラボレーションを取得エンドポイント</Link>を使用して、転送するファイルまたはフォルダのIDのコラボレーションを取得します。コラボレーションIDをキャプチャします。

<CodeGroup>
  ```sh cURL theme={null}
  curl -i -X GET "https://api.box.com/2.0/collaborations/1234" \
       -H "authorization: Bearer <ACCESS_TOKEN>"
  ```

  ```typescript Node/TypeScript v10 theme={null}
  await client.userCollaborations.getCollaborationById(collaborationId);
  ```

  ```python Python v10 theme={null}
  client.user_collaborations.get_collaboration_by_id(collaboration_id)
  ```

  ```cs .NET v10 theme={null}
  await client.UserCollaborations.GetCollaborationByIdAsync(collaborationId: collaborationId);
  ```

  ```swift Swift v10 theme={null}
  try await client.userCollaborations.getCollaborationById(collaborationId: collaborationId)
  ```

  ```java Java v10 theme={null}
  client.getUserCollaborations().getCollaborationById(collaborationId)
  ```

  ```cs .NET v6 theme={null}
  await client.UserCollaborations.GetCollaborationByIdAsync(collaborationId: collaborationId);
  ```

  ```javascript Node v4 theme={null}
  await client.userCollaborations.getCollaborationById(collaborationId);
  ```
</CodeGroup>

### 転送元ユーザーを所有者として削除

最後の手順は、ファイルまたはフォルダの所有者として`transfer_from_user`アカウントを削除することです。これは、<Link href="/reference/delete-collaborations-id">コラボレーションを削除エンドポイント</Link>を使用して行います。

`transfer_to_user`アカウントとして呼び出しを実行し、ファイルまたはフォルダのコラボレータとして`transfer_from_user`を削除します。

<CodeGroup>
  ```sh cURL theme={null}
  curl -i -X DELETE "https://api.box.com/2.0/collaborations/1234" \
       -H "authorization: Bearer <ACCESS_TOKEN>"
  ```

  ```typescript Node/TypeScript v10 theme={null}
  await client.userCollaborations.deleteCollaborationById(collaborationId);
  ```

  ```python Python v10 theme={null}
  client.user_collaborations.delete_collaboration_by_id(collaboration_id)
  ```

  ```cs .NET v10 theme={null}
  await client.UserCollaborations.DeleteCollaborationByIdAsync(collaborationId: collaborationId);
  ```

  ```swift Swift v10 theme={null}
  try await client.userCollaborations.deleteCollaborationById(collaborationId: collaborationId)
  ```

  ```java Java v10 theme={null}
  client.getUserCollaborations().deleteCollaborationById(collaborationId)
  ```

  ```cs .NET v6 theme={null}
  await client.UserCollaborations.DeleteCollaborationByIdAsync(collaborationId: collaborationId);
  ```

  ```javascript Node v4 theme={null}
  await client.userCollaborations.getCollaborationById(collaborationId);
  ```
</CodeGroup>

これにより、ファイルまたはフォルダの所有者は`transfer_to_user`アカウントになり、`transfer_from_user`アカウントはアクセスできなくなります。

<RelatedLinks
  title="関連するAPI"
  items={[
{ label: translate("Transfer owned folders"), href: "/reference/put-users-id-folders-0", badge: "PUT" }
]}
/>

<RelatedLinks
  title="関連するガイド"
  items={[
{ label: translate("Deprovision Users"), href: "/guides/users/deprovision/index", badge: "GUIDE" }
]}
/>
