Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The NetSuite Pro

The NetSuite Pro Logo The NetSuite Pro Logo

The NetSuite Pro Navigation

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Home/ Real-World NetSuite Examples/Real-Time Inventory Sync via RESTlet API

Real-Time Inventory Sync via RESTlet API

πŸ“¦ Business Use Case

Your eCommerce site or WMS (Warehouse Management System) tracks product inventory changes β€” but your NetSuite item records are out of sync. You need a way to push updated stock quantities to NetSuite in real time, automatically, and securely.


πŸš€ Solution: RESTlet for Inventory Updates

Instead of manual CSV imports or scheduled Map/Reduce jobs, use a RESTlet that:

  1. Accepts a JSON payload from your external system (e.g., WMS, Shopify, or middleware).
  2. Updates Inventory Detail or Quantity On Hand on Inventory Items, by location.
  3. Returns a clean API response with status and error handling.

🧠 RESTlet Design Pattern

  • Accepts: POST /app/site/hosting/restlet.nl?script=xxx&deploy=1
  • Payload:
{
  "external_id": "sku-abc123",
  "location_id": 3,
  "quantity_on_hand": 48
}
  • Response:
{
  "success": true,
  "item_id": 1278,
  "location_id": 3,
  "quantity_set": 48
}

🧩 SuiteScript 2.1: RESTlet to Sync Inventory

/**
 * @NApiVersion 2.1
 * @NScriptType Restlet
 * @author The NetSuite Pro
 * @description Updates inventory quantity for a given item and location
 */
define(['N/record', 'N/search', 'N/log'], (record, search, log) => {
  
  function post(request) {
    const { external_id, location_id, quantity_on_hand } = request;

    if (!external_id || !location_id || typeof quantity_on_hand !== 'number') {
      return { success: false, error: 'Missing required parameters' };
    }

    try {
      // Lookup inventory item by External ID (or use custom field if needed)
      const itemId = getItemIdByExternalId(external_id);
      if (!itemId) return { success: false, error: `Item not found for external_id: ${external_id}` };

      // Load the Inventory Item
      const rec = record.load({
        type: record.Type.INVENTORY_ITEM,
        id: itemId,
        isDynamic: true
      });

      // Go to 'Locations' sublist and find the line for the given location
      const lineCount = rec.getLineCount({ sublistId: 'locations' });
      let lineIndex = -1;
      for (let i = 0; i < lineCount; i++) {
        const loc = rec.getSublistValue({ sublistId: 'locations', fieldId: 'location', line: i });
        if (Number(loc) === Number(location_id)) {
          lineIndex = i;
          break;
        }
      }

      if (lineIndex === -1) return { success: false, error: 'Location not assigned to item' };

      rec.setSublistValue({
        sublistId: 'locations',
        fieldId: 'quantityonhand',
        line: lineIndex,
        value: quantity_on_hand
      });

      const id = rec.save({ enableSourcing: true, ignoreMandatoryFields: false });

      return { success: true, item_id: id, location_id, quantity_set: quantity_on_hand };

    } catch (e) {
      log.error('Inventory Sync Error', e.message);
      return { success: false, error: e.message };
    }
  }

  function getItemIdByExternalId(external_id) {
    const results = search.lookupFields({
      type: search.Type.ITEM,
      id: external_id,
      columns: ['internalid']
    });
    return results && results.internalid && results.internalid[0] && results.internalid[0].value;
  }

  return { post };
});

πŸ” Authentication & Security Tips

  • Use Token-Based Authentication (TBA) or OAuth 2.0.
  • Restrict to specific roles with permission to only update Inventory Items.
  • Implement API key validation if calling from an external server.
  • Log all calls using N/log for traceability.
  • Optional: create a custom record log of updates.

πŸ§ͺ Test Example

Use Postman or curl to simulate:

curl -X POST \
  https://ACCOUNT_ID.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1234&deploy=1 \
  -H "Authorization: NLAuth ..." \
  -H "Content-Type: application/json" \
  -d '{
        "external_id": "sku-abc123",
        "location_id": 3,
        "quantity_on_hand": 48
      }'

πŸ“Œ Best Practices

  • Don’t overwrite committed or on-order quantities β€” only use for real-time on-hand values.
  • If you use multiple locations, make sure the item record has that location enabled.
  • Use a middleware queue (like Boomi, Celigo, or AWS Lambda) for high-volume systems.
  • Add retry/backoff logic if you expect concurrency issues.
  • Use SuiteQL if you prefer pulling inventory values from NetSuite instead of pushing.
Share
  • Facebook

Leave a ReplyCancel reply

Sidebar

Ask A Question

Stats

  • Questions 6
  • Answers 6
  • Best Answers 0
  • Users 3
  • Popular
  • Answers
  • Rocky

    Issue in running a client script in NetSuite SuiteScript 2.0 ...

    • 1 Answer
  • admin

    How can I send an email with an attachment in ...

    • 1 Answer
  • admin

    How do I avoid SSS_USAGE_LIMIT_EXCEEDED in a Map/Reduce script?

    • 1 Answer
  • admin
    admin added an answer The issue is usually caused by following Wrong script file… September 14, 2025 at 10:33 pm
  • admin
    admin added an answer Steps to send an Invoice PDF by email: define(['N/email', 'N/render',… August 28, 2025 at 3:05 am
  • admin
    admin added an answer This error means your script hit NetSuite’s governance usage limit… August 28, 2025 at 3:02 am

Top Members

Rocky

Rocky

  • 1 Question
  • 22 Points
Begginer
Sophie1022

Sophie1022

  • 0 Questions
  • 20 Points
Begginer
admin

admin

  • 5 Questions
  • 2 Points

Trending Tags

clientscript netsuite scripting suitescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Menu

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us

Quick Links

  • NetSuite Scripting
  • NetSuite Customization
  • NetSuite Advanced PDF Template
  • NetSuite Integration
  • NetSuite Reporting & Analytics

Subscribe for NetSuite Insights....

© 2025 The NetSuite Pro. All Rights Reserved