PHP code example of cwm / broadworks-connector

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

    

cwm / broadworks-connector example snippets



use CWM\BroadWorksConnector\Ocip\Models\UserGetListInGroupRequest;
use CWM\BroadWorksConnector\Ocip\Models\UserGetListInGroupResponse;
use CWM\BroadWorksConnector\Ocip\Models\SearchCriteriaUserFirstName;
use CWM\BroadWorksConnector\Ocip\Models\SearchCriteriaUserLastName;
use CWM\BroadWorksConnector\Ocip\Models\SearchMode;
use CWM\BroadWorksConnector\Ocip\ErrorResponseException;
use CWM\BroadWorksConnector\Ocip\Validation\ValidationException;
use CWM\BroadWorksConnector\OcipClient;

-service-provider-portal.com:2209', 'portal-username', 'portal-password');

// In this example, a single request is made to get all users in a group whose first name is John.

$request1 = (new UserGetListInGroupRequest())
    ->setServiceProviderId('test-service-provider')
    ->setGroupId('test-group')
    ->setSearchCriteriaUserFirstName([
        (new SearchCriteriaUserFirstName())
            ->setIsCaseInsensitive(false)
            ->setMode(SearchMode::EQUAL_TO())
            ->setValue('John')
    ]);

try {
    $response = $ocip->userGetListInGroupRequest($request1);

    foreach ($response->getUserTable()->getRow() as $row) {
        echo $row->getCol()[0] . PHP_EOL;
    }
} catch (ErrorResponseException $e) {
    echo 'Server Error: ' . $e->getMessage() . PHP_EOL;
    exit();
} catch (ValidationException $e) {
    echo 'Validation Error: ' . $e->getMessage() . PHP_EOL;
    exit();
}

// Multiple requests can be executed in a single call to the API too via the callAll method.
// Here we'll add another request that retrieves all users from another group whose last name starts with an M.

$request2 = (new UserGetListInGroupRequest())
    ->setServiceProviderId('test-service-provider')
    ->setGroupId('another-test-group')
    ->setSearchCriteriaUserFirstName([
        (new SearchCriteriaUserLastName())
            ->setIsCaseInsensitive(false)
            ->setMode(SearchMode::STARTS_WITH())
            ->setValue('M')
    ]);

try {
    /** @var UserGetListInGroupResponse[] $responses */
    $responses = $ocip->callAll([$request1, $request2]);

    foreach ($responses as $response) {
        foreach ($response->getUserTable()->getRow() as $row) {
            echo $row->getCol()[0] . PHP_EOL;
        }
    }
} catch (ErrorResponseException $e) {
    echo 'Server Error: ' . $e->getMessage() . PHP_EOL;
    exit();
} catch (ValidationException $e) {
    echo 'Validation Error: ' . $e->getMessage() . PHP_EOL;
    exit();
}