PHPackages                             pithstudio/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. [API Development](/categories/api)
4. /
5. pithstudio/forrest

ActiveLibrary[API Development](/categories/api)

pithstudio/forrest
==================

Working version of - A Laravel 4 client for Salesforce REST API

v1.0.1(11y ago)135MITPHPPHP &gt;=5.4.0

Since May 31Pushed 11y agoCompare

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

READMEChangelogDependencies (2)Versions (13)Used By (0)

Omniphx/Forrest, Force.com REST API Client for Laravel 4
========================================================

[](#omniphxforrest-forcecom-rest-api-client-for-laravel-4)

[![Latest Stable Version](https://camo.githubusercontent.com/36b70bf6759c3df6e442d8f2dc169cb29a0fe4d34bd39360e2f785b44943117d/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e697068782f666f72726573742f762f737461626c652e737667)](https://packagist.org/packages/omniphx/forrest) [![Total Downloads](https://camo.githubusercontent.com/101209279e45cc3761ced86817c2aa1e0ac8f710117a18035e59134039fd7515/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e697068782f666f72726573742f646f776e6c6f6164732e737667)](https://packagist.org/packages/omniphx/forrest) [![Latest Unstable Version](https://camo.githubusercontent.com/899146aaf8c7b760389836b100ce4ce686fcbcd4ca4e824af3ae50fa119e80fc/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e697068782f666f72726573742f762f756e737461626c652e737667)](https://packagist.org/packages/omniphx/forrest) [![License](https://camo.githubusercontent.com/c66f350496937d088a518669fc0114c07aae9ab6fca7e3a7ae7d88ca953f19e1/68747470733a2f2f706f7365722e707567782e6f72672f6f6d6e697068782f666f72726573742f6c6963656e73652e737667)](https://packagist.org/packages/omniphx/forrest) [![Build Status](https://camo.githubusercontent.com/546d3e46118044180da576e606cc72b24ccc941b470df41017f519f59f36e13e/68747470733a2f2f7472617669732d63692e6f72672f6f6d6e697068782f666f72726573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/omniphx/forrest)

Forrest is a Force.com REST API client for Laravel 4. It provides access to restricted Salesforce information via Oauth 2.0. REST is a lightweight alternative to the SOAP API and is useful for mobile users.

While this package is built for Laravel, it has been decoupled so that it can be extended into any framework or vanilla PHP application.

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

[](#installation)

> If you are upgrading to Version 1.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": "1.*"

```

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

If you are using Laravel, add the service provider to your `app/config/app.php` file:

```
'Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider'

```

Followed by the alias:

```
'Forrest' => 'Omniphx\Forrest\Providers\Laravel\Facades\Forrest'

```

### Configuration

[](#configuration)

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

```
php artisan config:publish omniphx/forrest
```

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

After you have set up am connected app (see below), update your config file with a `consumerKey`, `consumerSecret`, `loginURL` and `callbackURI`.

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. Add those to your config file.

### Setup

[](#setup)

Forrest will come with the following routes included in it's package:

##### Web Server authentication flow

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

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

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

    $url = Config::get('forrest::authRedirect');

    return Redirect::to($url);
});
```

##### Username-Password authentication flow

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

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

    $url = Config::get('forrest::authRedirect');

    return Redirect::to($url);
});
```

> Note: If you would like to customize the authentication process, these routes can be overwritten in your `route.php` file. Feel free to call the routes anything you like, but the callback must match what is configured in your Connected App settings and config file.

#### 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);
});
```

Usage
-----

[](#usage)

### Query a record

[](#query-a-record)

The callback function will store an encrypted authentication token in the user's session which can now be used to make API requests such as:

```
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"
        }
    ]
}
```

> The default format is JSON, but it can be changed to [XML](#xml-format)

### 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::describe('Account',['format'=>'xml']);
```

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

[](#api-requests)

With the exception of the `search` and `query` resources, all requests are made dynamically using method overloading. The available resources are stored in the user's session when they are authenticated.

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

```
Session::get('resources');
```

or

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

Either will return the following array:

```
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, you can 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 provided if you use 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 for a specific API.

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

#### Identity

[](#identity)

Returns information about the logged-in user.

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

#### Limits

[](#limits)

Lists information about organizational limits. Available for API version 29.0 and later.

> Note: this call is part of a pilot program and may not be availabe to all orgs without a request to Salesforce.

```
Forrest::limits();
```

#### Describe

[](#describe)

Describes all global objects availabe in the organization.

```
Forrest::describe();
```

#### Query

[](#query)

Returns results for a specified SOQL query.

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

#### Query Explain

[](#query-explain)

Returns details of how Salesforce will process your query. Available for API verison 30.0 or later.

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

#### Query All

[](#query-all)

Returns results for a specified SOQL query, but will also inlcude deleted records.

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

#### Search

[](#search)

Returns the specified SOSL query

```
Forrest::search('Find {foo}');
```

#### Scope Order

[](#scope-order)

Global search keeps track of which objects the user interacts with and arranges them when the user performs a global search. This call will return this ordered list of objects.

```
Forrest::scopeOrder();
```

#### Search Layouts

[](#search-layouts)

Returns the search results layout for the objects in the query string. List should be formatted as a string, but delimited by a comma.

```
Forrest::searchLayouts('Account,Contact,Lead');
```

#### Suggested Articles

[](#suggested-articles)

Returns a list of Salesforce Knowledge articles based on the a search query. Pass additional parameters into the second argument. Available for API verison 30.0 or later.

> Salesforce Knowledge must be enabled for this to work.

```
Forrest::suggestedArticles('foo', [
    'parameters' => [
        'channel' => 'App',
        'publishStatus' => 'Draft']]);
```

#### Suggested Queries

[](#suggested-queries)

Returns a list of suggested searches based on a search text query. Matches search queries that other users have performed in Salesforce Knowledge. Like Suggest Articles, additional parameters can be passed into the second argument with the `parameters` key. Available for API version 30.0 or later.

```
Forrest::suggestedQueries('app, [
    'parameters' => ['foo' => 'bar']]);
```

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.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 89.7% 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 ~17 days

Total

10

Last Release

4210d ago

Major Versions

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd710feb29262b1323903a4d89762040821055d243081dbffcf6577fad67f816?d=identicon)[pithstudio](/maintainers/pithstudio)

---

Top Contributors

[![omniphx](https://avatars.githubusercontent.com/u/3722405?v=4)](https://github.com/omniphx "omniphx (70 commits)")[![johnjjung](https://avatars.githubusercontent.com/u/2654677?v=4)](https://github.com/johnjjung "johnjjung (7 commits)")[![clemblanco](https://avatars.githubusercontent.com/u/668419?v=4)](https://github.com/clemblanco "clemblanco (1 commits)")

---

Tags

laravelsalesforce

### Embed Badge

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

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

###  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)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[laravel-freelancer-nl/laravel-index-now

Alert search engines of content changes.

5212.1k](/packages/laravel-freelancer-nl-laravel-index-now)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)

PHPackages © 2026

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