PHP code example of onlime / laravel-bexio-api-client

1. Go to this page and download the library: Download onlime/laravel-bexio-api-client 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/ */

    

onlime / laravel-bexio-api-client example snippets



return [
    /*
    |--------------------------------------------------------------------------
    | Bexio API Credentials
    |--------------------------------------------------------------------------
    */
    'api' => [
        'clientId' => env('BEXIO_API_CLIENT_ID', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'),
        'clientSecret' => env('BEXIO_API_CLIENT_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        ),
        'tokensFile' => env('BEXIO_API_TOKENS_FILE', 'bexio_client_tokens.json'),
        'scopes' => explode(' ', env('BEXIO_API_SCOPES',
            'openid profile contact_edit offline_access kb_invoice_edit article_edit note_edit'
        )),
    ],
];

    'disks' => [
        // ...
        'secure' => [
            'driver' => 'local',
            'root' => storage_path('app/secure'),
            'visibility' => 'private',
            'throw' => false,
        ],

// routes/web.php

Route::middleware('auth')->group(function () {
    Route::group(['prefix' => 'admin'], function () {
        Route::controller(BexioController::class)->prefix('bexio')->group(function () {
            Route::redirect('/', '/admin/bexio/auth');
            Route::get('/auth', 'authenticate')->name('bexio.auth');
            Route::get('/demo', 'demo')->name('bexio.demo');
        });
    });
});



namespace App\Http\Controllers;

use Bexio\Resource\Contact as BexioContact;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Inertia\Inertia;
use LaravelBexio\Client;

class BexioController extends Controller
{
    public function authenticate(Request $request)
    {
        $client = $this->getBexioClient();
        $client->authenticate(config('bexio.api.scopes'), route('bexio.auth'));
        $client->persistTokens($this->getTokensFile());

        return view('bexio.auth');
    }

    public function demo(Request $request)
    {
        $client = $this->getBexioClient();
        $client->loadTokens($this->getTokensFile());

        return view('bexio.demo', [
            'contacts' => (new BexioContact($client))->getContacts(),
        ]);
    }

    protected function getBexioClient(): Client
    {
        return new Client(
            config('bexio.api.clientId'),
            config('bexio.api.clientSecret')
        );
    }

    protected function getTokensFile(): string
    {
        return Storage::disk('secure')->path(config('bexio.api.tokensFile'));
    }
}

$ php artisan serve