NetSuite REST Web Services/ RESTlets with OAuth 2.0 using Postman

SuiteCloud (SuiteTalk REST Web Services) is now usually available for all NetSuite products, extending a robust set of complementary SuiteTalk SOAP web services that have been part of NetSuite’s core integration solution for several releases. Including REST web services in SuiteTalk provides administrators and developers with even more options for integrating NetSuite with environments, external applications, and data sources. 

REST web services support API discoverability, offer link-based navigation, provide users with seamless access to NetSuite record metadata, and give users a uniform approach to interacting with both custom and standard records. 

No server-side coding or management of custom codes is necessary, as is the case with server-side RESTlets used to extend SuiteScript APIs when building REST-based integrations. 

This blog shows building REST-based integrations with OAuth 2.0 in your NetSuite Account, Postman Environment Setup, and POST Request. 

Learn more about our NetSuite Services

REST Web Services Prerequisites and Setup 

To use the REST web services, the relevant features must be enabled in your NetSuite account: 

  • Go to Setup > Company > click Enable features.  
  • Select SuiteCloud subtab. 
  • Check the REST Web Services feature in the SuiteTalk (Web Services) section. 

image001

  • Check the OAuth 2.0 checkbox in the Manage Authentication section. 

image003

  • Check the SuiteAnalytics Workbook in (Analytics) subtab.  

image005

  • Click Save. 

Assign the required permissions to the User Role: 

  • Go to Setup > Users/Roles > Manage Roles.  
  • Locate the role you want to modify. Click Edit or Customize link.  
  • On the Permissions subtab, click Setup 
  • In the Permission list, select REST Web Services from the dropdown list. 
  • In the Level list, select Full. Click Add 
  • In the Permission list under setup, select Log in using Access Tokens from the dropdown list. 
  • In the Level list, select Full. Click Add 
  • Click Save. 

image007

Create Integration Records for Applications using OAuth 2.0 

The following steps describe how to create an integration record:.  

  • Go to Setup > Integration > Integration Management > Manage Integrations > Click New. 
  • Enter a name for your application in the requiredName field. 
  • Enter a description in the Description field, if desired. 
  • Select Enabled in the State field. 
  • Enter a note in the Note field, if desired. 
  • On the Authentication tab, check the appropriate boxes for your application. 
  • Check the Rest Web Services & RESTlets box. 
  • Enter the valid redirect URI for your application, on which the authorization code will be handled. 
  • For the demo, I will be using https://google.com/. 
  • Under OAuth 2.0, check Authorization Code Grant for OAuth 2.0 to work. 
  • Click Save. 

image009

Once you click on the Save button, the Client Credentials values are displayed on the page. 

Note: For security reasons, this only appears once; make sure you note them. 

image011

NetSuite provides an account-specific domain containing the NetSuite account ID as part of the domain name to access REST web services or RESTlets. You can find the company URLs at Setup > Company > Company Information under the Company URLs subtab.

image013

Setting Up Postman Environment 

A Postman environment is a set of variables you can use in Postman requests. Using a Postman environment, you can switch between various NetSuite accounts and between your test or production accounts. Using Postman environments, you can customize requests using variables so you can switch between different setups without changing your requests. 

  1. Click the icon in the top menu of the Postman application. 

image015

    2. A popup window opens. Click Add on Manage Environments window. 

image017

3. Enter a self-descriptive name for your environment 

4. Enter your account ID (for example, 3604360) 

5. Enter the credentials you created,Tthe value of the consumer key/ client id and consumer secret/ client secret. 

6. Add all the variables and values as above. 

7. Click Add. 

Creating Postman Collections 

You can create a new collection by clicking the+ New buttonin the left sidebar, the New button > hit theCollection option displayed on it. A new window will pop up. 

image019

  • Give your new collection a Name. 
  • Select Type OAuth 2.0 under the Authorization section. 
  • The following detail will be automatically added;, if not, follow the below steps: 
  • Under Configure new token 

image021

  • Enter Self- descriptive Token Name. 
  • Enter Auth URL 
  •  {{proto}}://{{account}}.app.{{nsdomain}}/app/login/oauth2/authorize.nl 
  • Enter Access Token URL 
  • {{proto}}://{{account}}.{{suitetalkapi}}.{{nsdomain}}/{{restservice}}/auth/oauth2/{{version}}/token 
  • Enter Scope (For REST Web Services enter rest_webservices & for RESTlets enter restlets).  
  • Click GET New Access Token. 

image023

  • Login to your NetSuite account and click on the Continue button. 
  • On popup manage access tokens window. 

image025

  • Click the Use Token button.  
  • Tokens will be automatically added under the current token. 
  • Click Create. 

RESTlet POST Request 

  • After creating a new collection, click on Add requests to create your first request 

{{proto}}://{{account}}. {{restletsapi}}.{{nsdomain}}/app/site/hosting/restlet.nl?script=<>&deploy=<> 

image027

  • Add the RESTlet URL and enter the test body. 
  • Click Send. 
  • The success response will return 200 OK. 

image029

We have the correct status, created a recordand also found record Id in response. This means we could get into NetSuite and access our account information through third-party applications. Hence, we were authorized using OAuth 2.0. 

Summary & mandatory steps to follow are: 

  • REST Web Services Prerequisites and Setup 
  • Assign the required permissions to a user’s role 
  • Create Integration Record, obtain Client Id and Client Secret 
  • Get REST URL from Company Information 
  • Postman Environment and Collection Setup 
  • Add request and test Integration 

Leave a Reply

Your email address will not be published.