How to integrate Netsuite with PHP

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: Netsuite Translation Class

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.

By Douglas Radburn. at 2:49PM on Wednesday, 26 Mar 2014

Doug is our Senior Open Source Web Developer since bringing his knowledge and skills to Branded3 in 2009. A founding developer of our Twitition and Competwition platforms, Doug has also been lead in our Open Source Projects on Magento ecommerce solutions and Wordpress CMS platforms. Follow Douglas Radburn on Twitter.

comments

One Response to “How to integrate Netsuite with PHP”

  1. Dave Weiss says:

    A tip:

    There is an Upsert method which will either create or update the record in NetSuite. The one caveat is that you must use the ExternalID field as the primary key. If you are creating customers in Magento and syncing them to NetSuite, supply the Magento ID as the ExternalID.

    No need to bother with looking up the record in NetSuite and returning the internal ID (or NULL if the customer is not found).

    Another tip:

    Take a look at NetSuite’s RESTLet capabilities – roll your own API in a mostly RESTful architecture. I use them quite a bit.

Leave a Reply