Quality Management REST API
The NetSuite Quality SuiteApp exposes REST APIs you can use to trigger quality management inspections.
The Quality Management REST API uses HTTP requests to GET, PUT, POST, and DELETE data. Here’s how the NetSuite Quality SuiteApp uses REST APIs:
GET – qm_rest_queue
The Quality GET API returns a queue entry, or queue object dump.
Use the GET request to pull information about a pending or finished quality inspection that’s been queued for tablet data collection.
-
URL
/app/site/hosting/restlet.nl?script=customscript_qm_rest_queue&deploy=1
-
Method
GET
-
URL Params
Required:
id=[integer]
-
Success Response
-
Code: 200
Example Content:
{
"message": "Loaded queue record id: 5043",
"data": {
"status": "Pending",
"location": "India",
"quantity": 1,
"triggerType": "API",
"specification": "Color and Quantity check",
"priority": "0-Urgent",
"assignedTo": "Amruta Kumbhar",
"action": "Return To Vendor",
"inventoryTransaction": "Item Receipt #42",
"transactionLine": 1,
"parentTransaction": "Purchase Order #43",
"recordStaged": true,
"statusId": 1,
"locationId": 1,
"triggerTypeId": 4,
"specificationId": 3,
"priorityId": 1,
"assignedToId": 3,
"actionId": 2,
"inventoryTransactionId": 85,
"parentTransactionId": 84
},
"requestParams": {
"id": "5043"
}
}
-
Error Response
Most endpoints can fail for several reasons, like unauthorized access or wrong parameters.
Code: 400 BAD REQUEST
Example Content:
{
"error": {
"code": "JS_EXCEPTION",
"message": "Error: {\"message\":\"Queue record 50431 does not
exist.\"}" }
}
}
POST – qm_rest_queue
The Quality Management POST API lets you create new queue records. When you create a new queue record, it triggers processing so the inspections can be done on the tablet interface.
-
URL
/app/site/hosting/restlet.nl?script=customscript_qm_rest_queue&deploy=1
-
Method
POST
-
Data Params
{
"specificationId":"integer(m)",
"itemId":"integer(m)",
"locationId":"integer(m)",
"quantity":"integer(m)",
"assignedToId":"integer",
"priorityId":"integer",
"inventoryTransactionId":"integer",
"transactionLine":"integer",
"parentTransactionId":"integer"
"actionId":"integer"}
}
-
Success Response
Code: 200
Example Content:
{
"message": "Created queue record id: 662",
"data": {
"id": 662
},
"requestBody": {
"actionId": 2,
"assignedToId": 3,
"inventoryTransactionId": 85,
"specificationId": 3,
"locationId": 1,
"quantity": 1,
"itemId": 8,
"priorityId": 1,
"parentTransactionId": 84,
"transactionLine": 1
}
}
-
Error Response
-
Code: 400 BAD REQUEST
Example Content: Negative quantity error
{ "error": { "code": "JS_EXCEPTION", "message": "Error: Unable to insert queue record: Please provide positive number for quantity" } }
-
Code: 400 BAD REQUEST
Example Content: Required field error
{ "error": { "code": "JS_EXCEPTION", "message": "Error: {\"message\":\"Missing one of required parameters\",\"data\":{\"required\": [\"specificationId\",\"locationId\",\"itemId\",\"quantity\"]},\"request Body\": {\"specificationId\":3,\"locationId\":1,\"quantity1\":1,\"itemId\":8}}" } }
-
Code: 400 BAD REQUEST
Example Content: Invalid fields
{ "error": { "code": "JS_EXCEPTION", "message": "Error: You are passing invalid field/s: test" } }
-
DELETE – qm_rest_queue
The Quality Management DELETE API lets you cancel queue records (using the Request-URL). You can only use this to cancel queue records that were created by the POST API.
-
URL:
/app/site/hosting/restlet.nl?script=customscript_qm_rest_queue&deploy=1
-
Method
DELETE
-
URL Params
Required:
id=[integer]
-
Success Response:
-
Code: 200
Example Content:
{ "message": "Queue record canceled id: 762", "data": 762, "requestParams": { "id": "762" } }
-
Error Response
Code: 400 BAD REQUEST
Example Content
{ "error": { "code": "JS_EXCEPTION", "message": "Error: {\"message\":\"REST can only modify queue records created from REST api\"}" } }
-
Scriptable Inspection Triggers
The NetSuite Quality Management includes a SuiteScript 2.0 module that lets you start predefined inspection activities (specifications) right from your SuiteScript 2.0 customizations. This means you can extend inspection capabilities to fit your unique business needs. Exposing this API helps keep things streamlined and makes sure you avoid inconsistent inspection data.
Inspection Queue Trigger through Custom API
To trigger the Quality Inspection Queue without a transaction context, select API as the Transaction Type in the Quality Specification Context. For more information, see Specification Contexts.
For any inspection queues created with the API trigger, the trigger type will be API.
You can't create a Quality Specification Context for the API trigger through the user interface.
To create an inspection queue outside Quality Management, you’ll need to write custom scripts and call the API from your application.
When you call the API, it reads the parameters and creates the right inspection queue. Then, your partner writes the code and passes in the needed parameters.
You can use the code samples as a reference. For more information, see Code Samples.
Required Parameters
You’ll need to set these required parameters:
-
locationId
-
specificationId
-
quantity
-
itemId
Non-required Parameters
You can also set these optional parameters:
-
actionId
-
assignedTold
-
inventoryTransactionId
-
priorityId
-
parentTransactionId
-
transactionLine
Methods to Execute the REST API Trigger
You can run the REST API trigger using these HTTP methods:
-
GET – to retrieve a queue.
-
POST – to create a queue.
-
DELETE – to delete a queue.
To run the REST API trigger, use this statement:
function getRestletResponse(scriptId, deploymentId, restletMethod, requestBody, urlParams) { try { var urlParameters = {}, headerObj = {}; if (urlParams) urlParameters = urlParams; var requestHeader = { 'Content-Type': 'application/json' }; if (Object.keys(headerObj).length !== 0) { requestHeader = Object.assign(requestHeader, headerObj) } var requestResponse = https.requestRestlet({ body: JSON.stringify(requestBody), deploymentId: deploymentId, headers: requestHeader, method: restletMethod, scriptId: scriptId, urlParams: urlParameters }); log.debug("Web service response from restlet", requestResponse); log.debug(scriptId + ' Response code ', requestResponse.code) var responseCode = requestResponse.code; log.debug(scriptId + ' Response body', requestResponse.body); return true; } catch (e) { log.error('Exception occurred ', e) return false; }
}
Code Samples
Here are some code samples for calling the REST API with HTTP methods:
-
GET – to retrieve a record based on a unique input like an ID.
var params = { id: 9521 }; var response = getRestletResponse('customscript_qm_rest_queue', 'customdeploy_qm_rest_queue', 'GET', '', params);
-
POST – to create a record by sending the required information in the REST API call body.
var data = { "locationId": 101, "specificationId": 322, "quantity": 10, "itemId": 359 }; getRestletResponse('customscript_qm_rest_queue', 'customdeploy_qm_rest_queue', 'POST', data, '');