Oracle NetSuite provides a strong API for integrating and lengthening what you are promoting workflows, however working successfully with these APIs requires a strong understanding of how they perform.
On this information we dive deep into the evolution of NetSuite’s API choices, the variations between NetSuite’s SOAP and REST APIs, establishing API-based purposes, and scaling your deployments – all whereas leveraging NetSuite’s SuiteQL and SuiteScript for extra complicated eventualities. We’ll additionally discover how instruments like Nanonets will help automate your workflows throughout information layers.
Understanding NetSuite’s API Ecosystem
NetSuite began with the SuiteTalk SOAP API in 2002, which grew to become the go-to answer for companies trying to combine their methods with NetSuite’s deep characteristic set. For a few years, this was the usual API for NetSuite growth.
To handle the eventual limitations within the SOAP API, NetSuite launched its REST API in 2019, providing an easier, extra scalable solution to entry information. The REST API embraced trendy net requirements like JSON, offering simpler integration with cloud-native purposes and APIs. Nonetheless, not all is nice with the REST API, as we’ll see later on this information.
NetSuite additionally launched SuiteQL, launched alongside the REST API – to additional enhance information querying with SQL-like syntax. Because it seems, SuiteQL probably the most helpful options of the REST API.
The SuiteTalk SOAP API
The NetSuite SOAP API has remained the usual for a few years for any NetSuite integrations, and even at the moment numerous integrations will utilise the SOAP API just because it’s dependable and has good assist.
The API makes use of complicated XML payloads and has strict formatting, so whereas it would initially appear good to have a excessive stage of element in each API name, it may well shortly turn into cumbersome for instances the place you must combine the APIs at some stage of scale.
Additional, all the metadata (principally the information about the NetSuite objects) is saved in a format known as WSDL (Internet Providers Description Language). And the one metadata you get is that of the usual NetSuite objects and fields.
So should you created any customized fields (or, god forbid, total customized objects) – you will not see them right here. There is a good approach round this – utilizing RESTlets – however that may shortly get messy.
What are RESTlets? Earlier than we go additional, let’s perceive just a few NetSuite API ideas (be happy to skip forward in case you are already nicely versed).
SuiteScript and RESTlets
To outline a RESTlet, we’ll first need to outline what SuiteScript is.
💡
SuiteScript is a scripting language based mostly on JavaScript, that enables NetSuite builders (sure, that is you) to create custom-made scripts and features that may be triggered on sure actions/occasions. It is a nifty solution to customise non-standard actions in NetSuite.
This is a pattern SuiteScript that updates the e-mail deal with of a buyer file in NetSuite:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
outline(['N/record'], perform(file) {
perform beforeSubmit(context) {
var customerRecord = context.newRecord;
// Set a brand new e-mail deal with
customerRecord.setValue({
fieldId: 'e-mail',
worth: '[email protected]'
});
}
return {
beforeSubmit: beforeSubmit
};
});
💡
A RESTlet is a SuiteScript that may be executed by one other utility outdoors NetSuite (or additionally by one other SuiteScript) – and may return information again to that utility.
For instance – you may create a RESTlet to return information from NetSuite on the present stock held. You may then use this information in one other utility (like operating an approval course of for Buying Managers to approve a purchase order requisition based mostly on present stock ranges).
Nonetheless, creating and scaling RESTlet utilization is cumbersome. It may be performed, however wants a devoted place to host your code and enterprise logic + preserve observe of all customized entities (extra on this later).
The NetSuite REST API
Designed to be light-weight and extra fitted to cloud-based apps, the REST API makes use of JSON payloads, decreasing overhead in information transmission. The transition from SOAP to REST mirrored the rising demand for less complicated, quicker, and extra accessible integrations, significantly for cell apps and cloud ecosystems.
As is the case with most REST APIs, it may be tempting to fully sideline NetSuite’s SOAP API – just because growing with a REST API is usually a lot simpler. However in NetSuite’s case, this is not at all times true.
The article construction within the REST API is tough to cope with (owing partially to poor implementation of an object construction known as HATEOAS) which principally signifies that the information of an object isn’t returned completely in a single go, however in nested hyperlinks.
This is an instance – should you name a REST API endpoint like /distributors you’ll usually count on one thing like this within the response:
{
{
"vendorId": "123abc",
"vendorName": "Check Vendor"
},
{
"vendorId": "123abcd",
"vendorName": "Check Vendor 2"
},
{
"vendorId": "123abcde",
"vendorName": "Check Vendor 3"
}
}
As a substitute, what you get is a set of IDs of every vendor, and API hyperlinks to the person vendor entities themselves. So now you must know the ID of the seller you actually wish to get information for.
For those who do not already know this ID, you are going to need to iterate over 500+ distributors for any fundamental operation. Each. Single. Time.
There’s a approach out, although, and that’s to make use of SuiteQL.
What’s SuiteQL?
💡
SuiteQL is a question language (like SQL) that means that you can question the complete NetSuite information construction. It is part of the NetSuite REST API, and a useful one at that.
In reality, there’s a complete separate endpoint within the REST API to name SuiteQL. Let’s take the instance above – this is how you should use SuiteQL to seek out information for the Vendor that you really want:
HTTP Methodology - POST
https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/question/v1/suiteql
//Ship the precise SuiteQL question beneath within the request physique
{
"q": "SELECT * FROM Vendor the place vendorName="Check Vendor 2""
}
What about customized entities and fields in REST?
That is barely simpler within the REST API as nicely, as NetSuite offers a separate metadata catalog as a REST endpoint, and you’ll question (and persist if wanted) the complete schema of all objects.
This is a pattern REST API payload (you may see how easy this seems in comparison with the SOAP-y mess we noticed earlier).
import requests
from requests_oauthlib import OAuth1
url="https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/file/v1/vendorBill"
auth = OAuth1('<consumer_key>', '<consumer_secret>', '<token>', '<token_secret>')
payload = {
"entity": {"id": "12345"},
"lineItems": [
{"item": {"id": "5678"}, "quantity": 5},
{"item": {"id": "9012"}, "quantity": 3}
]
}
response = requests.submit(url, json=payload, auth=auth)
print(response.json())
SOAP vs REST API: Which one do you have to use?
The cliched (however sadly, appropriate) reply is that it actually relies on your use case. Whereas SOAP excels in environments requiring restricted transactions on commonplace objects and excessive safety, REST is most well-liked for its simplicity, flexibility and velocity.
Benefits of the REST API
- JSON Payloads: Simple to learn and debug, light-weight, and reduces bandwidth overhead.
- Sooner Improvement: You don’t must predefine strict constructions like SOAP’s WSDL.
- Simpler to make use of SuiteQL: SuiteQL might be probably the most highly effective facet of NetSuite’s API, and is a breeze to make use of with REST. With SOAP, you must create a RESTlet to make use of SuiteQL.
Good Use Circumstances for the REST API
- Light-weight deployments like cell apps or third occasion purposes the place fundamental CRUD operations (create, learn, replace and delete) have to be performed at velocity.
- Advanced Workflows with Customized Knowledge – For those who’re working with customised NetSuite information constructions, SuiteQL is by far one of the best ways to question and mix information. For instance, processes just like the beneath:
- Approval workflows based mostly on customized fields, or
- Customised 2-way/3-way PO matching
Benefits of the SOAP API
- Dependable: Robust documentation and assist since it’s a lot older.
- Helps Saved Searches: One of many favorite methods of NetSuite customers to get filtered, custom-made information, this extends the Saved Search performance on to the API.
Good Use Circumstances for the SOAP API
- Legacy deployments (like linking NetSuite to banking information) the place reliability and thoroughness of knowledge is extra essential than velocity.
- Utilising Saved Searches – The SOAP API natively helps Saved Searches, that are a really helpful approach of trying to find information on the NetSuite UI. In case you are replicating Saved Searches and pushing that information into one other utility, SOAP may be helpful.
You may discover much more element on the professionals/cons of every API in this weblog by Eric Popivker.
Setting Up the NetSuite API to make API calls
For the remainder of this text, we’ll use the REST API as the idea for dialogue (nonetheless most of the identical processes will work with the SOAP API too).
Let’s undergo a step-by-step information to arrange the REST API and make an API name.
- Create an Integration Report:
- In NetSuite, navigate to
Setup > Integration > Handle Integrations > New
. - Identify your integration (e.g., “My REST API Integration”).
- Verify “Token-Primarily based Authentication (TBA)” to allow it for the mixing.
- Save the file to generate the
Shopper Key
andShopper Secret
. You may want these for OAuth authentication.
- In NetSuite, navigate to
- Assign Roles and Permissions:
- Go to
Setup > Customers/Roles > Entry Tokens > New
. - Choose the mixing you simply created.
- Select the person and position (usually an admin or a job with the required permissions to entry information through the API).
- Generate the
Token ID
andToken Secret
.
- Go to
- OAuth Setup:
- Create an entry token through
Setup > Customers/Roles > Entry Tokens > New
. - You’ll get a
Token
andToken Secret
in your utility. - NetSuite makes use of OAuth 1.0a for authentication. This requires the above 4 key parameters:
Shopper Key
Shopper Secret
Token ID
Token Secret
- Create an entry token through
REST API Name Instance:
Your REST API calls will want each headers and physique (relying on the kind of request).
- Headers:
- Authentication: The first authentication is dealt with through OAuth 1.0a. You’ll cross OAuth tokens within the header.
- Content material-Sort: For POST or PUT requests, set this to
utility/json
since NetSuite REST API works with JSON information.
Authorization: OAuth oauth_consumer_key="<consumer_key>",
oauth_token="<token>",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="<timestamp>",
oauth_nonce="<random_string>",
oauth_signature="<signature>"
Content material-Sort: utility/json
- Physique: The physique of the request is required when making POST or PUT requests, usually in JSON format. For instance, when making a buyer file, your physique would possibly seem like this:
{
"companyName": "ABC Corp",
"e-mail": "[email protected]",
"cellphone": "555-555-5555"
}
This is a full API name for instance:
import requests
from requests_oauthlib import OAuth1
url="https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/file/v1/buyer"
auth = OAuth1('<consumer_key>', '<consumer_secret>', '<token>', '<token_secret>')
headers = {
'Content material-Sort': 'utility/json'
}
information = {
"companyName": "ABC Corp",
"e-mail": "[email protected]",
"cellphone": "555-555-5555"
}
response = requests.submit(url, json=information, auth=auth, headers=headers)
print(response.json())
Frequent points you would possibly run into:
- OAuth Setup: “Invalid signature” errors are widespread with OAuth 1.0a, usually attributable to incorrect parameter ordering or key misconfiguration.
- Incorrect API URL: Make sure that you’re utilizing the right NetSuite account ID within the API endpoint URL, e.g.,
https://<account_id>.suitetalk.api.netsuite.com
. - 403 Forbidden: This may very well be resulting from incorrect permissions or entry ranges for the person or position tied to the token.
Use an API testing software like Postman or Insomnia for simpler debugging and assist with API points.
Connecting NetSuite to different purposes
NetSuite usually has pre-configured SuiteApp integrations and workflow instruments that may interface with numerous enterprise purposes, together with:
- CRM Instruments: Combine with Salesforce, HubSpot, or Zoho to sync buyer and gross sales information.
- Office Apps: Instruments like Slack and Microsoft Groups may be built-in for real-time notifications or workflows.
- E-commerce Platforms: Join NetSuite to platforms like Shopify or Magento for stock syncs and order administration.
There are additionally a number of software program platforms that usually enable you arrange drag-and-drop workflows with these integrations:
- Celigo
- Workato
- MuleSoft
- Boomi
When are these pre-built workflow integrations helpful?
You may clear up numerous enterprise issues with good integrations. Consider instances like:
- Having to cross-check a buyer bill in NetSuite towards buyer information that is current in Salesforce/Hubspot
- Having to manually enter information into NetSuite when scanning complicated payments/invoices as a result of the OCR template is model new and never recognised
However they might not clear up all of your issues. Think about the beneath scenario:
⚠️
It’s a must to ship out a NetSuite Vendor Invoice for division approval, however your group works solely on Slack and you’ll’t actually purchase a brand new NetSuite license for ALL of them to simply approve a invoice.
One other widespread situation – what you are promoting would possibly depend on robust real-time stock monitoring. So that you arrange SuiteScripts to repeatedly monitor inventory ranges – however now it is impacting your NetSuite system efficiency.
Pre-built integrations go solely thus far, as we’ll discover out subsequent.
Why Use the NetSuite API if Pre-built Integrations Already Exist?
Pre-built workflow instruments and integrations simplify the setup for widespread use instances however fall brief in dealing with complicated, custom-made workflows. As an illustration, in the case of doing complicated processes at scale, you’ll most likely want to show to the API.
Let’s take an instance – say you may have a Buy Order matching course of the place you must match a PO to a number of vendor payments.
The usual NetSuite API has a perform known as PO Rework, that will probably be current on many pre-built integrations and will probably be built-in on the back-end code of most AP SaaS options.
This REST technique has the beneath endpoint:
https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/file/v1/purchaseOrder/<purchase_order_internal_id>/!remodel/vendorBill
You may name this API within the method beneath:
import requests
from requests_oauthlib import OAuth1
# NetSuite account data
account_id = '<account_id>'
purchase_order_id = '<purchase_order_internal_id>'
url = f'https://{account_id}.suitetalk.api.netsuite.com/providers/relaxation/file/v1/purchaseOrder/{purchase_order_id}/!remodel/vendorBill'
# OAuth1 Authentication
auth = OAuth1('<consumer_key>', '<consumer_secret>', '<token>', '<token_secret>')
payload = {
"entity": {
"id": "<vendor_id>"
},
"memo": "Transformed from PO",
"location": {
"id": "2"
},
"lineItems": [
{
"item": {"id": "1234"},
"quantity": 10,
"amount": 100.00
}
]
}
response = requests.submit(url, json=payload, auth=auth)
print(response.json())
The difficulty with the predefined technique is that it’s going to find yourself billing the ENTIRE Buy Order. There isn’t any approach so that you can limit it by choosing solely a part of the amount as per the Vendor Invoice.
So what’s the answer?
Constructing a fancy workflow utilizing the API as an alternative of No-Code instruments
Let’s now exhibit a greater solution to deal with the above scenario the place the pre-built integration fails. To attain our goal on this PO matching situation, we might want to use a SuiteQL question after which run a SuiteScript as beneath:
SuiteQL Question
SELECT id, merchandise, amount, quantity
FROM transactionLine
WHERE transactionType="PurchaseOrder"
AND transaction.id = '12345';
This SQL-like question fetches information for a selected Buy Order, which you should use as enter for additional API calls or workflow automation. Be aware that we needn’t iterate by way of EVERY buy order to get this performed.
The REST API name for this SuiteQL question is:
curl -X POST https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/question/v1/suiteql
-H "Authorization: OAuth oauth_consumer_key='<consumer_key>', oauth_token='<token>', oauth_signature="<signature>""
-H "Content material-Sort: utility/json"
-d '{
"q": "SELECT id, merchandise, amount, quantity FROM transactionLine WHERE transactionType="PurchaseOrder" AND transaction.id = '12345';"
}'
SuiteScript for Creating Vendor Invoice
perform createVendorBill(poId) {
var poRecord = file.load({
sort: file.Sort.PURCHASE_ORDER,
id: poId
});
var billRecord = file.create({
sort: file.Sort.VENDOR_BILL
});
for (var i = 0; i < poRecord.getLineCount('merchandise'); i++) {
var amount = poRecord.getSublistValue({ sublistId: 'merchandise', fieldId: 'amount', line: i });
if (amount > 0) {
billRecord.selectNewLine({ sublistId: 'merchandise' });
billRecord.setCurrentSublistValue({ sublistId: 'merchandise', fieldId: 'merchandise', worth: poRecord.getSublistValue({ sublistId: 'merchandise', fieldId: 'merchandise', line: i }) });
billRecord.setCurrentSublistValue({ sublistId: 'merchandise', fieldId: 'amount', worth: amount });
billRecord.commitLine({ sublistId: 'merchandise' });
}
}
billRecord.save();
}
This SuiteScript is customizable – you may select to replace portions on the PO partially, or you may select to by no means replace the PO till it’s absolutely matched throughout a number of invoices. The selection is totally yours.
You may set off this SuiteScript through the REST API as nicely. Beneath is the pattern API name:
curl -X POST https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/script/v1/scriptexecution
-H "Authorization: OAuth oauth_consumer_key='<consumer_key>', oauth_token='<token>', oauth_signature="<signature>""
-H "Content material-Sort: utility/json"
-d '{
"scriptId": "customscript_create_vendor_bill",
"deploymentId": "customdeploy_create_vendor_bill",
"params": {
"poId": "12345"
}
}'
On this approach you may leverage the flexibleness of the NetSuite API, SuiteQL, and SuiteScript to automate complicated enterprise processes.
In case you are thinking about going deeper into PO matching, this is a detailed information we revealed.
Learn how to run your API calls from an utility
When you can take a look at API calls in Postman, you will have a extra organized solution to work together with the NetSuite API and truly retailer and use the information you fetch.
To start out with, you may arrange a small utility in Python. Right here’s the essential setup for doing this:
Create a Python File:
import requests
from requests_oauthlib import OAuth1
def netsuite_api_call():
url="https://<account_id>.suitetalk.api.netsuite.com/providers/relaxation/file/v1/buyer"
auth = OAuth1('<consumer_key>', '<consumer_secret>', '<token>', '<token_secret>')
response = requests.get(url, auth=auth)
return response.json()
if __name__ == "__main__":
print(netsuite_api_call())
Set up Required Libraries:
pip set up requests requests_oauthlib
Storing Knowledge:
For one-off use instances, you may get by with storing information domestically in a JSON.
with open('netsuite_data.json', 'w') as file:
json.dump(information, file, indent=4)
For instances with extra information and common API calls to be performed, you may arrange a SQL database like SQLite3 utilizing the beneath pattern code.
import sqlite3
conn = sqlite3.join('netsuite_data.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS clients (
id INTEGER PRIMARY KEY,
title TEXT,
e-mail TEXT
)
''')
# Insert information into the database
for buyer in information['items']:
cursor.execute('''
INSERT INTO clients (id, title, e-mail)
VALUES (?, ?, ?)
''', (buyer['id'], buyer['companyName'], buyer['email']))
conn.commit()
conn.shut()
Nonetheless past a sure level, you will want a manufacturing DB and a solution to correctly administer and handle all this NetSuite information.
Deploying NetSuite APIs at Scale
Deploying NetSuite APIs at scale requires cautious consideration of efficiency, automation, and the layers of information you’re working with. Finish-to-end workflow automation instruments are usually the perfect match for this – they will significantly simplify this course of by offering an surroundings that means that you can handle automation throughout completely different layers.
Automating Throughout 3 Knowledge Layers
- Doc Layer:
- This consists of processing paperwork like POs, invoices, financial institution statements, and vendor payments. Instruments usually use AI-enabled OCR and machine studying to extract information from these paperwork.
- AP Course of Layer:
- The AP course of layer entails enterprise logic, reminiscent of approval routing and matching paperwork like POs to invoices. Workflow instruments can automate the logic right here to automate these processes.
- ERP Layer:
- The ERP layer refers back to the information and operations inside NetSuite itself. Utilizing NetSuite’s API, these workflow instruments can sync bi-directionally with NetSuite to push or pull information from the system, with out compromising the grasp information.
Nanonets is an AI workflow automation software that enables companies to orchestrate these layers in concord, enabling doc understanding, a easy AP course of, and sustaining a single supply of reality inside NetSuite.
Why Nanonets is Supreme for Scaling NetSuite API Utilization
- Finest-in-class AI enabled OCR: Knowledge extraction that does not rely upon OCR templates and repeatedly learns from person inputs.
- Enterprise Logic Automation: By permitting customized code deployment, Nanonets automates processes like bill matching, approval routing, and PO creation.
- Deep ERP Sync: Interface in real-time with each single information level in NetSuite, together with customized objects and fields.
A pattern workflow with Nanonets just like the one beneath, takes solely 15-20 minutes to arrange.
Inquisitive about studying extra? A brief 15-minute intro name with an automation professional is one of the best ways to get began.
References: