PHPackages                             firebear/netsuite-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. firebear/netsuite-php

ActiveLibrary[API Development](/categories/api)

firebear/netsuite-php
=====================

NetSuite PHP API wrapper

v2019.1.2(6y ago)014.1k↓33.3%Apache-2.0PHPPHP &gt;=5.3.0

Since Jan 28Pushed 6y ago3 watchersCompare

[ Source](https://github.com/firebearstudio/netsuite-php)[ Packagist](https://packagist.org/packages/firebear/netsuite-php)[ RSS](/packages/firebear-netsuite-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (24)Used By (0)

NetSuite PHP API Client
=======================

[](#netsuite-php-api-client)

[![License](https://camo.githubusercontent.com/81dc76799bc7e606602ddc16e675434b21d37748d45be59a6030eccfbd64f80b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7279616e77696e636865737465722f6e657473756974652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryanwinchester/netsuite-php)![Packagist](https://camo.githubusercontent.com/fed429d82866855bad641d86a355d3bfc7ca54b9f4b757442178211ddf4e7af1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e77696e636865737465722f6e657473756974652d7068702e7376673f6d61784167653d32353932303030)

A PHP API client package for NetSuite, pried from the [NetSuite PHP Toolkit](http://www.netsuite.com/portal/developers/resources/suitetalk-sample-applications.shtml).

Adding it to your project:
--------------------------

[](#adding-it-to-your-project)

Require with composer:

**V2 in Alpha**

```
composer require ryanwinchester/netsuite-php

```

Changes in v2:
--------------

[](#changes-in-v2)

- 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.

Quickstart:
-----------

[](#quickstart)

#### Instantiating the NetSuiteService class:

[](#instantiating-the-netsuiteservice-class)

The rest of the examples assume that you have done this.

```
require 'vendor/autoload.php';

use NetSuite\NetSuiteService;

$config = array(
   // required -------------------------------------
   "endpoint" => "2019_1",
   "host"     => "https://webservices.netsuite.com",
   "email"    => "jDoe@netsuite.com",
   "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);
```

You can alternatively place your config in environment variables. This is helpful in hosted environments where deployment of config files is either not desired or practical. You can find the valid keys in the included .env.example file with sample values.

Previously, instantiating the NetSuiteClient with ENV data entailed using the static method `createFromEnv`. This method is now marked as `deprecated` and if you are using it, please change your code to use the standard constructor which will extract your configuration out of the $\_ENV superglobal for you.

```
require 'vendor/autoload.php';

use NetSuite\NetSuiteService;

$service = new NetSuiteService();
```

Account-Specific Data Center URLs
---------------------------------

[](#account-specific-data-center-urls)

With 2019\_1, this library provides support to utilize NetSuite's new account-specific data center URL with each request. In practice, this lookup does have a measurable overhead cost. As such, I'd suggest using this feature only if your manner of NetSuite integration is such that you make fewer connections, handling integration in batches. If your manner of integration is to instead make many frequent, brief requests from NetSuite, then you will probably prefer to provide your data center URL explicitly and remove the lookup from every session.

```
// To use your own defined data center URL (or sandbox, for instance):
$config['host'] = 'https://123456789.suitetalk.api.netsuite.com';

// To allow the service to get the correct URL for your account on the fly,
// use the legacy webservices url.
$config['host'] = 'https://webservices.netsuite.com';
```

#### Retreiving a customer record:

[](#retreiving-a-customer-record)

```
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;
}
```

#### Searching for customers who emails start with "j":

[](#searching-for-customers-who-emails-start-with-j)

```
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.";
}
```

#### Adding a new customer:

[](#adding-a-new-customer)

```
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;
}
```

#### Adding a salesOrder with a custom field:

[](#adding-a-salesorder-with-a-custom-field)

This example of an order creation is not a complete example but shows how you set up and add the object generally as well as how you would add custom fields to the sale on insert.

```
use NetSuite\Classes\AddRequest;
use NetSuite\Classes\CustomFieldList;
use NetSuite\Classes\RecordRef;
use NetSuite\Classes\SalesOrder;
use NetSuite\Classes\StringCustomField;

$sale = new SalesOrder();

// Associate a customer record with this order
$sale->entity = new RecordRef();
$sale->entity->type = 'customer';
$sale->entity->internalId = $myCustomerInternalId;

// Set the date of the order
$sale->tranDate = $myOrderDate;

// Set the shipping method and price for the order
$sale->shipMethod = new RecordRef();
$sale->shipMethod->internalId = $myShipMethodId;
$sale->shippingCost = $myShippingTotal;

// Look at the SalesOrder class definition for a list of all the available
// properties and their types that you can use on a sales order in NetSuite.
// You'll need to add items, addresses, status, etc.

// Create a sample string-type custom field to the order which represents
// the ID of the order in our source platform:
$cfOrderNum = new StringCustomFieldRef();
$cfOrderNum->scriptId = 'custbody_order_num';
$cfOrderNum->value = $myOrderNumber;

// Collect all custom fields into an array and add the list of fields to the
// order add request:
$customFields[] = $cfOrderNum;
$sale->customFieldList = new CustomFieldList();
$sale->customFieldList->customField = $customFields;

// Submit the sales order create request
$request = new AddRequest();
$request->record = $sale;
$response = $service->add($request);

if (!$addResponse->writeResponse->status->isSuccess) {
    echo "ADD ERROR";
} else {
    echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
```

#### Creating an Item Fulfillment:

[](#creating-an-item-fulfillment)

Creating an item fulfillment against a Sales Order requires initializing the new record based on the target record (the sales order). Then you can set the properties on the new record accordingly and add it to NetSuite. The same method is used for creating CashSale records.

```
use NetSuite\Classes\AddRequest;
use NetSuite\Classes\InitializeRecord;
use NetSuite\Classes\InitializeRef;
use NetSuite\Classes\InitializeRequest;
use NetSuite\Classes\ItemFulfillmentPackage;
use NetSuite\Classes\ItemFulfillmentPackageList;

// Initialize an item fulfillment from an existing Sales Order
$reference = new InitializeRef();
$reference->type = InitializeRefType::salesOrder;
$reference->internalId = $mySalesOrderInternalId;

$record = new InitializeRecord();
$record->type = InitializeType::itemFulfillment;
$record->reference = $reference;

$request = new InitializeRequest();
$request->initializeRecord = $record;

$response = $service->initialize($request);

if (!$response->readResponse->status->isSuccess) {
    echo "INIT ERROR";
}

$itemFulfillment = $response->readResponse->record;

$package = new ItemFulfillmentPackage();
$package->packageWeight = 1;
$package->packageTrackingNumber = $myTrackingNumber;

$packageList = new ItemFulfillmentPackageList();
$packageList->package = $package;
$itemFulfillment->packageList = $packageList;

$request = new AddRequest();
$request->record = $itemFulfillment;

$response = $service->add($request);

if (!$response->writeResponse->status->isSuccess) {
    echo "ADD ERROR";
} else {
    echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
```

### Logging

[](#logging)

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.
```

#### Token-Based Authentication

[](#token-based-authentication)

Instead of instantiating `NetSuiteService` with the standard credentials method, you can pass a set of credentials of the form `consumerKey`/`consumerSecret`/`token`/`tokenSecret`.

```
$config = array(
   // required -------------------------------------
   "endpoint"       => "2019_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);
```

Status
------

[](#status)

- Extract the ~1500 classes from their single file...
- Composer package with autoloading
- Pass config through constructor
- Optional environment variable config
- Namespacing
- Logging
- Dynamic Data Center URLs
- Expanded user documentation
- Support automagic configuration via ENV variables

License
-------

[](#license)

[Original work](http://www.netsuite.com/portal/developers/resources/suitetalk-sample-applications.shtml) is Copyright © 2010-2015 NetSuite Inc. and provided "as is." Refer to the [NetSuite Toolkit License Agreement](https://github.com/ryanwinchester/netsuite-php/blob/master/original/NetSuite%20Application%20Developer%20License%20Agreement.txt) file.

All additional work is licensed under the **Apache 2.0** open source software license according to the included [LICENSE](https://github.com/ryanwinchester/netsuite-php/blob/master/LICENSE.txt) file.

###  Health Score

35

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~92 days

Recently: every ~220 days

Total

21

Last Release

2219d ago

Major Versions

v2014.2.0 → v2015.1.02015-05-01

v2.0.4-alpha → v2016.1.02016-06-02

v2016.2.0 → v2017.1.02017-09-26

v2017.1.1 → v2018.2.02019-02-28

v2018.2.1 → v2019.1.22020-02-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/89ace2cf6bd606a1c79e5d955e1d3d6a8c0eff870851f0f24b3a46e2cc2478a5?d=identicon)[fbeardev](/maintainers/fbeardev)

---

Top Contributors

[![ryanwinchester](https://avatars.githubusercontent.com/u/2897340?v=4)](https://github.com/ryanwinchester "ryanwinchester (72 commits)")[![jrebs](https://avatars.githubusercontent.com/u/4203789?v=4)](https://github.com/jrebs "jrebs (27 commits)")[![es02](https://avatars.githubusercontent.com/u/1310970?v=4)](https://github.com/es02 "es02 (5 commits)")[![magelogger](https://avatars.githubusercontent.com/u/45941552?v=4)](https://github.com/magelogger "magelogger (4 commits)")[![bendavies](https://avatars.githubusercontent.com/u/625392?v=4)](https://github.com/bendavies "bendavies (4 commits)")[![skylord123](https://avatars.githubusercontent.com/u/3412313?v=4)](https://github.com/skylord123 "skylord123 (4 commits)")[![neclimdul](https://avatars.githubusercontent.com/u/82823?v=4)](https://github.com/neclimdul "neclimdul (2 commits)")[![balintbrews](https://avatars.githubusercontent.com/u/297418?v=4)](https://github.com/balintbrews "balintbrews (2 commits)")[![patforg](https://avatars.githubusercontent.com/u/792553?v=4)](https://github.com/patforg "patforg (1 commits)")[![r-phelan](https://avatars.githubusercontent.com/u/5914294?v=4)](https://github.com/r-phelan "r-phelan (1 commits)")[![fahmiardi](https://avatars.githubusercontent.com/u/1201482?v=4)](https://github.com/fahmiardi "fahmiardi (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![serhiimakarov](https://avatars.githubusercontent.com/u/15029756?v=4)](https://github.com/serhiimakarov "serhiimakarov (1 commits)")[![boaf](https://avatars.githubusercontent.com/u/341348?v=4)](https://github.com/boaf "boaf (1 commits)")

---

Tags

phpapinetsuite

### Embed Badge

![Health badge](/badges/firebear-netsuite-php/health.svg)

```
[![Health](https://phpackages.com/badges/firebear-netsuite-php/health.svg)](https://phpackages.com/packages/firebear-netsuite-php)
```

###  Alternatives

[ryanwinchester/netsuite-php

NetSuite PHP API wrapper

2012.5M4](/packages/ryanwinchester-netsuite-php)[fungku/netsuite-php

NetSuite PHP API wrapper

2011.8k](/packages/fungku-netsuite-php)[jstolpe/instagram-graph-api-php-sdk

Instagram Graph API PHP SDK

13994.9k1](/packages/jstolpe-instagram-graph-api-php-sdk)[netsuitephp/netsuite-laravel

NetSuite PHP laravel provider wrapper

11195.3k](/packages/netsuitephp-netsuite-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
