PHPackages                             2amigos/php-box-view - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. 2amigos/php-box-view

ActiveLibrary[API Development](/categories/api)

2amigos/php-box-view
====================

PHP wrapper for the Box View API

1.0.1(8y ago)030BSDPHPPHP &gt;=5.4

Since Apr 22Pushed 8y ago2 watchersCompare

[ Source](https://github.com/2amigos/php-box-view)[ Packagist](https://packagist.org/packages/2amigos/php-box-view)[ Docs](https://developers.box.com/view/)[ RSS](/packages/2amigos-php-box-view/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

php-box-view
============

[](#php-box-view)

Introduction
------------

[](#introduction)

php-box-view is a PHP wrapper for the Box View API. The Box View API lets you upload documents and then generate secure and customized viewing sessions for them. Our API is based on REST principles and generally returns JSON encoded responses, and in PHP are converted to associative arrays unless otherwise noted.

For more information about the Box View API, see the [API docs at developers.box.com](https://developers.box.com/view/).

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP 5.4 or newer

### Install with Composer

[](#install-with-composer)

We recommend installing `php-box-view` using [Composer](https://getcomposer.org).

If you don't have Composer, you can install it from the command line:

```
curl -sS https://getcomposer.org/installer | php
```

Use Composer to install the latest stable version:

```
composer require crocodoc/php-box-view
```

Make sure to add this package to your composer.json file. And if you aren't doing this already, require Composer's autoloader from your project:

```
require __DIR__ . '/path/to/root/vendor/autoload.php';
```

### Install without Composer

[](#install-without-composer)

Download the library and put it in your project. You will also need to download and include [Guzzle](https://github.com/guzzle/guzzle).

From the file you want to include it from, just use the autoload file:

```
require __DIR__ . '/path/to/box/view/autoload.php';
```

Getting Started
---------------

[](#getting-started)

### Get an API Key

[](#get-an-api-key)

[Create a Box Application](https://app.box.com/developers/services/edit/) to get an API key. Enter your application name, click the option for `Box View`, and click `Create Application`. Then click `Configure your application`.

You can find your API key where it says `View API Key`.

In the future, if you need to return to this page, go to [Box Developers &gt; My Applications](https://app.box.com/developers/services) and click on any of your Box View apps.

### Examples

[](#examples)

You can see a number of examples on how to use this library in `examples/examples.php`. These examples are interactive and you can run this file to see `php-box-view` in action.

To run these examples, open up `examples/examples.php` and change this line to show your API key:

```
$exampleApiKey = 'YOUR_API_KEY';
```

Save the file, make sure the `examples/files` directory is writable, and then run `examples/examples.php`:

```
php examples/examples.php
```

You should see 17 examples run with output in your terminal. You can inspect the `examples/examples.php` code to see each API call being used.

### Your Code

[](#your-code)

To start using `php-box-view` in your code, set your API key:

```
$boxView = new Box\View\Client('YOUR_API_KEY');
```

Tests
-----

[](#tests)

First make sure you're running Composer and that you've run `composer install`.

Run the tests:

```
./vendor/bin/phpunit
```

Support
-------

[](#support)

Please use GitHub's issue tracker for API library support.

Usage
-----

[](#usage)

### Fields

[](#fields)

All fields are accessed using getters. You can find a list of these fields below in their respective sections.

### Errors

[](#errors)

Errors are handled by throwing exceptions. We throw instances of `Box\View\BoxViewException`.

Note that any Box View API call can throw an exception. When making API calls, put them in a try/catch block. You can see `examples/examples.php` to see working code for each method using try/catch blocks.

### Document

[](#document)

#### Fields

[](#fields-1)

FieldGetterid$document-&gt;id()createdAt$document-&gt;createdAt()name$document-&gt;name()status$document-&gt;status()#### Upload from File

[](#upload-from-file)

To upload a document from a local file, use `$boxView->uploadFile()`. Pass in a file resource, and also an optional associative array of other params. This function returns a `Box\View\Document` object.

```
// without options
$handle     = fopen($filename, 'r');
$document   = $boxView->uploadFile($handle);

// with options
$handle   = fopen($filename, 'r');
$document = $boxView->uploadFile($handle, [
    'name'       => 'Test File',
    'thumbnails' => ['100x100', '200x200'],
    'nonSvg'     => true,
]);
```

The response looks like this:

```
object(Box\View\Document)#54 (5) {
  ["createdAt":"Box\View\Document":private]=>
  string(25) "2015-03-11T07:48:52+00:00"
  ["id":"Box\View\Document":private]=>
  string(32) "0971e7674469406dba53254fcbb11d05"
  ["name":"Box\View\Document":private]=>
  string(11) "Sample File"
  ["status":"Box\View\Document":private]=>
  string(6) "queued"
}
```

#### Upload by URL

[](#upload-by-url)

To upload a document by a URL, use `$boxView->uploadUrl()`. Pass in the URL of the file you want to upload, and also an optional associative array of other params. This function returns a `Box\View\Document` object.

```
// without options
$document = $boxView->uploadUrl($url);

// with options
$document = $boxView->uploadUrl($url, [
    'name'       => 'Test File',
    'thumbnails' => ['100x100', '200x200'],
    'nonSvg'     => true,
]);
```

The response looks like this:

```
object(Box\View\Document)#54 (5) {
  ["createdAt":"Box\View\Document":private]=>
  string(25) "2015-03-11T07:48:52+00:00"
  ["id":"Box\View\Document":private]=>
  string(32) "0971e7674469406dba53254fcbb11d05"
  ["name":"Box\View\Document":private]=>
  string(11) "Sample File"
  ["status":"Box\View\Document":private]=>
  string(6) "queued"
}
```

#### Get Document

[](#get-document)

To get a document, use `$boxView->getDocument()`. Pass in the ID of the document you want to get. This function returns a `Box\View\Document` object.

```
$document = $boxView->getDocument($documentId);
```

The response looks like this:

```
object(Box\View\Document)#54 (5) {
  ["createdAt":"Box\View\Document":private]=>
  string(25) "2015-03-11T07:48:52+00:00"
  ["id":"Box\View\Document":private]=>
  string(32) "0971e7674469406dba53254fcbb11d05"
  ["name":"Box\View\Document":private]=>
  string(11) "Sample File"
  ["status":"Box\View\Document":private]=>
  string(6) "queued"
}
```

#### Find

[](#find)

To get a list of documents you've uploaded, use `$boxView->findDocuments()`. Pass an optional associative array of parameters you want to filter by. This function returns an array of `Box\View\Document` objects matching the request.

```
// without options
$documents = $boxView->findDocuments();

// with options
$start     = date('c', strtotime('-2 weeks'));
$end       = date('c', strtotime('-1 week'));
$documents = $boxView->findDocuments([
    'limit'         => 10,
    'createdAfter'  => $start,
    'createdBefore' => $end,
]);
```

The response looks like this:

```
array(2) {
  [0]=>
  object(Box\View\Document)#31 (5) {
    ["createdAt":"Box\View\Document":private]=>
    string(25) "2015-03-11T07:50:41+00:00"
    ["id":"Box\View\Document":private]=>
    string(32) "f2f9be2249e2490da3b0a040d5eaae58"
    ["name":"Box\View\Document":private]=>
    string(14) "Sample File #2"
    ["status":"Box\View\Document":private]=>
    string(10) "processing"
  }
  [1]=>
  object(Box\View\Document)#55 (5) {
    ["createdAt":"Box\View\Document":private]=>
    string(25) "2015-03-11T07:50:40+00:00"
    ["id":"Box\View\Document":private]=>
    string(32) "966f747cb77b4f1b805cc594c9fdd30c"
    ["name":"Box\View\Document":private]=>
    string(11) "Sample File"
    ["status":"Box\View\Document":private]=>
    string(4) "done"
  }
}
```

#### Download

[](#download)

To download a document, use `$document->download()`. This function returns the contents of the downloaded file.

```
$contents = $document->download();
$filename = __DIR__ . '/files/new-file.doc';
$handle   = fopen($filename, 'w');

fwrite($handle, $contents);
fclose($handle);
```

The response is just a giant string representing the data of the file.

#### Thumbnail

[](#thumbnail)

To download a document, use `$document->thumbnail()`. Pass in the width and height in pixels of the thumbnail you want to download. This function returns the contents of the downloaded thumbnail.

```
$thumbnailContents = $document->thumbnail(100, 100);
$filename          = __DIR__ . '/files/new-thumbnail.png';
$handle            = fopen($filename, 'w');

fwrite($handle, $thumbnailContents);
fclose($handle);
```

The response is just a giant string representing the data of the file.

#### Update

[](#update)

To update the metadata of a document, use `$document->update()`. Pass in the fields you want to update. Right now, only the `name` field is supported. This function returns a boolean of whether the file was updated or not.

```
$updated = $document->update(['name' => 'Updated Name']);

if ($updated) {
    // do something
} else {
    // do something else
}
```

The response looks like this:

```
bool(true)
```

#### Delete

[](#delete)

To delete a document, use `$document->delete()`. This function returns a boolean of whether the file was deleted or not.

```
$deleted = $document->delete();

if ($deleted) {
    // do something
} else {
    // do something else
}
```

The response looks like this:

```
bool(true)
```

### Session

[](#session)

#### Fields

[](#fields-2)

FieldGetterid$session-&gt;id()document$session-&gt;document()expiresAt$session-&gt;expiresAt()assetsUrl$session-&gt;assetsUrl()realtimeUrl$session-&gt;realtimeUrl()viewUrl$session-&gt;viewUrl()#### Create

[](#create)

To create a session, use `$document->createSession()`. Pass in an optional associative array of params. This function returns a `Box\View\Session` object.

```
// without options
$session = $document->createSession();

// with options
$session = $document->createSession([
    'expiresAt'        => date('c', strtotime('+10 min')),
    'isDownloadable'   => true,
    'isTextSelectable' => false,
]);
```

The response looks like this:

```
object(Box\View\Session)#41 (5) {
  ["document":"Box\View\Session":private]=>
  object(Box\View\Document)#27 (5) {
    ...
  }
  ["id":"Box\View\Session":private]=>
  string(32) "d1b8c35a69da43fbb2e978e99589114a"
  ["expiresAt":"Box\View\Session":private]=>
  string(25) "2015-03-11T08:53:23+00:00"
  ["urls":"Box\View\Session":private]=>
  array(3) {
    ["assets"]=>
    string(76) "https://view-api.box.com/1/sessions/d1b8c35a69da43fbb2e978e99589114a/assets/"
    ["realtime"]=>
    string(61) "https://view-api.box.com/sse/d1b8c35a69da43fbb2e978e99589114a"
    ["view"]=>
    string(73) "https://view-api.box.com/1/sessions/d1b8c35a69da43fbb2e978e99589114a/view"
  }
}
```

#### Delete

[](#delete-1)

To delete a session, use `$session->delete()`. This function returns a boolean of whether the session was deleted or not.

```
$deleted = $session->delete();

if ($deleted) {
    // do something
} else {
    // do something else
}
```

The response looks like this:

```
bool(true)
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~893 days

Total

2

Last Release

3141d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/566016?v=4)[Antonio Ramirez](/maintainers/tonydspaniard)[@tonydspaniard](https://github.com/tonydspaniard)

---

Top Contributors

[![bgoldman](https://avatars.githubusercontent.com/u/160560?v=4)](https://github.com/bgoldman "bgoldman (50 commits)")[![radzserg](https://avatars.githubusercontent.com/u/293785?v=4)](https://github.com/radzserg "radzserg (17 commits)")[![codyebberson](https://avatars.githubusercontent.com/u/749094?v=4)](https://github.com/codyebberson "codyebberson (6 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (6 commits)")[![nurikabe](https://avatars.githubusercontent.com/u/83678?v=4)](https://github.com/nurikabe "nurikabe (1 commits)")

---

Tags

apicrocodocboxbox-view

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/2amigos-php-box-view/health.svg)

```
[![Health](https://phpackages.com/badges/2amigos-php-box-view/health.svg)](https://phpackages.com/packages/2amigos-php-box-view)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[get-stream/stream-chat

A PHP client for Stream Chat (https://getstream.io/chat/)

301.8M2](/packages/get-stream-stream-chat)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
