RESTlet – Add Item to Commerce Category

Here is the RESTlet code to add a product to an existing Commerce Category.


This is called via a post request.

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

Here is the code in a form more easily copied.

addProductToCategory: function(datain) {
if (!datain.sku) return “Missing sku”;
if (!datain.vendor_id) return “Missing vendor_id”;
if (!datain.categories) return “Missing categories”;

var item_ids = logic_restlet_sca.GetItemIds(datain.sku, datain.vendor_id);

for (var i = 0; i < datain.categories.length; i++) {
// load a verify that the category exists
var categoryRec = nlapiLoadRecord(‘commercecategory’, datain.categories[i]);
if (!categoryRec) continue;

for (var j=0; j < item_ids.length; j++) {
categoryRec.setCurrentLineItemValue(‘items’, ‘item’, item_ids[0].internalid)

var id = nlapiSubmitRecord(categoryRec);
return “Success”;
catch (err) {
return err.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