PHP code example of roydejong / superoffice-webapi

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

    

roydejong / superoffice-webapi example snippets




use SoftwarePunt\SoWebApi\Client;
use SoftwarePunt\SoWebApi\Config;

$config = new Config();
$config->environment = "sod";
$config->tenantId = "Cust12345";
// ...

$client = new Client($config);



new Config([
    'environment' => "sod",
    'tenantId' => "Cust12345"
    // ...
]);

 

use SoftwarePunt\SoWebApi\Client;

$client = new Client(/* $config */);
$redirectUrl = $client->getOAuthAuthorizationUrl("optional_state");



$tokenResponse = $client->requestOAuthAccessToken($_GET['code']);



$tokenResponse = $client->refreshOAuthAccessToken($tokenResponse->refresh_token);



// ... request or refresh access token to get a $tokenResponse
$jwtIsValid = $tokenResponse->validateAndVerifyJwt($config);

if (!$jwtIsValid) {
    // ... something is fishy, bail
}



use SoftwarePunt\SoWebApi\Client;

// Optionally pass it directly in the client constructor:
$client = new Client(/* $config */, $tokenResponse->access_token);

// Or set it on an existing client instance:
$client->setAccessToken($tokenResponse->access_token);



use SoftwarePunt\SoWebApi\Client;

// Authentication is not enantStatus();

// If the target environment is offline, do not proceed:
if (!$tenantStatus->IsRunning) die("Tenant offline!");

// Tenant status gives a load-balanced base URL you can set on the client:
$client->setBaseUrl($tenantStatus->Endpoint);