PHP code example of securibox / cloudagents

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

    

securibox / cloudagents example snippets


use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::AuthenticationBasic("username", "password");

use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::SslClientCertificate("C:\Path\to\PEM Certificate", "PEM pass phrase");

use Securibox\CloudAgents\Documents\ApiClient;

$client = ApiClient::Jwt("C:\Path\to\PEM private key", "PEM pass phrase");

 
// If you are using Composer (recommended)
Securibox\CloudAgents\Documents\Entities;

// If you are not using Composer
// agent){
    print("\n\n\n------ Agent Details ------\n");
    print("ID: ".$agent->id."\n");
    print("Name: ".$agent->name."\n");
    print("Periodicity: ".$agent->agentPeriodicity."\n");
    print("Current Status: ".$agent->agentCurrentState."\n");
    print("Category: ".$agent->category."\n");
    foreach($agent->fields as $field){
        print("   Field[". $field->position ."]: ".$field->name."\n");
    }
}


// If you are using Composer (recommended)
 Securibox\CloudAgents\Documents\Entities;

// If you are not using Composer
// t->customerAccountId = 'Account201708082';
$account->customerUserId = 'User123';
$account->name = 'Test Account 1';
$account->credentials = array();

//Configure credentials
$username = new Entities\Credential();
$username->position = 0;
$username->value = '[email protected]';

//Configure credentials
$password = new Entities\Credential();
$password->position = 1;
$password->value = '###password###';

array_push($account->credentials, $username, $password);

//Setup client
$client = new ApiClient::AuthenticationBasic("Basic Username", "Basic Password");

//Create the account which automatically launches a synchronization
$returnedAccount = $client->CreateAccount($account);

//Let's wait until the synchronization has reached a final status
$synchronization = $client->GetLastSynchronizationByAccount($returnedAccount->customerAccountId);
while($synchronization->synchronizationState != "PendingAcknowledgement" &&
      $synchronization->synchronizationState != "Completed" &&
      $synchronization->synchronizationState != "ReportFailed"){
        sleep(5);
        $synchronization = $client->GetLastSynchronizationByAccount($returnedAccount->customerAccountId);
}

//Let's get the newly downloaded documents and save them locally
$documents = $client->GetDocumentsByAccount($account->customerAccountId, 'true','true');
$receivedFiles = array();
foreach($documents as $document){
    $file = fopen("C:\\Temp\\".$document->name, "wb");
    $content =  base64_decode($document->base64Content);
    fwrite($file, $content);
    fclose($file);
    array_push($receivedFiles, $document->id);   
}
$client->AcknowledgeSynchronizationForAccount($account->customerAccountId, $receivedFiles, array());