Quality Management REST API
The NetSuite Quality SuiteApp exposes REST APIs that enable you to trigger quality management inspections.
Quality Management REST API uses HTTP requests to GET, PUT, POST, and DELETE data. To learn how the NetSuite Quality SuiteApp leverages REST APIs, see the following:
GET – qm_rest_queue
The Quality GET API returns a queue entry, or queue object dump.
Use the GET request to retrieve relevant information about a pending or complete quality inspection that has 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 in many ways. For example, from unauthorized access to wrongful 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 enables you to create new queue records. Creating a new queue record triggers processing to allow the associated inspections to be performed 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: Mandatory 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 is used to cancel queue records (identified by the Request-URL). You can only use this API to cancel queue records that have been 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 enables you to initiate predefined inspection activities (specifications) from within SuiteScript 2.0 customizations to NetSuite. This enhancement enables you to extend inspection capabilities to address your unique market and organizational inspection needs. Exposing this API ensures that implementations are streamlined and have the necessary safeguards to 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 all inspection queues created with the API trigger, the trigger type will be API.
You cannot create a Quality Specification Context for the API trigger through the user interface.
To create an inspection queue outside of Quality Management, you must create custom scripts and call the API from your application.
When you call the API, the parameters are read by the API, and an appropriate inspection queue is created. Then, the partner writes the code and passes the parameters as required.
You can use the code samples as reference. For more information, see Code Samples.
Mandatory Parameters
You must set the following mandatory parameters:
-
locationId
-
specificationId
-
quantity
-
itemId
Non-mandatory Parameters
Optionally, you can set the following non-mandatory parameters:
-
actionId
-
assignedTold
-
inventoryTransactionId
-
priorityId
-
parentTransactionId
-
transactionLine
Methods to Execute the REST API Trigger
You can execute the REST API trigger using the following HTTP methods:
-
GET – to retrieve a queue.
-
POST – to create a queue.
-
DELETE – to delete a queue.
To execute the REST API trigger, enter the following 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
The following code samples show how to call the REST API using HTTP methods:
-
GET – to retrieve a record based on a unique input such as ID.
var params = { id: 9521 }; var response = getRestletResponse('customscript_qm_rest_queue', 'customdeploy_qm_rest_queue', 'GET', '', params);
-
POST – to create a record by passing required information in the body of the REST API call.
var data = { "locationId": 101, "specificationId": 322, "quantity": 10, "itemId": 359 }; getRestletResponse('customscript_qm_rest_queue', 'customdeploy_qm_rest_queue', 'POST', data, '');