All Projects → netsuitephp → Netsuite Php

netsuitephp / Netsuite Php

Licence: other
NetSuite PHP API Client with namespaces and autoloading

Projects that are alternatives of or similar to Netsuite Php

Tekore
Spotify Web API client for Python 3
Stars: ✭ 111 (-18.38%)
Mutual labels:  api-client
Tik4net
Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Stars: ✭ 118 (-13.24%)
Mutual labels:  api-client
Bigcommerce Api Php
Connect PHP applications with the Bigcommerce Platform
Stars: ✭ 128 (-5.88%)
Mutual labels:  api-client
Nodejs Foscam
Remote control, view and config a Foscam or compatible IP camera
Stars: ✭ 113 (-16.91%)
Mutual labels:  api-client
Sdk Js
Directus JS SDK — JavaScript Software Development Kit for Node and Browser
Stars: ✭ 117 (-13.97%)
Mutual labels:  api-client
Kraken Php
Official Kraken.io library for PHP - https://kraken.io
Stars: ✭ 121 (-11.03%)
Mutual labels:  api-client
Huawei Lte Api
API For huawei LAN/WAN LTE Modems
Stars: ✭ 108 (-20.59%)
Mutual labels:  api-client
Messaging Apis
Messaging APIs for multi-platform
Stars: ✭ 1,754 (+1189.71%)
Mutual labels:  api-client
Trakt.py
Python interface for the Trakt.tv API
Stars: ✭ 117 (-13.97%)
Mutual labels:  api-client
Cloudflare Rs
Rust library for the Cloudflare v4 API
Stars: ✭ 126 (-7.35%)
Mutual labels:  api-client
Douyin Api
抖音API、抖音数据、抖音直播数据、抖音直播Api、抖音视频Api、抖音爬虫、抖音去水印、抖音视频下载、抖音视频解析、抖音直播监控、抖音数据采集
Stars: ✭ 112 (-17.65%)
Mutual labels:  api-client
Coinbase Pro Node
Coinbase Pro API written in TypeScript and covered by tests.
Stars: ✭ 116 (-14.71%)
Mutual labels:  api-client
Pykrakenapi
A python implementation of the Kraken API.
Stars: ✭ 124 (-8.82%)
Mutual labels:  api-client
Quandl R
This is Quandl's R Package
Stars: ✭ 113 (-16.91%)
Mutual labels:  api-client
Redmine Net Api
.Net API for Redmine bug/task management systems.
Stars: ✭ 131 (-3.68%)
Mutual labels:  api-client
Laqul
A complete starter kit that allows you create amazing apps that look native thanks to the Quasar Framework. Powered by an API developed in Laravel Framework using the easy GraphQL queries language. And ready to use the Google Firebase features.
Stars: ✭ 110 (-19.12%)
Mutual labels:  api-client
Pyetrade
Python E-Trade API Wrapper
Stars: ✭ 120 (-11.76%)
Mutual labels:  api-client
Pynynab
a python client for the new YNAB
Stars: ✭ 133 (-2.21%)
Mutual labels:  api-client
Vsphere Automation Sdk Java
Java samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
Stars: ✭ 132 (-2.94%)
Mutual labels:  api-client
Anyapi
AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way.
Stars: ✭ 126 (-7.35%)
Mutual labels:  api-client

NetSuite PHP API Client

License Packagist

A PHP API client package for NetSuite, pried from the NetSuite PHP Toolkit.

Adding it to your project:

Require with composer:

V2 in Alpha

composer require ryanwinchester/netsuite-php

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:

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"    => "[email protected]",
   "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

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:

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":

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:

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 = "[email protected]";

$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:

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

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

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

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

License

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].