RESTLet – Add Commerce Categories

It is not possible to manipulate commerce categories using SuiteTalk. You can do it with CSV imports or by calling a RESTlet. CSV imports can get messy if you have lots of nested categories. Here is an example of a RESTlet that adds a commerce category.


This function is called via a post request:

POST:  function(datain) { addCommerceCategory(datain); }

Here is the code in a format that can be easily copied:

addCommerceCategory: function(datain) {
if (!datain) return “Missing datain”;
if (!datain.externalid) return “Missing externalid”;
if (! return “Missing name”;
if (!datain.primaryparent) return “Missing primaryparent”;
if (!datain.pagetitle) return “Missing pagetitle”;
var record = nlapiCreateRecord(‘commercecategory’);
record.setFieldValue(‘catalog’, ‘1’);
if (datain.urlfragment) {
record.setFieldValue(‘urlfragment’, datain.urlfragment);
else {
record.setFieldValue(‘urlfragment’, /g, ‘-‘));
record.setFieldValue(‘primaryparent’, datain.primaryparent);
record.setFieldValue(‘externalid’, datain.externalid);
record.setFieldValue(‘pagetitle’, datain.pagetitle);
if (datain.metakeywords) record.setFieldValue(‘metakeywords’, datain.metakeywords);
if (datain.metadescription) record.setFieldValue(‘metadescription’, datain.metadescription);

try {
var id = nlapiSubmitRecord(record);
return id;
catch (ex) {
return ex.message ;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s