This is a package can be used with PHP Project and especially integrate with Laravel. This package will serve latest Box API for App User for Enterprise to communicate server to server (eg. Uploading files to company Box behind the scene without ask grant to your web visitor, and Standard User for common user accesing their own Box account, and this will need grant access from their account.
To install into your project just run this command in terminal
composer require maengkom/boxapi
After download completed, you can add this to your app.php config file
Brightlocal\Box\BoxAPIServiceProvider::class, // Laravel 5
'Brightlocal\Box\BoxAPIServiceProvider', // Laravel 4
And if you want using Facade, you can use these two facade
/* Laravel 5 */
'BoxAU' => Brightlocal\Box\Facades\AppUserFacade::class,
'BoxSU' => Brightlocal\Box\Facades\StandardUserFacade::class,
/* Laravel 4 */
'BoxAU' => 'Brightlocal\Box\Facades\AppUserFacade',
'BoxSU' => 'Brightlocal\Box\Facades\StandardUserFacade',
BoxAU is used for App User for Enterprise box account. BoxSU is used for normal box user to access their asset in their box account.
After this don't forget to run this command below, to copy config file into config folder in Laravel 5 project
php artisan vendor:publish --tag="boxapi"
for Laravel 4, run this command in terminal
php artisan config:publish maengkom/boxapi
After install using composer, you need configure some in bootstrap/app.php
file :
// Uncomment this line below
$app->withFacades();
// Add these line below to use Facade
class_alias('Brightlocal\Box\Facades\AppUserFacade', 'BoxAU');
class_alias('Brightlocal\Box\Facades\StandardUserFacade', 'BoxSU');
// Register this service provider
$app->register('Brightlocal\Box\BoxAPIServiceProvider');
Just include the classes you want to use, pick one or both :
BoxAppUser.php // Class for App User type
BoxStandardUser.php // Class for Standard User type
and these classes are required
BoxContent.php // Trait content Box Content API Methods
Helper.php // Helper class
Please read the comment and open url box documentation to get the values for those keys.
For App User type, assumed you only need one user for your webserver communicate with your box account. Just set app_user_name and package will check if not exist, it will created for you based on name, if exist as app user on your box app, it will use user id to used in application.
When using App User class ``BoxAppUser`, you must create 2 files : private_key.pem and public_key.pem. Put private key file in the root of application, for Laravel project this should be fine because outside public folder.
There are some configuration key to set in folder
config/boxapi.php
and don't forget if you set private key file in root folder. Set this
'private_key_file' => base_path() . '/private_key.pem'
Configuration file will be put on folder
app\config\packages\maengkom\boxapi\config.php
also like Laravel 5, you may set private key file in the root project folder
'private_key_file' => base_path() . '/private_key.pem'
Configuration integrated in .env file, use the key below and find the values in you box app. Follow guideline in http://developer.box.com
BOX_AU_CLIENT_ID =
BOX_AU_CLIENT_SECRET =
BOX_REDIRECT_URI =
BOX_ENTERPRISE_ID =
BOX_APP_USER_NAME =
BOX_APP_USER_ID =
BOX_EXPIRATION = 60
BOX_KID_VALUE =
BOX_PRIVATE_KEY_FILE = private_key.pem
BOX_PASSPHRASE = 1234
For Lumen just mention the name of private key file, absolute path already set in ServiceProvider
'private_key_file' => base_path() . "/" . $_ENV['BOX_PRIVATE_KEY_FILE']
Set configuration values in array and passing the config variables in instance creation, for example :
$config = array(
'client_id' => '',
'client_secret' => '',
'redirect_uri' => '',
'enterprise_id' => '',
'app_user_name' => '',
'app_user_id' => '',
'kid_value' => '',
'passphrase' => '',
'expiration' => 60,
'private_key_file' => 'private_key.pem',
$box = new BoxAppUser($config); // For App User or
$box = new BoxStandardUser($config) // For Standard User
Set your private key file out of folder that accessible for internet user.
Below are the API methods you can used. All methods are following Box documentation.
Object | Method | Verb | Official Manual |
---|---|---|---|
Folder | getFolderInfo($id) | Get | Get Folder’s Info |
Folder | getFolderItems($id) | Get | Get Folder's Items |
Folder | createFolder($name, $parent_id) | Post | Create Folder |
Folder | updateFolder($id, $name) | Put | Update Folder |
Folder | deleteFolder($id) | Delete | Delete Folder |
Folder | copyFolder($id, $dest) | Post | Copy Folder |
Folder | createSharedLink($id) | Put | Create Shared Link |
Folder | folderCollaborations($id) | Get | Folder Collaborations |
Folder | getTrashedItems($limit, $offeset) | Get | Get Trashed Items |
Folder | getTrashedFolder($id) | Get | Get Trashed Folder |
Folder | permanentDelete($id) | Delete | Permanently Delete |
Folder | restoreFolder($id, $newName) | Get | Restore Folder |
File | getFileInfo($id) | Get | Get File's Info |
File | updateFileInfo($id, $name) | Put | Update File's Info |
File | toggleLock($id, $type, $expire, $down) | Put | Lock and Unlock |
File | downloadFile($id) | Get | Download File |
File | uploadFile($file, $parent, $name) | Post | Upload File |
File | deleteFile($id) | Delete | Delete File |
File | updateFile($name, $id) | Post | Update File |
File | copyFile($id, $dest) | Post | Copy File |
File | getThumbnail($id) | Get | Get Thumbnail |
File | getEmbedLink($id) | Get | Get Embed Link |
File | createSharedLink($id, $access) | Put | Create Shared Link |
File | getTrashedFile($id) | Get | Get Trashed File |
File | deleteFilePermanent($id) | Delete | Permanently Delete |
File | restoreItem($id, $newName) | Post | Restore File Item |
File | viewComments($id) | Get | View Comments |
File | getFileTasks($id) | Get | Get File's Tasks |
If you want to get folder information in root, call this methods :
BoxAU::getFolderInfo('0', true); // Return root folder information using App User in Json format
BoxSU::getFolderInfo('0', true); // Return root folder information using Standard User in Json format