PHP code example of bestcompany / bestcompany-api

1. Go to this page and download the library: Download bestcompany/bestcompany-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bestcompany / bestcompany-api example snippets


use Bestcompany\BestcompanyApi\BestcompanyApi;

$api = BestcompanyApi::create([
    'key' => 'your_api_key',
    'hostname' => 'https://api.bestcompany.com/api',
    'version' => 'v1'
]);

// Company operations
$companies = $api->companies()->all();
$company = $api->companies()->get(123);

// Review operations
$reviews = $api->reviews()->all();
$review = $api->reviews()->get(456);

// Other available resources
$api->verticals()->all();
$api->factSheets()->all();
$api->companyReviewLists()->all();

use Bestcompany\BestcompanyApi\SnoballApi;

$snoballApi = SnoballApi::create([
    'key' => 'your_snoball_api_key',
    'hostname' => 'https://api.snoball.com/api',
    'version' => 'v1'
]);

// Referral operations
$referral = $snoballApi->referralRequest()->create([
    'user_id' => 456,
    'company_id' => 789,
    'referral_type' => 'standard'
]);

$salesRep = $snoballApi->salesRepReferral()->all();

use Bestcompany\BestcompanyApi\BestcompanyApi;
use Bestcompany\BestcompanyApi\SnoballApi;

class CompanyController extends Controller
{
    public function __construct(
        private BestcompanyApi $bestcompanyApi,
        private SnoballApi $snoballApi
    ) {}

    public function getCompanies()
    {
        $companies = $this->bestcompanyApi->companies()->all();
        return response()->json($companies);
    }

    public function createReferral(Request $request)
    {
        $referral = $this->snoballApi->referralRequest()->create($request->all());
        return response()->json($referral);
    }
}

// config/bestcompany-api.php
return [
    'api_key' => env('BC_API_KEY', null),
    'hostname' => env('BC_HOSTNAME', 'https://api.bestcompany.com/api'),
    'version' => env('BC_API_VERSION', 'v1'),
];

// config/snoball.php
return [
    'api_key' => env('SNOBALL_API_KEY', null),
    'hostname' => env('SNOBALL_HOSTNAME', 'https://api.snoball.com/api'),
    'version' => env('SNOBALL_API_VERSION', 'v1'),
];

// Required configuration for BestcompanyApi
$api = BestcompanyApi::create([
    'key' => 'your_api_key',
    'hostname' => 'https://api.bestcompany.com/api',
    'version' => 'v1'
]);

// Required configuration for SnoballApi
$snoballApi = SnoballApi::create([
    'key' => 'your_snoball_key',
    'hostname' => 'https://api.snoball.com/api',
    'version' => 'v1'
]);

// In your config/app.php aliases array:
'aliases' => [
    'BestcompanyApi' => Bestcompany\BestcompanyApi\BestcompanyApiFacade::class,
    'SnoballApi' => Bestcompany\BestcompanyApi\SnoballApiFacade::class,
]

// Then use directly:
use BestcompanyApi;
use SnoballApi;

$companies = BestcompanyApi::companies()->all();
$referrals = SnoballApi::referralRequest()->all();

// This will throw a BadMethodCallException:
$bestcompanyApi->referralRequest(); // ❌ Not available in BestcompanyApi

// This will throw a BadMethodCallException:
$snoballApi->companies(); // ❌ Not available in SnoballApi

use Bestcompany\BestcompanyApi\Exceptions\SnoballApiException;

try {
    $referralRequest = SnoballApi::referralRequest()->create($params);
} catch (SnoballApiException $e) {
    if ($e->hasFieldErrors()) {
        // Per-field validation errors, keyed by input name — map onto your form.
        return back()->withErrors($e->fieldErrors());
    }

    if ($e->isUserSafe()) {
        // The server marked this message safe to show the person filling out the form.
        return back()->with('error', $e->displayMessage());
    }

    // Config/server problem — log it and show a generic message.
    report($e);
    return back()->with('error', 'Something went wrong — please contact support.');
}