Box Developerドキュメント

BoxWorks 2024でコンテンツとAIの可能性について紹介します。

詳細を表示

フォルダの作成

フォルダの作成

Box上でフォルダを作成するには、新しいフォルダのnameと、新しいフォルダの作成先になるparentフォルダのidをAPIに渡す必要があります。

cURL
curl -i -X POST "https://api.box.com/2.0/folders" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "name": "New Folder",
       "parent": {
         "id": "0"
       }
     }'
TypeScript Gen
await parentClient.folders.createFolder({
  name: getUuid(),
  parent: { id: '0' } satisfies CreateFolderRequestBodyParentField,
} satisfies CreateFolderRequestBody);
Python Gen
parent_client.folders.create_folder(get_uuid(), CreateFolderParent(id="0"))
.NET Gen
await parentClient.Folders.CreateFolderAsync(requestBody: new CreateFolderRequestBody(name: Utils.GetUUID(), parent: new CreateFolderRequestBodyParentField(id: "0")));
Java
BoxFolder parentFolder = new BoxFolder(api, "id");
BoxFolder.Info childFolderInfo = parentFolder.createFolder("Child Folder Name");
Python
subfolder = client.folder('0').create_subfolder('My Stuff')
print(f'Created subfolder with ID {subfolder.id}')
.NET
// Create a new folder in the user's root folder
var folderParams = new BoxFolderRequest()
{
    Name = "New folder",
    Parent = new BoxRequestEntity()
    {
        Id = "0"
    }
};
BoxFolder folder = await client.FoldersManager.CreateAsync(folderParams);
Node
client.folders.create('0', 'New Folder')
    .then(folder => {
        /* folder -> {
            type: 'folder',
            id: '123456',
            sequence_id: '0',
            etag: '0',
            name: 'New Folder',
            created_at: '2012-12-12T10:53:43-08:00',
            modified_at: '2012-12-12T11:15:04-08:00',
            description: '',
            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: '22222',
                name: 'Example User'
                login: 'user@example.com' },
            modified_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            owned_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            shared_link: null,
            parent: 
            { type: 'folder',
                id: '0',
                sequence_id: null,
                etag: null,
                name: 'All Files' },
            item_status: 'active',
            item_collection: 
            { total_count: 0,
                entries: [],
                offset: 0,
                limit: 100 } }
        */
    });
iOS
client.folders.create(name: "New Folder", parentId: "22222") { (result: Result<Folder, BoxSDKError>) in
    guard case let .success(folder) = result else {
        print("Error creating folder")
        return
    }

    print("Created folder \"\(folder.name)\" inside of folder \"\(folder.parent?.name)\"")
}

名前に関する制約事項

フォルダ名にはいくつかの制限があります。印字不可能なASCII文字、スラッシュ、バックスラッシュ (/\) を含む名前のほか、末尾にスペースを含む名前は禁止されています。

また、.および..は予約済みの名前であるため、使用できません。