In this short tutorial article, we will go over how to extract parameters in a SuiteCommerce service file for a "GET" and "POST" request.
Both “GET” and “POST” requests to service files can contain data the requester passed along. Extracting this data is done differently based on the request. See the tutorial article SuiteScript2(SS2) Services for SuiteCommerce for the different ways to make a request.
Best Practice: Add validation of the incoming parameters!
The code block below shows how to extract parameters passed for each request type. Remember, “fetch” calls make a “GET” request, and “save” calls make a “POST” request (more info here).
define([], function () {
"use strict";
var response = {
errors: [],
};
function service(context) {
try {
//Extract parameters from a "POST" request
if (context.request.method == "POST") {
var parameters = context.request.body ? JSON.parse(context.request.body) : {};
}
//Extract parameters from a "GET" request
else if (context.request.method == "GET") {
var parameters = context.request.parameters || {};
}
} catch (error) {
response.errors.push(error);
}
context.response.write(JSON.stringify(response));
}
return {
service: service,
};
});
We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!
If you have questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!
Tagged with Training