REST API and RESTlet

In NetSuite, both REST API and RESTlet are used to interact with external systems and perform operations like creating, reading, updating, and deleting data. But they have some differences:

REST API in NetSuite: (Representational State Transfer)

  • Standard API: It’s a built-in system that follows a standard format (REST) for working with NetSuite data.
  • Easy to use: Designed to be developer-friendly and integrates well with external systems.
  • Pre-made features: It has ready-made paths (endpoints) for things like customers, invoices, and items.
  • Authentication: It uses OAuth 2.0 for secure login, making it standardized and safe.

So, REST API is a ready-to-use, easy, and secure way to access NetSuite data without writing a lot of code.

Example:

To get information about a customer via REST API, you would make a request like:

GET /record/v1/customer/{customerId}

RESTlet in NetSuite:

  • Custom API: RESTlets are custom scripts you write using NetSuite’s SuiteScript (a JavaScript-based language).
  • Customization: You can design the logic to fit your exact needs, making it very flexible.
  • Flexibility: You can create your own API endpoints to expose only the data and functions you want.
  • Authentication: Like the REST API, RESTlets also need secure authentication, but since they’re custom, they might require more setup.

In short, RESTlets let you build your own custom API to meet specific business requirements.

Example:

To create a simple RESTlet to return a customer’s information, your RESTlet script might look like this:

/**

 * @NApiVersion 2.x

 * @NScriptType Restlet

 */

define([‘N/record’, ‘N/log’], function(record, log) {

 function getCustomerData(request) {

  var customerId = request.customerId;

  var customer = record.load({

   type: record.Type.CUSTOMER,

   id: customerId

  });

  return {

   id: customer.id,

   name: customer.getValue({ fieldId: ‘entityid’ }),

   email: customer.getValue({ fieldId: ’email’ })

  };

 }

 return {

  get: getCustomerData

 };

});

Leave a comment

Your email address will not be published. Required fields are marked *