Registry / devops / netsuite-rest

netsuite-rest

JSON →
library1.1.0jsnpmunverified

A lightweight Node.js wrapper for NetSuite's SuiteTalk REST Web Services, currently at version 1.1.0. It provides a simple interface to make signed HTTP requests using Token-Based Authentication (TBA), supporting CRUD operations on records, SuiteQL queries, and HATEOAS navigation. Unlike the official NetSuite SDK, this package is a thin client that wraps the REST API directly, making it lightweight and easy to use. It has a monthly release cadence and is maintained on GitHub. Key differentiators include built-in request signing, promise-based async API, and optional custom base URL.

npm install netsuite-rest
INSTALL
IMPORT
SIG · NETSUITE-REST
N
netsuite-rest
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NsApiWrapper
const NsApiWrapper = require('netsuite-rest');
import NsApiWrapper from 'netsuite-rest';
The library uses CommonJS exports; ESM import may not work without a bundler.
new NsApiWrapper()
const api = new NsApiWrapper({ consumer_key, consumer_secret_key, token, token_secret, realm });
const api = NsApiWrapper({ consumer_key, ... }); // Missing 'new'
The constructor returns a new instance; forgetting 'new' will fail.
NsApi.request()
api.request({ path: 'record/v1/customer/', method: 'GET' }).then(res => ...).catch(err => ...);
api.request('/record/v1/customer/'); // path must be an object with at least 'path' property
The request method expects an object with path, method (optional, default GET), and optionally body.
SuiteQL
const SuiteQL = require('suiteql'); // separate package
// SuiteQL is not part of netsuite-rest; use the standalone 'suiteql' package
SuiteQL is a separate package that extends netsuite-rest for streaming queries.

Initializes the wrapper with TBA credentials from environment variables, then makes a GET request to list customers.

const NsApiWrapper = require('netsuite-rest'); const api = new NsApiWrapper({ consumer_key: process.env.NETSUITE_CONSUMER_KEY ?? '', consumer_secret_key: process.env.NETSUITE_CONSUMER_SECRET ?? '', token: process.env.NETSUITE_TOKEN ?? '', token_secret: process.env.NETSUITE_TOKEN_SECRET ?? '', realm: process.env.NETSUITE_REALM ?? '', }); api.request({ path: 'record/v1/customer/', method: 'GET' }) .then(response => console.log(response.data)) .catch(err => console.error(err));
Debug
Known issues
gotchaAll credentials (consumer_key, consumer_secret_key, token, token_secret, realm) must be provided; missing any will cause authentication failure.
fix
Ensure environment variables are set or pass them directly. The realm is your NetSuite account ID (e.g., '1234567').
affects: >=1.0.0
gotchaThe request method's path does not start with a leading slash; it is appended to the base URL. Including a leading slash may result in double slashes.
fix
Use paths like 'record/v1/customer/' (no leading slash).
affects: >=1.0.0
gotchaHTTP response codes other than 2xx cause the promise to be rejected; error handling is required for non-2xx responses (e.g., 4xx, 5xx).
fix
Always add a .catch() handler or use try/catch with async/await.
affects: >=1.0.0
deprecatedThe constructor parameter 'base_url' is optional but its behavior may change in future versions.
fix
If you rely on base_url, test after upgrading to 1.1.x; the default is https://{{realm}}.suitetalk.api.netsuite.com.
affects: 1.0.x
Errors
Common errors & fixes
Error: Consumer key missing
One or more required TBA credentials are not provided when constructing NsApiWrapper.
fix
Pass all credential parameters: consumer_key, consumer_secret_key, token, token_secret, realm.
TypeError: api.request is not a function
Attempting to call request directly on the class or forgetting to instantiate with 'new'.
fix
Use: const api = new NsApiWrapper({...}); api.request({...});
Error: Request failed with status code 401
Invalid TBA credentials or incorrect realm; NetSuite rejects the signed request.
fix
Verify consumer_key, consumer_secret, token, token_secret, and realm (NetSuite account ID). Check that TBA is enabled in NetSuite.
TypeError: Cannot read property 'data' of undefined
The response object may not contain 'data' in some error cases; non-2xx responses are rejected and the error object might not have a data property.
fix
In .catch(), check the error object structure. Use console.error(err) to inspect. Ensure you handle errors properly.
SyntaxError: Unexpected token < in JSON at position 0
NetSuite returned an HTML error page instead of JSON (e.g., due to authentication failure or incorrect path).
fix
Check the request path and credentials. Log the full error response to see the HTML content.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
oauth-1.0aoptionalUsed for signing requests with OAuth 1.0a (Token-Based Authentication).
crypto-jsoptionalProvides cryptographic functions required for OAuth signature generation.
axiosoptionalHTTP client used to make the actual REST calls.
Agent activity
4 hits · last 30 days
node
4
Resources
netsuite-rest — npm install netsuite-rest · libregistry