PHPackages                             michakpl/forrest - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. michakpl/forrest

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

michakpl/forrest
================

Salesforce / Force.com REST API Client for Laravel 5

2.4.7(7y ago)029MITPHPPHP &gt;=5.6

Since May 31Pushed 7y ago1 watchersCompare

[ Source](https://github.com/michakpl/forrest)[ Packagist](https://packagist.org/packages/michakpl/forrest)[ RSS](/packages/michakpl-forrest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (57)Used By (0)

Salesforce REST API Client for Laravel 5
========================================

[](#salesforce-rest-api-client-for-laravel-5)

[![Laravel](https://camo.githubusercontent.com/232d618909dfd7f0bc8dbefecce911eb09e87dd73c4b1508e6b9641a2b9a1257/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e352d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![Latest Stable Version](https://camo.githubusercontent.com/e5a3a48d9f71c59503bc598ca520074218a79ec78868360ef60cc50ce6d111be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6d6e697068782f666f72726573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omniphx/forrest)[![Total Downloads](https://camo.githubusercontent.com/e679084b6737ece2d4bc3488579f10a164babb7b069ad2dedd2c87eef2db8b9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6d6e697068782f666f72726573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omniphx/forrest)[![License](https://camo.githubusercontent.com/6a7c803bd9e94472fd8f0739733738aa0f3999eabae4ee273fb8e1cf073b4fed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f6d6e697068782f666f72726573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omniphx/forrest)[![Build Status](https://camo.githubusercontent.com/c53f2f74263b0109ec14274cf12ef360e64aa31fdbe107730b56368498b37f0f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f6d6e697068782f666f72726573742e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/omniphx/forrest)

Salesforce/Force.com REST API client for Laravel. While it acts as more of a wrapper of the API methods, it should provide you with all the flexibility you will need to interact with the REST service.

While this package is built for Laravel, it has been decoupled so that it can be extended into any framework or vanilla PHP application. Currently the only support is for Larevel 4, 5 and Lumen.

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

[](#installation)

> If you are upgrading to Version 2.0, be sure to re-publish your config file.

Forrest can be installed through composer. Open your `composer.json` file and add the following to the `require` key:

```
"omniphx/forrest": "2.*"
```

Next run `composer update` from the command line to install the package.

### Laravel Installation

[](#laravel-installation)

Add the service provider and alias to your `config/app.php` file:

```
Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider::class
'Forrest' => Omniphx\Forrest\Providers\Laravel\Facades\Forrest::class
```

> For Laravel 4, add `Omniphx\Forrest\Providers\Laravel4\ForrestServiceProvider` in `app/config/app.php`. Alias will remain the same.

### Lumen Installation

[](#lumen-installation)

```
class_alias('Omniphx\Forrest\Providers\Laravel\Facades\Forrest', 'Forrest');
$app->register(Omniphx\Forrest\Providers\Lumen\ForrestServiceProvider::class);
$app->configure('forrest');
$app->withFacades();
```

Then you'll utilize the Lumen service provider by registering it in the `bootstrap/app.php` file.

### Configuration

[](#configuration)

You will need a configuration file to add your credentials. Publish a config file using the `artisan` command:

```
php artisan vendor:publish
```

You can find the config file in: `config/forrest.php`

> For Lumen, you should copy the config file from `src/config/config.php` and add it to a `forrest.php` configuration file under a config directory in the root of your application.

> For Laravel 4, run `php artisan config:publish omniphx/forrest`. It will be found in `app/config/omniphx/forrest/config.php`

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

[](#getting-started)

### Setting up a Connected App

[](#setting-up-a-connected-app)

1. Log into to your Salesforce org
2. Click on Setup in the upper right-hand menu
3. Under Build click `Create > Apps`
4. Scroll to the bottom and click `New` under Connected Apps.
5. Enter the following details for the remote application:
    - Connected App Name
    - API Name
    - Contact Email
    - Enable OAuth Settings under the API dropdown
    - Callback URL
    - Select access scope (If you need a refresh token, specify it here)
6. Click `Save`

After saving, you will now be given a Consumer Key and Consumer Secret. Update your config file with values for `consumerKey`, `consumerSecret`, `loginURL` and `callbackURI`.

### Setup

[](#setup)

Creating authentication routes

##### Web Server authentication flow

[](#web-server-authentication-flow)

```
Route::get('/authenticate', function()
{
    return Forrest::authenticate();
});

Route::get('/callback', function()
{
    Forrest::callback();

    return Redirect::to('/');
});
```

##### Username-Password authentication flow

[](#username-password-authentication-flow)

With the Username Password flow, you can directly authenticate with the `Forrest::authenticate()` method.

> To use this authentication you must add your username, and password to the config file. Security token might need to be ammended to your password unless your IP address is whitelisted.

```
Route::get('/authenticate', function()
{
    Forrest::authenticate();
    return Redirect::to('/');
});
```

#### Custom login urls

[](#custom-login-urls)

Sometimes users will need to connect to a sandbox or custom url. To do this, simply pass the url as an argument for the authenticatation method:

```
Route::get('/authenticate', function()
{
    $loginURL = 'https://test.salesforce.com';

    return Forrest::authenticate($loginURL);
});
```

> Note: You can specify a default login URL in your config file.

Basic usage
-----------

[](#basic-usage)

After authentication, your app will store an encrypted authentication token which can be used to make API requests.

### Query a record

[](#query-a-record)

```
Forrest::query('SELECT Id FROM Account');
```

Result:

```
{
    "totalSize": 2,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Account",
                "url": "\/services\/data\/v30.0\/sobjects\/Account\/001i000000xxx"
            },
            "Id": "001i000000xxx"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "\/services\/data\/v30.0\/sobjects\/Account\/001i000000xxx"
            },
            "Id": "001i000000xxx"
        }
    ]
}
```

If you are querying more than 2000 records, you response will include:

```
"nextRecordsUrl" : "/services/data/v20.0/query/01gD0000002HU6KIAW-2000"

```

Simply, call `Forrest::next($nextRecordsUrl)` to return the next 2000 records.

### Create a new record

[](#create-a-new-record)

Records can be created using the following format.

```
$body = ['Name' => 'New Account'];
Forrest::sobjects('Account',[
    'method' => 'post',
    'body'   => $body]);
```

### Update a record

[](#update-a-record)

Update a record with the PUT method.

```
$body = [
    'Name'  => 'Acme'
    'Phone' => '555-555-5555'];

Forrest::sobjects('Account/001i000000xxx',[
    'method' => 'put',
    'body'   => $body]);
```

### Upsert a record

[](#upsert-a-record)

Update a record with the PATCH method and if the external Id doesn't exist, it will insert a new record.

```
$body = [
    'Phone' => '555-555-5555',
    'External_Id__c' => 'XYZ1234'];

Forrest::sobjects('Account',[
    'method' => 'patch',
    'body'   => $body]);
```

### Delete a record

[](#delete-a-record)

Delete a record with the DELETE method.

```
Forrest::sobjects('Account/001i000000xxx', ['method' => 'delete']);
```

### XML format

[](#xml-format)

Change the request/response format to XML with the `format` key or make it default in your config file.

```
Forrest::sobjects('Account',['format'=>'xml']);
```

API Requests
------------

[](#api-requests)

With the exception of the `search` and `query` resources, all resources are requested dynamically using method overloading.

First, determine which resources you have access to by calling:

```
Forrest::resources();
```

Result:

```
Array
(
    [sobjects] => /services/data/v30.0/sobjects
    [connect] => /services/data/v30.0/connect
    [query] => /services/data/v30.0/query
    [theme] => /services/data/v30.0/theme
    [queryAll] => /services/data/v30.0/queryAll
    [tooling] => /services/data/v30.0/tooling
    [chatter] => /services/data/v30.0/chatter
    [analytics] => /services/data/v30.0/analytics
    [recent] => /services/data/v30.0/recent
    [process] => /services/data/v30.0/process
    [identity] => https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000aaaaAAA
    [flexiPage] => /services/data/v30.0/flexiPage
    [search] => /services/data/v30.0/search
    [quickActions] => /services/data/v30.0/quickActions
    [appMenu] => /services/data/v30.0/appMenu
)
```

Next, call resources by referring to the specified key. For instance:

```
Forrest::theme();
```

or

```
Forrest::appMenu();
```

Resource urls can be extended by passing additional parameters into the first argument:

```
Forrest::sobjects('Account/describe/approvalLayouts/');
```

You can also add optional parameters to requests:

```
Forrest::theme(['format'=>'xml']);
```

### Additional API Requests

[](#additional-api-requests)

#### Refresh

[](#refresh)

If a refresh token is set, the server can refresh the access token on the user's behalf. Refresh tokens are only for the Web Server flow.

```
Forrest::refresh();
```

> If you need a refresh token, be sure to specify this under `access scope` in your [Connected App](#setting-up-connected-app). You can also specify this in your configuration file by adding `'scope' => 'full refresh_token'`. Setting scope access in the config file is optional, the default scope access is determined by your Salesforce org.

#### Revoke

[](#revoke)

This will revoke the authorization token. The session will continue to store a token, but it will become invalid.

```
Forrest::revoke();
```

#### Versions

[](#versions)

Returns all currently supported versions. Includes the verison, label and link to each version's root:

```
Forrest::versions();
```

#### Resources

[](#resources)

Returns list of available resources based on the logged in user's permission and API version.

```
Forrest::resources();
```

#### Identity

[](#identity)

Returns information about the logged-in user.

```
Forrest::identity();
```

For a complete listing of API resources, refer to the [Force.com REST API Developer's Guide](http://www.salesforce.com/us/developer/docs/api_rest/api_rest.pdf)

### Custom Apex endpoints

[](#custom-apex-endpoints)

If you create a custom API using Apex, you can use the `custom()` method for consuming them.

```
Forrest::custom('/myEndpoint');
```

Additional options and parameters can be passed in like this:

```
Forrest::custom('/myEndpoint', [
    'method' => 'post',
    'body' => ['foo' => 'bar'],
    'parameters' => ['flim' => 'flam']]);
```

> Read [Creating REST APIs using Apex REST](https://developer.salesforce.com/page/Creating_REST_APIs_using_Apex_REST) for more information.

### Raw Requests

[](#raw-requests)

If needed, you can make raw requests to an endpoint of your choice.

```
Forrest::get('/services/data/v20.0/endpoint');
Forrest::head('/services/data/v20.0/endpoint');
Forrest::post('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::put('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::patch('/services/data/v20.0/endpoint', ['my'=>'param']);
Forrest::delete('/services/data/v20.0/endpoint');
```

### Raw response output

[](#raw-response-output)

By default, this package will return the body of a response as either a deserialized JSON object or a SimpleXMLElement object.

There might be times, when you would rather handle this differently. To do this, simply use any format other than 'json' or 'xml' and the code will return a Guzzle response object.

```
$response = Forrest::sobjects($resource, ['format'=> 'none']);
$content = (string) $response->getBody(); // Guzzle response
```

### Event Listener

[](#event-listener)

This package makes use of Guzzle's event listers

```
Event::listen('forrest.response', function($request, $response) {
    dd((string) $response);
});
```

For more information about Guzzle responses and event listeners, refer to their [documentation](http://guzzle.readthedocs.org).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 82% 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 ~35 days

Recently: every ~59 days

Total

44

Last Release

2850d ago

Major Versions

v0.3.1 → v1.0.0-beta2014-08-30

v1.4.0 → v2.0.02015-05-06

PHP version history (3 changes)v0.1.0PHP &gt;=5.4.0

v2.1.2PHP &gt;=5.5.0

v2.4.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d54349fa0be6f5f39a6cd98d9876ba2603dc21a7d912f3fbe5f3e82dbb51232?d=identicon)[michak](/maintainers/michak)

---

Top Contributors

[![omniphx](https://avatars.githubusercontent.com/u/3722405?v=4)](https://github.com/omniphx "omniphx (214 commits)")[![tabirkeland](https://avatars.githubusercontent.com/u/10934808?v=4)](https://github.com/tabirkeland "tabirkeland (10 commits)")[![rtconner](https://avatars.githubusercontent.com/u/334533?v=4)](https://github.com/rtconner "rtconner (7 commits)")[![Olofguard](https://avatars.githubusercontent.com/u/1020137?v=4)](https://github.com/Olofguard "Olofguard (6 commits)")[![RobvH](https://avatars.githubusercontent.com/u/2434699?v=4)](https://github.com/RobvH "RobvH (4 commits)")[![scottwakefield](https://avatars.githubusercontent.com/u/4173571?v=4)](https://github.com/scottwakefield "scottwakefield (4 commits)")[![rkeppner](https://avatars.githubusercontent.com/u/3485765?v=4)](https://github.com/rkeppner "rkeppner (3 commits)")[![camiloherbertv](https://avatars.githubusercontent.com/u/171182396?v=4)](https://github.com/camiloherbertv "camiloherbertv (2 commits)")[![diggersworld](https://avatars.githubusercontent.com/u/3224105?v=4)](https://github.com/diggersworld "diggersworld (2 commits)")[![michakpl](https://avatars.githubusercontent.com/u/8200593?v=4)](https://github.com/michakpl "michakpl (2 commits)")[![pravindahal](https://avatars.githubusercontent.com/u/894731?v=4)](https://github.com/pravindahal "pravindahal (2 commits)")[![toddmcbrearty](https://avatars.githubusercontent.com/u/74171?v=4)](https://github.com/toddmcbrearty "toddmcbrearty (1 commits)")[![blocher](https://avatars.githubusercontent.com/u/5084741?v=4)](https://github.com/blocher "blocher (1 commits)")[![clemblanco](https://avatars.githubusercontent.com/u/668419?v=4)](https://github.com/clemblanco "clemblanco (1 commits)")[![robdrimmie](https://avatars.githubusercontent.com/u/47645?v=4)](https://github.com/robdrimmie "robdrimmie (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")

---

Tags

laravelrestsalesforceforce.comforce

### Embed Badge

![Health badge](/badges/michakpl-forrest/health.svg)

```
[![Health](https://phpackages.com/badges/michakpl-forrest/health.svg)](https://phpackages.com/packages/michakpl-forrest)
```

###  Alternatives

[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[api-platform/laravel

API Platform support for Laravel

59126.4k5](/packages/api-platform-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M307](/packages/psalm-plugin-laravel)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M368](/packages/laravel-zero-framework)

PHPackages © 2026

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