Created
August 3, 2018 02:15
-
-
Save jkentjnr/5a921eeae6c90efa5ee72f58bb1c3aee to your computer and use it in GitHub Desktop.
Netsuite Restlet 2.0 Hello World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const request = require('request'); | |
| const headers = { | |
| "Authorization": "NLAuth lauth_account=4878491_SB1,nlauth_email=testuser@test.com,nlauth_signature=#####,nlauth_role=1006", | |
| "Content-Type": "application/json", | |
| "Accept": "application/json" | |
| }; | |
| function callback(error, response, body) { | |
| console.log(error, body); | |
| } | |
| request({ | |
| url: 'https://4878493-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=234&deploy=1', | |
| method: 'GET', | |
| headers: headers | |
| }, callback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| *@NApiVersion 2.x | |
| *@NScriptType Restlet | |
| */ | |
| define( | |
| [ | |
| 'N/search', | |
| 'N/record', | |
| 'N/cache', | |
| 'N/format' | |
| ], | |
| function (search, record, cache, fmt) { | |
| function get (context) { | |
| try { | |
| return { test: 'Hello World' }; | |
| } catch (err) { | |
| log.audit({ | |
| title: 'GET', | |
| details: JSON.stringify(err) | |
| }); | |
| return err; | |
| } | |
| } | |
| return { | |
| get: get, | |
| //delete: delete, | |
| //post: post, | |
| //put: put | |
| }; | |
| } | |
| ); |
Author
Author
For reference - these are the guides that have been followed:
• http://cdn2.hubspot.net/hubfs/4259277/Techfino_March2018/Images/Token-Based-Authentication-Guide-for-NetSuite.pdf?t=1524742685505
• https://www.tenfold.com/support-center/netsuite-restlet
• https://github.com/mark-keaton/oauth-netsuite
• http://blog.prolecto.com/2017/10/14/download-netsuite-oauth-token-based-authentication-sample-node-js-program/
• https://community.boomi.com/docs/DOC-2675 | https://community.boomi.com/docs/DOC-2676
Using NLAuth this works fine in our test account. The only difference I can see is that this uses the old-style https://rest.netsuite.com endpoint.
Note that nlauth.js above has two errors (not that these result in UNEXPECTED_ERROR):
- "NLAuth lauth_account=..." should be "NLAuth nlauth_account=...
- "request({ url: 'https://4878493-sb1.restlets.api.netsuite.com, ..." doesn't match the authorised account 4878491_SB1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install Node
Run
npm install requestRun
node nlauth.js