Netsuite PHPToolkit Web Service - Create Customer Tutorial

Netsuite provides a soap-based web service interface called SuiteTalk to allow 3rd-party applications to interface with Netsuite ERP system. Netsuite also provides Toolkits written in PHP, .NET and Java programming languages, which will make Netsuite integration easier. We'll use PHPToolkit to create a customer record in Netsuite.

In order to interface with Netsuite, we'll have to setup a login_info which we can use to authenticated in Netsuite. The PHPToolkit includes sample PHP scripts that illustrates how to add a customer records (sample_add_customer.php) and search records (sample_search_items.php) in the Netsuite platform.

require ('PHPtoolkit.php');
require ('login_info.php');

class CreateCustomer {
	const CustomEntityTestId = 4;
	const CustomerEntityStatusId = 6;   // LEAD::unqualified.
	public static function add($data) {
		global $myNSclient;
		// We are going to hard-code custom entity here for illustration purpose.
		$test = new nsListOrRecordRef(
				array('internalId' => self::CustomEntityTestId, 'typeId' => 1));
		$testRef = new nsComplexObject("SelectCustomFieldRef");
		$testRef->setFields(array("internalId" => 'custentity_test', 'value' => 5));
		$customFieldList = new nsCustomFieldList(
				array("customField" => array($testRef)));
		// create array of customer fields
		$customerFields = array (
		    'isPerson'        => true,
		    'firstName'       => $data['firstName'],
		    'lastName'        => $data['lastName'],
		    'companyName'     => $data['companyName'],
		    'phone'           => $data['phone'],
		    'email'           => $data['email'],
		    'entityStatus'    => new nsRecordRef(
                           array('internalId' => self::CustomerEntityStatusId)),
		'customFieldList' => $customFieldList,
		// create Customer record
		$customer = new nsComplexObject('Customer');
		$response = $myNSclient->add($customer);
		if (!$response->isSuccess) {
			$response =  $response->statusDetail[0]->message;
		} else {
			return TRUE;

$data = array("name" => "John Doe",
			  "phone" => "333-333-3333",
			  "email" => "[email protected]"

$response = CreateCustomer::add($data);


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.