NetSuite Python Client

0.12.0 · active · verified Thu Apr 16

The `netsuite` Python library provides an asynchronous client for interacting with NetSuite's SuiteTalk SOAP/REST Web Services and Restlets. It simplifies making requests, handling authentication (including Token-Based Authentication), and parsing responses. Currently at version 0.12.0, the library has a moderately active release cadence, with several minor releases and occasional breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the `NetSuite` client, which automatically picks up credentials from environment variables, and then demonstrates fetching a customer record using the REST API and executing a simple SuiteQL query. Replace placeholder IDs with your actual NetSuite data. Remember to set your NetSuite credentials as environment variables.

import asyncio
import os
from netsuite import NetSuite

async def main():
    # Ensure these environment variables are set:
    # NETSUITE_ACCOUNT, NETSUITE_CONSUMER_KEY, NETSUITE_CONSUMER_SECRET,
    # NETSUITE_TOKEN_ID, NETSUITE_TOKEN_SECRET
    
    # The NetSuite client automatically picks up credentials from environment variables.
    # For explicit config, see documentation.
    ns = NetSuite()

    print(f"NetSuite client initialized for account: {os.environ.get('NETSUITE_ACCOUNT', '[Not Set]')}")

    try:
        # Example: Fetch a specific record using the REST API
        # Replace 'customer' and '1234' with actual record type and ID in your NetSuite instance
        customer_id = '1234'
        customer_record = await ns.rest_api.get(
            f"record/v1/customer/{customer_id}"
        )
        print(f"Successfully fetched customer {customer_id}:\n{customer_record}")

        # Example: Run a SuiteQL query
        # This query selects the ID and company name of the first 5 customers
        suiteql_result = await ns.suiteql.get(
            "SELECT id, companyname FROM customer ORDER BY id LIMIT 5"
        )
        print(f"\nSuccessfully executed SuiteQL query (first 5 customers):\n{suiteql_result}")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    # Set dummy environment variables for demonstration if not set
    os.environ.setdefault('NETSUITE_ACCOUNT', 'TEST_ACCOUNT_ID')
    os.environ.setdefault('NETSUITE_CONSUMER_KEY', 'TEST_CONSUMER_KEY')
    os.environ.setdefault('NETSUITE_CONSUMER_SECRET', 'TEST_CONSUMER_SECRET')
    os.environ.setdefault('NETSUITE_TOKEN_ID', 'TEST_TOKEN_ID')
    os.environ.setdefault('NETSUITE_TOKEN_SECRET', 'TEST_TOKEN_SECRET')

    asyncio.run(main())

view raw JSON →