A PHP API client package for NetSuite, pried from the NetSuite PHP Toolkit.
Require with composer:
V2 in Alpha
NOTE: package name change
composer require "ryanwinchester/netsuite-php:2016.1.*"
- Changed namespaces
- Significantly simplified NetSuiteClient
- Added a convenience method for creating an instance using environment variables for configuration
- Improved logging, still logs even if exception is thrown in soap call.
- You will need to run
composer install
in order to create the 'vendor' directory.
The rest of the examples assume that you have done this.
require 'vendor/autoload.php';
use NetSuite\NetSuiteService;
$config = array(
// required -------------------------------------
"endpoint" => "2016_1",
"host" => "https://webservices.netsuite.com",
"email" => "jDoe@netsuite.com",
"password" => "mySecretPwd",
"role" => "3",
"account" => "MYACCT1",
"app_id" => "9DB49F44-9854-44E9-8527-115AE98823A5",
// optional -------------------------------------
"logging" => true,
"log_path" => "/var/www/myapp/logs/netsuite"
);
$service = new NetSuiteService($config);
Note for app_id: Application Id is required for requests using end point 2015.2 or later. Application Id can be found by going to SetUp -> Integration -> Manage Integrations for NetSuite UI using Admin role.
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 = "joe.doe@abc.com";
$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;
}
You can set logging on or off on the fly, or override the configuration setting passed in. Please note that if you don't specify a logging directory in the config or afterwards, then you won't get logs no matter what you do.
Set a logging path
$service->setLogPath('/path/to/logs');
Turn logging on
$service->logRequests(true); // Turn logging on.
Turn logging off
$service->logRequests(false); // Turn logging off.
- Extract the ~1500 classes from their single file...
- Composer package with autoloading
- Pass config through constructor
- Optional environment variable config
- Namespacing
- Logging
Original work is Copyright © 2010-2015 NetSuite Inc. and provided "as is." Refer to the NetSuite Toolkit License Agreement file.
All additional work is licensed under the Apache 2.0 open source software license according to the included LICENSE file.
Maybe?