NetSuite SDK for Python
Netsuite-sdk-py is a Python SDK for accessing NetSuite resources via the NetSuite SOAP web service SuiteTalk. It leverages the `zeep` library internally but abstracts its complexity, providing a simplified interface for interacting with NetSuite APIs. The library is actively maintained with frequent releases, currently at version 3.1.2.
Warnings
- breaking Starting from version 3.0.0, the default WSDL version used by the SDK changed from '2019_1' to '2024_1'. If your NetSuite account is older or if your integration explicitly relies on an older WSDL version, you might experience compatibility issues.
- breaking Version 3.0.1 removed the 'Passport Complex Type'. Integrations that were directly utilizing this specific complex type will break.
- gotcha Authentication failures are common, often due to NetSuite's Two-Factor Authentication (2FA) for highly privileged roles, revoked or expired access tokens, or insufficient role permissions. Roles used for integration must have 'Web Services access' and 'Log in using Access Tokens' permissions.
- gotcha Incorrect NetSuite role permissions can lead to 'INSUFFICIENT_PERMISSION' errors or silently missing data. Even if authenticated, the user role might lack access to specific record types or fields required for an operation.
- gotcha Using incorrect internal IDs or field names for NetSuite records is a frequent source of errors (e.g., 'INVALID_FIELD_FOR_RECORD_TYPE'). NetSuite often uses specific internal field names that may not match display names.
Install
-
pip install netsuitesdk
Imports
- NetSuiteConnection
from netsuitesdk import NetSuiteConnection
Quickstart
import os
from netsuitesdk import NetSuiteConnection
from netsuitesdk.exceptions import NetSuiteLoginError
# Ensure these environment variables are set with your NetSuite TBA credentials
NS_ACCOUNT = os.getenv('NS_ACCOUNT', 'YOUR_ACCOUNT_ID')
NS_CONSUMER_KEY = os.getenv('NS_CONSUMER_KEY', 'YOUR_CONSUMER_KEY')
NS_CONSUMER_SECRET = os.getenv('NS_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET')
NS_TOKEN_KEY = os.getenv('NS_TOKEN_KEY', 'YOUR_TOKEN_KEY')
NS_TOKEN_SECRET = os.getenv('NS_TOKEN_SECRET', 'YOUR_TOKEN_SECRET')
if 'YOUR' in NS_ACCOUNT:
print("Please set NS_ACCOUNT, NS_CONSUMER_KEY, NS_CONSUMER_SECRET, NS_TOKEN_KEY, NS_TOKEN_SECRET environment variables.")
else:
try:
nc = NetSuiteConnection(
account=NS_ACCOUNT,
consumer_key=NS_CONSUMER_KEY,
consumer_secret=NS_CONSUMER_SECRET,
token_key=NS_TOKEN_KEY,
token_secret=NS_TOKEN_SECRET
)
print(f"Successfully connected to NetSuite account: {nc.account}")
# Example: Fetch all currencies
currencies = nc.currencies.get_all()
print(f"Found {len(currencies)} currencies. First 3: {currencies[:3]}")
except NetSuiteLoginError as e:
print(f"NetSuite login failed: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")