Search code examples
apirestnetsuitesuitescript

Netsuite Rest API Create Non-inventory Item for Sale


I try to create a Non-Inventory Sale item with the NetSuite API. Here is my request : Method : POST Endpoint: /services/rest/record/v1/nonInventorySaleItem Payload:

{
    "itemId": "Test Item",
    "IncomeAccount": {
        "id": "1315"
    },
    "deterredRevenueAccount": {
        "id": "1343"
    },
    "itemType": {
        "refName": "NonInvtPart"
    },
    "location": {
        "id": "46"
    },
    "taxSchedule": {"id": "1"}
}

It keeps returning 400 HTTP Error and the message :

Error while accessing a resource. Please enter value(s) for: Tax Schedule.

I tried to work around with a custom entity field and a UserEventScript SuiteScript to update taxSchedule before submit without success.


Solution

  • I spoke with NetSuite support staff and they basically said that the feature isn't supported. If you want you can create a RESTlet and recreate the functionality by accepting the parameters that you want and creating the item that way. Something roughly like this:

    define(['N/record'], function(record) {
        function post(context) {
            if (context.request.method !== 'POST') {
                throw {
                    status: 405,
                    message: 'Invalid HTTP method',
                };
            }
            
            // Parse the request body
            var requestBody = JSON.parse(context.request.body);
            
            // Create the inventory item record
            var itemRecord = record.create({
                type: record.Type.INVENTORY_ITEM,
                isDynamic: true,
            });
            
            // Set the item name, tax schedule, asset account, and cogs account
            itemRecord.setValue({
                fieldId: 'itemid',
                value: requestBody.name,
            });
            itemRecord.setValue({
                fieldId: 'taxschedule',
                value: requestBody.taxSchedule,
            });
            itemRecord.setValue({
                fieldId: 'assetaccount',
                value: requestBody.assetAccount,
            });
            itemRecord.setValue({
                fieldId: 'cogsaccount',
                value: requestBody.cogsAccount,
            });
            
            // Save the inventory item record
            var itemId = itemRecord.save({
                enableSourcing: true,
                ignoreMandatoryFields: true,
            });
            
            // Return the new inventory item ID
            return {
                id: itemId,
            };
        }
        
        return {
            post: post,
        };
    });

    Obviously also include any other fields that you want, but I found that the Tax Schedule, COGS account, and asset accounts were all required.