Skip to main content

Easily work with Netsuite's REST API

Project description

restsuite

restsuite is a python package developed to help developers interact with the Netsuite REST API. restsuite offers a number of classes that can be utilized to interact with Netsuite's Suite-Talk, RESTlet, or SuiteQL services. restsuite currently utilizes Netsuite's token authentication methods, however, current development is under way for supporting Netsuite's Oauth2 authentication methods.

Installation

restsuite is part of the Python Package Index (PyPI) and can thus be installed with pip:

pip install restsuite

restsuite requires a python version of 3.8 or higher and depends on the requests python package and the requests_oauthlib python package

Getting Started

As restsuite is an abstraction of the Netsuite API, it will be helpful to become familiar with, or at least reference, the Netsuite API documentation:

Authentication

Each of the provided classes (NetSuiteRest, NetSuiteRESTlet, NetSuiteQL) utilize the requests_oauthlib package to handle authentication for the developer. All that is required is basic account information that can be generated in the user's account integration settings (see REST Web Services Prerequisites and Setup for a guide on setting up your Netsuite application to utilize REST capabilities)

Each class requires that you pass the following attributes upon object instantiation:

  • Netsuite Account ID : This can be found the Netsuite url path (e.g: https://{{ account_id }}.app.netsuite.com))
  • Consumer Key : Consumer Key and Secret are provided upon integration record creation Integration Record Overview.
  • Consumer Secret : Consumer Secret is provided upon integation record creation Integration Record Overview
  • Token Key : Tokens can be generated a number of ways. We are currently developing a Class for generating tokens with the issuetoken endpoint. For the time being, you can generate a token with the Netsuite UI.
  • Token Secret : See Token Key

Suite-Talk

The restsuite.NetSuiteRest class provides an interface to NetSuite's Suite-Talk API.

For a full list of available resources, see the NetSuite REST API Browser: Record API v1

Examples:

Instantiating a Suite-Talk object:

import restsuite

netsuite = restsuite.NetSuiteRest(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)

Getting a Record (GET):

url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job".format(NS_ACCOUNT_ID)

response = netsuite.request("GET", url)

if response.status_code < 300:
    data = response.json()

Getting docs

It is important to note here that all classes will require the full URL to be passed to each request method.

Creating a Record object (POST):

url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"entityid": "New Customer", "companyname": "My Company", "subsidiary": {"id": "1"}}

response = netsuite.request("POST", url=url, body=body)

Creating docs

Updating a Record object (PATCH):

url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"entityid": "Updated Customer"}

response = netsuite.request("PATCH", url=url, body=body)

Updating docs

Upserting a Record object (PUT):

url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

body = {"firstName": "John", "lastName": "Smith"}

response = netsuite.request("PUT", url=url, body=body)

Upsert docs

Deleting a Record object (DELETE)

url = "https://{}.suitetalk.api.netsuite.com/services/rest/record/v1/job/12345".format(NS_ACCOUNT_ID)

response = netsuite.request("DELETE", url=url)

RESTlet

"A restlet is a SuiteScript that executes when called by an external application or by another SuiteScript. Depending on how the RESTlet is written and called, it may also return data to the calling application."

The restsuite.NetSuiteRESTlet class acts as an external application that allows you to activate RESTlets based on a handful of HTTP verbs:

  • GET
  • POST
  • PUT
  • DELETE

These verbs, however, act more as a guide than as the strict HTTP verbs described here. This is because the actual actions taken are defined in the RESTlets themselves, and the verbs are used to call certain functions within the RESTlet. More information can be found on RESTlets here.

Examples:

Calling a RESTlet is similar to the Suite-Talk methods shown above. Only one example will be given here to highlight the difference in the URL path, everything else will be the same.

Sending a GET request to RESTlet:

import restsuite

netsuite = restsuite.NetSuiteRESTlet(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)

url = "https://{}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script={}&deploy={}".format(NS_ACCOUNT_ID, SCRIPT_ID, DEPLOYMENT_ID)

response = netsuite.request("GET", url)

SuiteQL

NetSuite allows for users to query their records their version of SQL, SuiteQL. In order to utilize SuiteQL, query strings are sent to a suiteql endpoint. SuiteQL queries can be sent to Netsuite using the NetSuiteQL class:

import restsuite

netsuite = restsuite.NetSuiteQL(
    account_id = NS_ACCOUNT_ID,
    consumer_key = CONSUMER_KEY,
    consumer_secret = CONSUMER_SECRET,
    token_key = TOKEN_KEY,
    token_secret = TOKEN_SECRET
)

data = netsuite.suiteql("Select * From job where id = 12345")
print(data)

The suiteql method returns a list of dictionary-type objects, where each object is a record of the queried record-type. For this specific example, each object would be a job record-type that matched the id of 12345.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

restsuite-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

restsuite-1.0.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file restsuite-1.0.0.tar.gz.

File metadata

  • Download URL: restsuite-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for restsuite-1.0.0.tar.gz
Algorithm Hash digest
SHA256 89db3a637407a186b2143706afb82e61fb2455b4841259f5ee6455aea437f6cb
MD5 a3fb44f212bda5e7172c95f48dc3846f
BLAKE2b-256 66ed876a6ae33faba876700d6587f89647c57ec900cadb12a21ce3e9eeaeac38

See more details on using hashes here.

File details

Details for the file restsuite-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: restsuite-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for restsuite-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55d231f4c380f3c90a7251cf0d0c70b630fef8e3463d7a3256f1adc13bf62082
MD5 eb953b81e4ad7b287726cd0a2661a8af
BLAKE2b-256 b412bac3c86ee8a986219e0ba6da1bfeb1006fe351ae35c9b7cb2ba54f6f5594

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page