NetSuite Restlet 2.0 Tutorial

To enable integration (e.g. with Shopify and Amazon), you'll need to expose a RESTful endpoint and create a script to handle POSTs to that endpoint:

1)  Enable Features


Login to NetSuite as an administrator

Go to Setup > Company > Enable Features and click on the SuiteCloud subtab, then enable these features:

  • Client SuiteScript
  • Server SuiteScript
  • Token-Based Authentication


Then click Save

2)  Set Up Role


Go to Setup > Users/Roles > Manage Roles > New and enter the following information:

  • Name:  Token Based Authentication
  • ID:  _token_based_auth
  • Center Type:  System Administrator Center
  • Accessible Subsidiaries (for OneWorld accounts):  ALL

In the Permissions > Setup subtab, add the following permissions (at Full level):

  • Access Token Management
  • Log in using Access Tokens
  • User Access Tokens

Then click Save

3)  Create Employee Record


Go to Lists > Employees > Employees > New and enter the following information:

  • Name: Restlet User
  • Email: create a new email address/alias using your company email system and enter it here
  • Subsidiary (for OneWorld accounts): your company subsidiary

In the Access subtab, do the following:

  • check Give Access
  • check Manually Assign or Change Password and set a complex password
  • select Token Based Authentication for the role and click Add


Then click Save

4)  Create Integration Record


Go to Setup > Integration > Manage Integrations > New and enter the following information:

  • Name:  Restlet Integration

In the Authentication subtab, uncheck User Credentials and check Token-Based Authentication:
Then click Save

IMPORTANT: copy the Consumer Key and Consumer Secret values to a safe location:

5)  Create Employee Token


Logout of NetSuite

Login with employee credentials from Step #3

Go to Setup > Users/Roles > Access Tokens > New and enter the following information:

  • Application Name: Restlet Integration
  • User: Restlet User
  • Role: Token Based Authentication
  • Token Name (rename to): Restlet Integration Token

Then click Save

IMPORTANT: copy the Token ID and Token Secret values to a safe location:

Logout of NetSuite

6)  Download Code Template


Download RestletExample.js from http://ideone.com/jF5LeI

7)  Upload Code Template


Login to NetSuite as an administrator

Go to Customization > Scripting > Scripts > New

Hover your mouse to the right of the textbox and a plus (+) sign with appear.  Click on it.

Select SuiteScripts for Folder and select the file from Step #6, then click Save

Click Create Script Record

Enter the following information:

  • Name: Restlet Example
  • ID: _restlet_example

Then click Save

Click Deploy Script

Enter the following information:

  • Title: Restlet Example Deployment
  • ID: _restlet_example_deployment
  • Status: Released
  • Log Level: Debug
  • Roles: Token Based Authentication
  • Subsidiaries (for OneWorld accounts): select your subsidiary
  • Employees: Restlet User

Then click Save

IMPORTANT: copy the External URL value to a safe location:

8)  Get Account ID


Go to Setup > Company > Company Information

IMPORTANT: copy the Account ID value to a safe location:


9)  Run Test


Install/Open a RESTful tool like https://insomnia.rest/ or https://www.getpostman.com/
(…Insomnia is used in this tutorial)

Enter the following OAuth 1.0 information:

  • Consumer Key: see Step #4
  • Consumer Key: see Step #4
  • Token: see Step #5
  • Token Secret: see Step #5
  • Signature Method: HMAC-SHA256
  • Version: 1.0
  • Realm: see Step #8

Set type to POST and URL from Step #7.  Set payload to {"example":"my data"} then click Send.  You should get at 200 OK response:


10)  Verify Test


In NetSuite, go to Customization > Scripting > Scripts

Set Type to RESTlet and click View for Restlet Example


In the Execution Log subtab you should see the JSON payload from Step #9


11)  Edit Script


In another browser tab, go to Customization > Scripting > Scripts and click View for Restlet Example

In the Scripts subtab, click Edit

Change Hello, World to Hello, World Again and then click Save


Re-run Step #9

In your other browser tab, click “Refresh” and confirm the new change:






References:


Comments

Popular Posts