How to integrate Netsuite with PHP

  • 1
  • March 26, 2014
Douglas Radburn

Douglas Radburn

Head of Technical

Integration with third-party systems is a large part of what we do here at Branded3. Integrating into a platform that already streamlines your work process is a no-brainer, there really is no reason to reinvent the wheel.

We recently completed work on an integration between Netsuite and Magento. Netsuite is a large business management solution. A number of our clients have existing integrations with Netsuite, and many use it for stock management and its sales order process.

Netsuite API

Netsuite have an API for integration with their systems, called SuiteTalk. They also provide a PHP Toolkit, however, examples of its usage is thin on the ground. We’re going to look at some examples using the 2012_2r1 toolkit (so you’ll need to be using the “2012_2” endpoint).

Creating a customer

The Netsuite toolkit includes a Customer class, so, we’ll go ahead and populate some details in it.

Netsuite also includes a CustomerAddressbook class. It can’t be sent directly with a customer object, it needs to be attached to a CustomerAddressbookList, which can be attached to a customer object. You may want to add shipping and delivery addresses to a customer for example, and this allows for that.

If you don’t set a country, the default one that is set in Netsuite will be used. In our case for this example, we were pulling data from Magento, so we simply checked if the country wasn’t UK, and if it wasn’t, we set it. Netsuite uses its own internal country codes, so the country code must be valid so that Netsuite doesn’t throw an exception. We actually built a small translation class to do the conversion.

You can download it here: [download id=”9″ format=”3″]

To add this customer, you can make an AddRequest.

It’s important to note that Netsuite doesn’t try and match the customer details when you send them. It will create a new customer in the system. If you want to update existing customer details, you first need to look up the customer, then update their details and save it back to Netsuite. Netsuite keeps track of customers (and many other assets) using internal reference IDs.

To get internal references back from Netsuite, Netsuite returns them when an action (such as adding a record) completes. So, you can get the ID like this:

Looking up customers

Netsuite uses searches internally to look up all data. So, you just need to tell Netsuite what type of data you’re looking for, and what filters you want to put on that data in order to retrieve some. As with everything, there are a number of objects involved, so lets take a look – we’re going to look up a customer by email address in this case.

The internal Netsuite Id will be returned as part of the result array ($customerDetails) – $customerDetails[‘internalId’].

Using the internal customer Id, we can create a new Customer object and set it’s internal Id. Doing this, we can send an UpdateRequest to reference an existing customer.

At this stage, we should be able to send new customers to Netsuite, and also to update existing customers in Netsuite by looking up the customer record by customer email address.

If you need help integrating with any of your systems, big or small, get in touch.