Using Oracle NetSuite (SuiteScript 2.1)
To use the CubeMaster API, you need an API key (TokenID) for authentication. Here's how to get started:
TokenID (e.g., abc123xyz789). Copy this key and store it securely, as it will be used in the HTTP headers of your API requests.Note: The TokenID will be used in the HTTP headers of your POST request for authentication.
A RESTful API (Representational State Transfer) is a way for two systems (like NetSuite and CubeMaster) to communicate over the internet using standard HTTP methods. Here’s a quick breakdown:
https://api.cubemaster.net/loads) where the API accepts requests.In this guide, you’ll send a POST request to the /loads endpoint with a JSON payload and a TokenID in the headers, all configured within NetSuite’s scripting environment.
NetSuite uses SuiteScript to make HTTP requests. You’ll need to create a script within NetSuite’s UI to call the CubeMaster API. Here’s how to set it up:
CubeMasterLoadBuilder. Below that, the Script File field (with a “Choose File” button) will be used later to upload your script—leave it blank for now. Optionally, add a Description in the text area (e.g., “Script to integrate with CubeMaster API”). Click the gray Save button at the bottom-right to create the script record.customscript_cubemasterloadbuilder) under the “General” tab—this is auto-generated and useful for referencing the script later.UI Tip: If you’re unsure of your role’s permissions, check under Setup > Users/Roles > Manage Roles to ensure you have the “Scripts” and “SuiteScript” permissions enabled.
The /loads endpoint requires a JSON payload describing the load details (cargoes, containers, and rules). Below is the sample request JSON:
{
"Title": "New Mixed Truck Load",
"Description": "Hello Web API",
"Cargoes": [
{
"Name": "ITEM001",
"Length": 72,
"Width": 30,
"Height": 75,
"Weight": 1002.45,
"OrientationsAllowed": "OrientationsAll",
"TurnAllowedOnFloor": false,
"Qty": 16,
"ColorKnownName": "Brown"
},
{
"Name": "ITEM002",
"Length": 27.31,
"Width": 37.5,
"Height": 76.67,
"Weight": 521.45,
"OrientationsAllowed": "OrientationsAll",
"TurnAllowedOnFloor": false,
"Qty": 28,
"ColorKnownName": "Aqua"
},
{
"Name": "SKU0005",
"Length": 27.31,
"Width": 9.5,
"Height": 75.67,
"Weight": 501.45,
"OrientationsAllowed": "OrientationsAll",
"TurnAllowedOnFloor": true,
"Qty": 24,
"ColorKnownName": "Beige"
},
{
"Name": "SKU0005",
"Qty": 23
},
{
"Name": "SKU0008",
"Qty": 34
}
],
"Containers": [
{
"VehicleType": "Dry",
"Name": "53FT-Intermodal",
"Length": 630,
"Width": 98,
"Height": 106,
"ColorKnownName": "Blue"
}
],
"Rules": {
"IsWeightLimited": true,
"IsSequenceUsed": false,
"FillDirection": "FrontToRear",
"CalculationType": "MixLoad"
}
}
You can hardcode this JSON in your SuiteScript or dynamically generate it within NetSuite. To generate it dynamically:
Name), “Length,” “Width,” “Height,” and “Weight” under the “Inventory” tab.N/record) to fetch these values and map them to the JSON structure.Use SuiteScript to send the POST request to https://api.cubemaster.net/loads with the TokenID in the headers. Here’s how to implement it in NetSuite:
CubeMasterLoadBuilder) in the list and click its name to edit.CubeMasterLoadBuilder.js. In the File Type dropdown, select “JavaScript File.” Paste the following code into the Content text area (a large text box below):define(['N/https', 'N/log'], function(https, log) {
function sendLoadRequest() {
var apiKey = 'your-api-key-here'; // Replace with your TokenID from Step 1
var url = 'https://api.cubemaster.net/loads';
var headers = {
'Content-Type': 'application/json',
'TokenID': apiKey
};
var requestBody = {
"Title": "New Mixed Truck Load",
"Description": "Hello Web API",
"Cargoes": [
{"Name": "ITEM001", "Length": 72, "Width": 30, "Height": 75, "Weight": 1002.45, "OrientationsAllowed": "OrientationsAll", "TurnAllowedOnFloor": false, "Qty": 16, "ColorKnownName": "Brown"},
{"Name": "ITEM002", "Length": 27.31, "Width": 37.5, "Height": 76.67, "Weight": 521.45, "OrientationsAllowed": "OrientationsAll", "TurnAllowedOnFloor": false, "Qty": 28, "ColorKnownName": "Aqua"},
{"Name": "SKU0005", "Length": 27.31, "Width": 9.5, "Height": 75.67, "Weight": 501.45, "OrientationsAllowed": "OrientationsAll", "TurnAllowedOnFloor": true, "Qty": 24, "ColorKnownName": "Beige"},
{"Name": "SKU0005", "Qty": 23},
{"Name": "SKU0008", "Qty": 34}
],
"Containers": [
{"VehicleType": "Dry", "Name": "53FT-Intermodal", "Length": 630, "Width": 98, "Height": 106, "ColorKnownName": "Blue"}
],
"Rules": {
"IsWeightLimited": true,
"IsSequenceUsed": false,
"FillDirection": "FrontToRear",
"CalculationType": "MixLoad"
}
};
try {
var response = https.post({
url: url,
body: JSON.stringify(requestBody),
headers: headers
});
log.debug('Response', response.body);
return response.body;
} catch (e) {
log.error('Error', e.message);
throw e;
}
}
return {
onRequest: sendLoadRequest
};
});
UI Notes: The script file is stored in the File Cabinet (Documents > Files > File Cabinet), under the “SuiteScripts” folder by default. Replace 'your-api-key-here' with your actual TokenID from Step 1.
The CubeMaster API returns a JSON response detailing the load calculation. Below is the sample response (abridged for brevity):
{
"status": "succeed",
"message": "Engine created. 5 cargoes. 1 empty containers. Calculation started. Calculation ended. The load built successfully. The load saved to the cloud database.",
"calculationError": "InvalidCargoSize",
"document": {
"title": "New Mixed Truck Load",
"description": "Hello Web API",
"isShared": true,
"isAutoSaved": true,
"isPending": false,
"calculationTimeInSeconds": 0.6152743,
"processId": "",
"batchId": "",
"createdBy": "CHANG@LOGEN.CO.KR",
"createdAt": "2023-02-11T01:17:01.7392204+09:00",
"updatedAt": "0001-01-01T00:00:00"
},
"loadSummary": {
"cargoesLoaded": 68,
"piecesLoaded": 68,
"cargoesLeft": 0,
"piecesLeft": 57,
"unitloadsLoaded": 0,
"volumeLoaded": 5261723.4606,
"weightLoaded": 42674.59999999999,
"priceLoaded": 0,
"containersLoaded": 1
},
"filledContainers": [
{
"name": "#1 53FT-Intermodal",
"sequence": 1,
"loadSummary": {
"cargoesLoaded": 68,
"piecesLoaded": 68,
"unitloadsLoaded": 0,
"volumeLoaded": 5261723.4606,
"volumeUtilization": 80.39990374424703,
"vollumeUtilizationToLoadHeight": 81.03441853085657,
"floorLoaded": 57090.75,
"floorUtilization": 92.46963070942662,
"weightLoaded": 42674.59999999999,
"weightTotal": 42674.59999999999,
"weightUtilization": 0,
"dimWeight": 39424.33734939759,
"priceLoaded": 0,
"pricetUtilization": 0,
"cargoesPerLayer": 14,
"layersPerUnitload": 0
}
}
]
}
Handling in NetSuite:
JSON.parse(response.body). Store key values (e.g., cargoesLoaded, volumeUtilization) in a custom record or transaction.log.debug. Filter logs by date or type using the dropdowns above the log table.status isn’t "succeed", log the error via log.error and review under Customization > Scripting > Script Execution Logs. The log list shows columns like “Date,” “Type,” and “Details.”After writing the script, test and deploy it in NetSuite:
CubeMasterLoadBuilder.js.customdeploy_cubemasterload, select Status as “Released” from the dropdown, and check the Execute as Role dropdown (default is “Administrator”). Click Save. Note the URL field (e.g., /app/site/hosting/scriptlet.nl?script=123&deploy=1) for testing.log.debug). Check Customization > Scripting > Script Execution Logs for detailed output in the “Details” column.UI Tip: Use the System Notes tab on the script or deployment record to track changes (e.g., “Field Changed” logs).