PHP code example of stitch-digital / laravel-simpro-api
1. Go to this page and download the library: Download stitch-digital/laravel-simpro-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/ */
stitch-digital / laravel-simpro-api example snippets
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Info\GetInfo;
$response = Simpro::send(new GetInfo())->json();
use StitchDigital\LaravelSimproApi\LaravelSimproApi;
use StitchDigital\LaravelSimproApi\Requests\Info\GetInfo;
$connector = new LaravelSimproApi();
$request = new GetInfo();
$response = $connector->send($request)->json();
use StitchDigital\LaravelSimproApi\LaravelSimproApi;
use StitchDigital\LaravelSimproApi\Requests\Info\GetInfo;
$connector = new LaravelSimproApi(
baseUrl: 'https://custom-api-url.simprosuite.com',
apiKey: 'custom-api-key'
);
$response = $connector->send(new GetInfo());
$response->json();
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Customers\GetCustomers;
$companyId = 0;
$response = Simpro::send(new GetCustomers($companyId))->json();
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Customers\GetCustomers;
$companyId = 0;
$response = Simpro::send(new GetCustomers($companyId))->headers();
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Customers\GetCustomers;
$companyId = 0;
$response = Simpro::paginate(new GetCustomers($companyId))
->collect()
->all();
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Customers\GetCustomers;
$companyId = 0;
$response = Simpro::paginate(new GetCustomers($companyId))
->setPerPageLimit(250) // increase the per page limit to 250
->collect()
->all();
/*
|--------------------------------------------------------------------------
| Rate Limit Configuration
|--------------------------------------------------------------------------
|
| Set the rate limit for Simpro requests. The rate limit is set per second
| and the threshold is the percentage of the rate limit that is accepted.
| The threshold must be a number between 0 and 1 (e.g. 0.5 for 50%).
|
| The default rate limit is as per the Simpro API documentation.
|
*/
'rate_limit' => [
'enabled' => true,
'per_second' => 10,
'driver' => 'database',
'threshold' => 0.8,
],
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Info\GetInfo;
$response = Simpro::useRateLimitPlugin(false)
->send(new GetInfo())
->json();
/*
|--------------------------------------------------------------------------
| Cache Configuration
|--------------------------------------------------------------------------
|
| Enable or disable caching for Simpro GET requests. The cache driver can
| be set to any of the Laravel cache drivers. The cache expiry time is
| set in seconds.
|
*/
'cache' => [
'enabled' => true,
'driver' => 'database',
'expire' => 120,
],
/*
|--------------------------------------------------------------------------
| Global Retry Configuration
|--------------------------------------------------------------------------
|
| Set the number of retries for all requests. This can still be overridden
| on a per-request basis, by chaining sendAndRetry() to the request:
|
| Example:
| $response = $connector->sendAndRetry($request, 1);
|
*/
'global_retries' => 3, // Set to null to disable global retries
use StitchDigital\LaravelSimproApi\Facades\Simpro;
use StitchDigital\LaravelSimproApi\Requests\Jobs\GetJobs;
$companyId = 0;
$siteId = 123;
$request = new GetJobs($companyId);
$request->query()->add('Site.ID', $siteId);
// Returns all jobs for Site ID 123
$response = Simpro::send($request)->json();