- すべてのコンテンツをあるユーザーから別のユーザーに直接移動する、APIを使用する。
- コラボレーション転送の方法を使用して、一度に1つのファイルまたはフォルダの所有権を、あるユーザーから別のユーザーに変更する。
転送中は、ユーザーが所有するファイルにアクセスできなくなります。また、移動中もユーザーが所有する共有コンテンツにアクセスできない可能性があります。コンテンツの量によっては、この操作にかなりの時間がかかる場合があります。
所有フォルダの移動APIの使用
は、あるユーザーが所有するコンテンツ全体を別のユーザーに移動することを目的に設計されています。所有フォルダの移動APIは、同期プロセスとして実行されるため、ソースユーザーのフォルダ全体に多数の項目がある場合、レスポンスが遅くなる可能性があります。
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())
String sourceUserID = "11111";
String destinationUserID = "22222";
BoxUser sourceUser = new BoxUser(api, sourceUserID);
BoxFolder.Info transferredFolderInfo = sourceUser.transferContent(destinationUserID);
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}')
var sourceUserId = "33333";
var destinationUserId = "44444";
BoxFolder movedFolder = await client.MoveUserFolderAsync(sourceUserId, destinationUserId);
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' }
*/
});
コラボレーション転送の使用
コラボレーション転送は、を使用して、単一のファイルまたはフォルダの所有権をあるユーザーから別のユーザーに即座に変更するプロセスです。この方法では、単一のファイルまたはフォルダの所有権を即時に転送します。ただし、この方法でルート (すべてのファイルおよびフォルダ) を別のユーザーに転送することはできません。
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))
BoxCollaborator user = new BoxUser(api, "user-id")
BoxFolder folder = new BoxFolder(api, "folder-id");
folder.collaborate(user, BoxCollaboration.Role.EDITOR);
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}"')
// 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);
// 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' } }
*/
});
転送先ユーザーとしてコラボレーションIDを取得
次の手順では、コラボレーション情報を取得するリクエストをtransfer_to_userアカウントとして実行します。返されるコラボレーションオブジェクトには、最後の手順で使用するコラボレーションIDが含まれます。
transfer_to_userアカウントとして呼び出しを実行し、を使用して、転送するファイルまたはフォルダのIDのコラボレーションを取得します。コラボレーションIDをキャプチャします。
curl -i -X GET "https://api.box.com/2.0/collaborations/1234" \
-H "authorization: Bearer <ACCESS_TOKEN>"
await client.userCollaborations.getCollaborationById(collaborationId);
client.user_collaborations.get_collaboration_by_id(collaboration_id)
await client.UserCollaborations.GetCollaborationByIdAsync(collaborationId: collaborationId);
try await client.userCollaborations.getCollaborationById(collaborationId: collaborationId)
client.getUserCollaborations().getCollaborationById(collaborationId)
await client.UserCollaborations.GetCollaborationByIdAsync(collaborationId: collaborationId);
await client.userCollaborations.getCollaborationById(collaborationId);
転送元ユーザーを所有者として削除
最後の手順は、ファイルまたはフォルダの所有者としてtransfer_from_userアカウントを削除することです。これは、を使用して行います。
transfer_to_userアカウントとして呼び出しを実行し、ファイルまたはフォルダのコラボレータとしてtransfer_from_userを削除します。
curl -i -X DELETE "https://api.box.com/2.0/collaborations/1234" \
-H "authorization: Bearer <ACCESS_TOKEN>"
await client.userCollaborations.deleteCollaborationById(collaborationId);
client.user_collaborations.delete_collaboration_by_id(collaboration_id)
await client.UserCollaborations.DeleteCollaborationByIdAsync(collaborationId: collaborationId);
try await client.userCollaborations.deleteCollaborationById(collaborationId: collaborationId)
client.getUserCollaborations().deleteCollaborationById(collaborationId)
await client.UserCollaborations.DeleteCollaborationByIdAsync(collaborationId: collaborationId);
await client.userCollaborations.getCollaborationById(collaborationId);
transfer_to_userアカウントになり、transfer_from_userアカウントはアクセスできなくなります。
