Snippets

Monil Gandhi Get Emails

Created by Monil Gandhi

<?php
use Braango\braangomodel as model;

require_once (__DIR__ . '/../../vendor/autoload.php');

// Configure API key authorization: auth_token
Braango\Configuration::getDefaultConfiguration()->setApiKey('auth_token', 'ISNWF0P30WM0CMK');

$api_instance = new Braango\braangoapi\EmailsApi();

// string | id of _sub_dealer_
$subdealerid = "subdealers2002";

// string | if of _personnel_
$salespersonid = "aed72631-c968-4362-a9a4-ebe5bef8310b";

// string | API Key to access this dealer's resources. 
// Value was returned when create_account api was called and dealer was created first time
$apiKey = "ISNMdzuNiKG7jhl9d9v";

// string | Dealer or partner is accessing this API
$accountType = "partner";

// bool | Specifies to get ADF CRM email records or plain email records.  
// If not specified, default is false i.e. regular email ID accounts
$typeAdfCrm = FALSE;

try {
    $result = $api_instance->getEmail($subdealerid, $salespersonid, $apiKey, $accountType, $typeAdfCrm);
    if ($result != null) {
        
        // Extract out response hdr and bdy
        $rspHdr = $result->getHeader();
        
        if ($requestHdr = ! null) {
            $rspId = $rspHdr->getId();
            $braangoRequestId = $rspHdr->getIsnRequestId();
        }
        
        $rspBdy = $result->getBody();
        if ($rspBdy != null) {
            $status = $rspBdy->getStatus();
            
            // Typically this value should be always SUCCESS else exception will be thrown
            // Sometimes, this can be WARNING to indicate if any resource conflicted or not
            // In case of SUCCESS or WARNING, resources are always created (excepting warned sub-resources)
            print_r("Status = " . $status . "\n");
            
            $emailOutPutBodyData = new model\EmailOutputBodyData();
            
            $emailOutPutBodyData = $rspBdy->getData();
            
            $emails = array();
            
            if ($typeAdfCrm) {
                $emails = $emailOutPutBodyData->getCrmEmailList();
            } else {
                $emails = $emailOutPutBodyData->getEmailList();
            }
            print "Email LIST: ";
            
            print_r(array_values($emails));
            
        }
        
    }
    
} catch (Exception $e) {
    echo 'Exception when calling EmailsApi->getEmail: ', $e->getMessage(), PHP_EOL;
}
?>

Comments (0)