<?php

require_once __DIR__ . '/../vendor/autoload.php';
$recordID = 'ac096703-67fd-8dd2-980a-57097932f07a';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    $EP = $SugarAPI->getAttachment('Notes', $recordID, 'filename')->downloadTo(__DIR__)->execute();
    $response = $EP->getResponse();
    if ($response->getStatus() == '200') {
        if (file_exists($response->file())) {
            echo "File downloaded to " . $response->file();
        }
    } else {
        echo "Failed to retrieve Note<br>";
        echo "Response: " . $response->getStatus() . "<br>";
        print_r($response->getBody());
    }
} catch (\SugarAPI\SDK\Exception\SDKException $ex) {
    print $ex->getMessage();
}
Esempio n. 2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    $EP = $SugarAPI->filterRecords('Accounts');
    $response = $EP->execute()->getResponse();
    print_r($EP->getRequest());
    if ($response->getStatus() == '200') {
        $recordList = $response->getBody(false);
        $max = count($recordList->records);
        echo "found {$max} records from Filter Records request. <br>";
        $number = rand(0, $max);
        $randomRecord = $recordList->records[$number];
        echo "Choose random record #{$number}, with ID: " . $randomRecord->id . " <br>";
        $getRecord = $SugarAPI->getRecord('Accounts', $randomRecord->id)->execute(array('fields' => 'name'));
        $response = $getRecord->getResponse();
        if ($response->getStatus() == '200') {
            echo "Retrieved Record <br>";
            $randomRecord = $getRecord->getResponse()->getBody(false);
            $randomRecord->name = 'Updated Record Name';
            $updateRecord = $SugarAPI->updateRecord('Accounts', $randomRecord->id)->execute($randomRecord);
            $response = $updateRecord->getResponse();
            if ($response->getStatus() == '200') {
                $randomRecord = $updateRecord->getResponse()->getBody(false);
                echo "Updated Record <br>";
                print_r($randomRecord);
                $deleteRecord = $SugarAPI->deleteRecord('Accounts', $randomRecord->id)->execute();
                $response = $deleteRecord->getResponse();
                if ($response->getStatus() == '200') {
<?php

require_once __DIR__ . '/../vendor/autoload.php';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    print_r($SugarAPI->getToken());
    echo "<br>Test1<br>";
    print_r(\SugarAPI\SDK\SugarAPI::getStoredToken('sugar'));
    echo "<br>Test2<br>";
    $SugarAPI2 = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/', array('username' => 'admin', 'password' => 'asdf'));
    if ($SugarAPI2->authenticated()) {
        echo "Authenticated!";
        print_r($SugarAPI2->getToken());
    }
} catch (\SugarAPI\SDK\Exception\SDKException $ex) {
    print_r($ex->getMessage());
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    $Accounts = $SugarAPI->filterRecords('Accounts')->setData(array('max_num' => 5));
    $Contacts = $SugarAPI->filterRecords('Contacts')->setData(array('max_num' => 1));
    $Notes = $SugarAPI->filterRecords('Notes')->setData(array('max_num' => 3));
    $Leads = $SugarAPI->filterRecords('Leads')->setData(array('max_num' => 2));
    $BulkCall = $SugarAPI->bulk()->execute(array($Accounts, $Contacts, $Notes, $Leads));
    $response = $BulkCall->getResponse();
    if ($response->getStatus() == '200') {
        echo "<h3>Requests Completed</h3><pre>";
        print_r($response->getBody());
        echo "</pre>";
    } else {
        echo "<h3>Request Failed</h3><pre>";
        print_r($response);
        echo "</pre>";
    }
} catch (\SugarAPI\SDK\Exception\Authentication\AuthenticationException $ex) {
    echo "Credentials:<pre>";
    print_r($SugarAPI->getCredentials());
    echo "</pre> Error Message: ";
    print $ex->getMessage();
} catch (\SugarAPI\SDK\Exception\SDKException $ex) {
    echo $ex->__toString();
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    $EP = $SugarAPI->createRecord('Accounts');
    $data = array('name' => 'Test Record 4', 'email1' => '*****@*****.**');
    $response = $EP->execute($data)->getResponse();
    if ($response->getStatus() == '200') {
        $record = $response->getBody(false);
        $EP2 = $SugarAPI->getRecord('Accounts', $record->id)->execute(array('fields' => 'name,email1'));
        $getResponse = $EP2->getResponse();
        print $EP2->getUrl();
        print_r($getResponse->getBody());
    }
} catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) {
    print $ex->getMessage();
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password' => 'asdf'));
    $SugarAPI->login();
    $EP = $SugarAPI->createRecord('Notes')->execute(array('name' => 'Test Note'));
    $response = $EP->getResponse();
    if ($response->getStatus() == '200') {
        $record = $response->getBody(false);
        $upload = $SugarAPI->attachFile('Notes', $record->id, 'filename')->execute(__DIR__ . '/testfile.txt');
        $response = $upload->getResponse();
        if ($response->getStatus() == '200') {
            $record = $response->getBody();
            print_r($record);
        } else {
            print_r($upload->getRequest());
            echo "Failed to Update Note with File<br>";
            echo "Response: " . $response->getStatus() . "<br>";
            print_r($response->getBody());
        }
    } else {
        echo "Failed to create Note<br>";
        echo "Response: " . $response->getStatus() . "<br>";
        print_r($response->getBody());
    }
} catch (\SugarAPI\SDK\Exception\SDKException $ex) {
    print $ex->getMessage();
}
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$record_id = 'a887c75b-b89a-852e-8e67-56f1ccdee355';
try {
    $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77', array('username' => 'admin', 'password' => 'admin123'));
    $SugarAPI->login();
    $EP = $SugarAPI->favorite('Accounts', $record_id);
    $response = $EP->execute()->getResponse()->getBody();
    print_r($response);
} catch (\SugarAPI\SDK\Exception\AuthenticationException $ex) {
    print $ex->getMessage();
}