PHP code example of tjsteinhaus / netsuite-php
1. Go to this page and download the library: Download tjsteinhaus/netsuite-php 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/ */
tjsteinhaus / netsuite-php example snippets
use NetSuite\NetSuiteService;
$config = array(
// bservices.netsuite.com",
"email" => "[email protected] ",
"password" => "mySecretPwd",
"role" => "3",
"account" => "MYACCT1",
"app_id" => "4AD027CA-88B3-46EC-9D3E-41C6E6A325E2",
// optional -------------------------------------
"logging" => true,
"log_path" => "/var/www/myapp/logs/netsuite"
);
$service = new NetSuiteService($config);
use NetSuite\Classes\GetRequest;
use NetSuite\Classes\RecordRef;
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = "123";
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
if ( ! $getResponse->readResponse->status->isSuccess) {
echo "GET ERROR";
} else {
$customer = $getResponse->readResponse->record;
}
use NetSuite\Classes\SearchStringField;
use NetSuite\Classes\CustomerSearchBasic;
use NetSuite\Classes\SearchRequest;
$service->setSearchPreferences(false, 20);
$emailSearchField = new SearchStringField();
$emailSearchField->operator = "startsWith";
$emailSearchField->searchValue = "j";
$search = new CustomerSearchBasic();
$search->email = $emailSearchField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
} else {
$result = $searchResponse->searchResult;
$count = $result->totalRecords;
$records = $result->recordList;
echo $count . " records were found.";
}
use NetSuite\Classes\Customer;
use NetSuite\Classes\RecordRef;
use NetSuite\Classes\AddRequest;
$customer = new Customer();
$customer->lastName = "Doe";
$customer->firstName = "John";
$customer->companyName = "ABC company";
$customer->phone = "123456789";
$customer->email = "[email protected] ";
$customer->customForm = new RecordRef();
$customer->customForm->internalId = -8;
$request = new AddRequest();
$request->record = $customer;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
$service->setLogPath('/path/to/logs');
$service->logRequests(true); // Turn logging on.
$service->logRequests(false); // Turn logging off.
$config = array(
// "2017_1",
"host" => "https://webservices.netsuite.com",
"account" => "MYACCT1",
"consumerKey" => "0123456789ABCDEF",
"consumerSecret" => "0123456789ABCDEF",
"token" => "0123456789ABCDEF",
"tokenSecret" => "0123456789ABCDEF",
// optional -------------------------------------
"signatureAlgorithm" => 'sha256', // Defaults to 'sha256'
);
$service = new NetSuiteService($config);
composer