PHP code example of crademaker / bexio-api-client

1. Go to this page and download the library: Download crademaker/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/ */

    

crademaker / bexio-api-client example snippets




declare(strict_types=1);

use Crademaker\BexioApiClient\Auth\StaticTokenProvider;
use Crademaker\BexioApiClient\Http\BexioClient;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;

$httpClient = new GuzzleClient();
$httpFactory = new HttpFactory();

$client = new BexioClient(
    $httpClient,
    $httpFactory,
    $httpFactory,
    new StaticTokenProvider('your-personal-access-token'),
);

$contacts = $client->contacts()->v2ListContacts([
    'limit' => 20,
]);

$contact = $client->contacts()->v2ShowContact([
    'contact_id' => 123,
]);

$matches = $client->contacts()->v2SearchContact(
    [
        [
            'field' => 'name_1',
            'value' => 'Example Company',
            'criteria' => '=',
        ],
    ],
    ['limit' => 20],
);

$created = $client->files()->v3CreateFile(
    [
        'name' => 'example.pdf',
        'file' => [
            'contents' => file_get_contents('/path/to/example.pdf'),
            'filename' => 'example.pdf',
            'content_type' => 'application/pdf',
        ],
    ],
);



declare(strict_types=1);

use Crademaker\BexioApiClient\Auth\InMemoryTokenStore;
use Crademaker\BexioApiClient\Auth\OAuthTokenService;
use Crademaker\BexioApiClient\Auth\RefreshableTokenProvider;
use Crademaker\BexioApiClient\Auth\TokenSet;
use Crademaker\BexioApiClient\Http\BexioClient;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;

$httpClient = new GuzzleClient();
$httpFactory = new HttpFactory();

$tokenStore = new InMemoryTokenStore(
    new TokenSet(
        accessToken: 'initial-access-token',
        refreshToken: 'refresh-token',
    ),
);

$oauth = new OAuthTokenService($httpClient, $httpFactory, $httpFactory);
$provider = new RefreshableTokenProvider(
    clientId: 'client-id',
    clientSecret: 'client-secret',
    tokenStore: $tokenStore,
    tokenService: $oauth,
    scopes: ['openid', 'offline_access', 'contact_show'],
);

$client = new BexioClient($httpClient, $httpFactory, $httpFactory, $provider);

$authorizationUrl = $oauth->buildAuthorizationUrl(
    clientId: 'client-id',
    redirectUri: 'https://app.example.com/callback',
    scopes: ['openid', 'offline_access', 'contact_show'],
    state: 'csrf-token',
);