npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netsuite-nodejs-api-client

v1.0.5

Published

A TypeScript Node.js module to connect to the NetSuite API

Downloads

282

Readme

NSClient - NetSuite API Client

NSClient is a Node.js client library for interacting with NetSuite's SuiteTalk REST API and RESTlets using OAuth 1.0a authentication. It provides helper functions for executing SuiteQL queries, making RESTlet calls, and performing other general-purpose API requests to the NetSuite platform.

Features

  • SuiteQL Execution: Run SuiteQL queries to retrieve data from NetSuite.
  • RESTlet Calls: Call custom RESTlets in NetSuite with script and deployment IDs.
  • General API Requests: Make authenticated requests to any NetSuite REST endpoint.
  • OAuth 1.0a Authentication: Automatically signs requests using OAuth 1.0a for secure NetSuite API access.

Prerequisites

  • Node.js: Ensure Node.js is installed.
  • NetSuite OAuth 1.0a Credentials: To use this client, you need a NetSuite Account ID, Consumer Key, Consumer Secret, Token ID, and Token Secret. These can be obtained by setting up an integration in NetSuite and generating tokens.

Installation

To install the dependencies required for this client, use:

npm install axios axios-oauth-1.0a

Environment Configuration

Create an environment configuration file to store your NetSuite credentials:

ACCOUNT_ID=your_account_id
CONSUMER_KEY=your_consumer_key
CONSUMER_SECRET=your_consumer_secret
TOKEN_ID=your_token_id
TOKEN_SECRET=your_token_secret

Usage

1. Initialization

Import and instantiate the NSClient:

import NSClient from './path/to/NSClient';

const client = new NSClient();

2. Methods

fetchSuiteQL

Executes a SuiteQL query against NetSuite.

const query = "SELECT id, companyname FROM customer WHERE isinactive = 'F'";
const offset = 0;
const limit = 10;

try {
  const response = await client.fetchSuiteQL(query, offset, limit);
  console.log('SuiteQL Response:', response.data);
} catch (error) {
  console.error('Error executing SuiteQL:', error);
}
  • Parameters:
    • query (string): The SuiteQL query to execute.
    • offset (number, optional): Pagination offset. Defaults to 0.
    • limit (number, optional): Number of records to retrieve per page. Defaults to 10.
  • Returns: Promise<AxiosResponse<NSBaseRestResponse>>

getRestlet

Calls a NetSuite RESTlet using the specified script and deployment IDs.

const scriptId = 1234;
const deployId = 1;
const params = { param1: 'value1', param2: 'value2' };

try {
  const response = await client.getRestlet(scriptId, deployId, params);
  console.log('RESTlet Response:', response.data);
} catch (error) {
  console.error('Error calling RESTlet:', error);
}
  • Parameters:
    • scriptId (number): The ID of the RESTlet script to call.
    • deployId (number, optional): The deployment ID of the RESTlet. Defaults to 1.
    • params (Record<string, string>): Query parameters to pass to the RESTlet.
  • Returns: Promise<AxiosResponse<T>>

request

Makes a generic API request to any NetSuite endpoint.

const options = {
  path: '/record/v1/customer',
  method: 'GET',
  body: {},  // For POST/PUT requests, include data here
};

try {
  const response = await client.request(options);
  console.log('API Response:', response.data);
} catch (error) {
  console.error('Error making API request:', error);
}
  • Parameters:
    • options (NetsuiteRequestOptions): Object with the following properties:
      • path (string): The API endpoint path.
      • method (string): HTTP method (GET, POST, PUT, DELETE).
      • body (any, optional): Data to send with the request.
  • Returns: Promise<AxiosResponse<T>>

Error Handling

All methods throw NetsuiteError when errors occur during the API call. Be sure to handle errors appropriately, as shown in the examples.

Example

(async () => {
  const client = new NSClient();

  // SuiteQL Example
  const suiteql = "SELECT id, companyname FROM customer WHERE isinactive = 'F'";
  const suiteqlResponse = await client.fetchSuiteQL(suiteql);
  console.log('SuiteQL Data:', suiteqlResponse.data);

  // RESTlet Example
  const restletResponse = await client.getRestlet(1234, 1, { custparam: '123' });
  console.log('RESTlet Data:', restletResponse.data);
})();

License

MIT License

Support

For any issues or questions, feel free to reach out or open an issue in the repository.