UNPKG

netsuite-oauth-client

Version:

NetSuite OAuth 1.0 client library for Node.js with TypeScript support

153 lines (111 loc) 4.16 kB
# NetSuite OAuth Client 🚀 Simple and easy-to-use NetSuite OAuth library for Node.js applications. No more complex OAuth setup - just plug in your credentials and start making API calls! ## Why Use This Library? - 🎯 **Simple Setup** - Just 3 lines of code to get started - 🔐 **Secure** - Handles all OAuth 1.0 complexity for you - 📝 **TypeScript Ready** - Full type support out of the box - 🛠️ **Works Everywhere** - Use with any HTTP client (axios, fetch, etc.) -**Zero Dependencies** - Lightweight and fast ## Installation ```bash npm install netsuite-oauth-client ``` ## Quick Start (3 Steps!) ### Step 1: Install and Import ```javascript const { NetSuiteOAuthClient } = require("netsuite-oauth-client"); // Or with ES6/TypeScript import { NetSuiteOAuthClient } from "netsuite-oauth-client"; ``` ### Step 2: Create Client with Your Credentials ```javascript const client = new NetSuiteOAuthClient({ accountid: "your_account_id", consumerkey: "your_consumer_key", consumersecret: "your_consumer_secret", tokenkey: "your_token_key", tokensecret: "your_token_secret", apibaseurl: "https://your-account.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql", }); ``` ### Step 3: Real-World Examples ### 📋 Get All Customers ```javascript import axios from "axios"; import { NetSuiteOAuthClient } from "netsuite-oauth-client"; const getOauthClient = new NetSuiteOAuthClient({ // Your credentials here }); async function getAllCustomers() { try { const requestOptions = client.createRequestOptions({ url: "https://your-account.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql", method: "POST", data: { q: "query", }, headers: { "Content-Type": "application/json", Accept: "application/json", Authorization: getOauthClient, }, }); const response = await axios(requestOptions); console.log("Customers:", response.data); return response.data; } catch (error) { console.error("Error:", error.message); } } getAllCustomers(); ``` ## Getting Your NetSuite Credentials ### Step 1: Create Integration Record 1. Login to NetSuite 2. Go to **Setup → Integration → New** 3. Fill in: - **Name**: Your App Name - **State**: Enabled - **Token-Based Authentication**: ✅ Checked 4. Save and copy the **Consumer Key** and **Consumer Secret** ### Step 2: Create Access Token 1. Go to **Setup → Users/Roles → Access Tokens → New** 2. Select your integration 3. Select user and role 4. Save and copy the **Token Key** and **Token Secret** ### Step 3: Find Your Account ID - Look at your NetSuite URL: `https://[ACCOUNT-ID].app.netsuite.com` - Or go to **Setup → Company → Company Information** ### Step 4: Build API URL ``` https://[ACCOUNT-ID].suitetalk.api.netsuite.com/services/rest/platform/v1 ``` ## Troubleshooting ### ❌ "Invalid signature" error - Check your consumer secret and token secret - Verify your account ID is correct - Ensure system time is accurate ### ❌ "Invalid token" error - Verify token key and token secret - Check if token is expired or disabled - Ensure user has proper role permissions ### ❌ "Access denied" error - Check user role permissions - Verify integration record is enabled - Ensure token-based authentication is enabled ### ❌ "Invalid URL" error - Check your account ID in the API base URL - Verify the endpoint path is correct ## Need Help? - 📖 **Documentation**: Check the examples above - 🐛 **Issues**: [GitHub Issues](https://github.com/yourusername/netsuite-oauth-client/issues) - 💬 **Questions**: [GitHub Discussions](https://github.com/yourusername/netsuite-oauth-client/discussions) - 📧 **Email**: tushars@satvasolutions.com ## What's Next? -**Star this repo** if it helped you! - 🔄 **Share** with your team - 🐛 **Report issues** you find - 💡 **Suggest features** you need --- _Made with ❤️ for the NetSuite developer community_