@cafeasp/netsuite-core
v0.1.0
Published
NetSuite REST API and SuiteQL client library
Maintainers
Readme
@cafeasp/netsuite-core
NetSuite REST API and SuiteQL client library for Node.js. Zero runtime dependencies — uses only Node.js built-in modules.
Installation
npm install @cafeasp/netsuite-coreQuick Start
import {
loadConfig,
createAuthProvider,
NetSuiteClient,
SuiteQLClient,
} from "@cafeasp/netsuite-core";
// Load config from ~/.netsuite/config.json or environment variables
const config = loadConfig();
const auth = createAuthProvider(config);
const client = new NetSuiteClient(auth, config.accountId);
const suiteql = new SuiteQLClient(client);
// Run a SuiteQL query
const customers = await suiteql.query(
"SELECT id, companyname, email FROM customer",
{ limit: 10 }
);
console.log(customers.items);
// Auto-paginate through all results
const allCustomers = await suiteql.queryAll(
"SELECT id, companyname FROM customer"
);
// CRUD operations
const record = await client.getRecord("customer", "123");
const list = await client.listRecords("item", { limit: 50 });
await client.createRecord("customer", { companyname: "Acme Corp" });
await client.updateRecord("customer", "123", { email: "[email protected]" });
await client.deleteRecord("customer", "456");Authentication
Uses Token-Based Authentication (TBA) with HMAC-SHA256 signing.
Setup in NetSuite
- Enable REST Web Services and Token-Based Authentication in Setup > Company > Enable Features
- Create an Integration Record — save the Consumer Key and Consumer Secret
- Create an Access Token — save the Token ID and Token Secret
Configuration
Option A: Config file (~/.netsuite/config.json)
{
"profiles": {
"default": {
"authMethod": "tba",
"accountId": "YOUR_ACCOUNT_ID",
"consumerKey": "...",
"consumerSecret": "...",
"tokenId": "...",
"tokenSecret": "..."
}
}
}Option B: Environment variables
export NETSUITE_ACCOUNT_ID=YOUR_ACCOUNT_ID
export NETSUITE_CONSUMER_KEY=...
export NETSUITE_CONSUMER_SECRET=...
export NETSUITE_TOKEN_ID=...
export NETSUITE_TOKEN_SECRET=...Environment variables override file config.
API
loadConfig(options?)
Load config from file and/or environment. Options: { profile?: string, configPath?: string }
createAuthProvider(config)
Create an auth provider from config. Returns an AuthProvider instance.
NetSuiteClient
getRecord(type, id, options?)— GET a recordlistRecords(type, options?)— List records with filteringcreateRecord(type, body)— Create a recordupdateRecord(type, id, body)— Update a recorddeleteRecord(type, id)— Delete a recordrequest(method, path, body?, headers?)— Raw HTTP request
SuiteQLClient
query(sql, options?)— Execute SuiteQL (max 1000 rows per call)queryAll(sql)— Auto-paginate through all results
NetSuiteError
Extends Error with statusCode, errorCode, and body properties. Use NetSuiteError.fromResponse(status, body) to parse NetSuite error responses.
Related Packages
- @cafeasp/netsuite-cli — Terminal interface
- @cafeasp/netsuite-mcp — MCP server for AI clients
License
MIT
