Skip to content

Instantly share code, notes, and snippets.

@jkentjnr
Created August 3, 2018 02:15
Show Gist options
  • Select an option

  • Save jkentjnr/5a921eeae6c90efa5ee72f58bb1c3aee to your computer and use it in GitHub Desktop.

Select an option

Save jkentjnr/5a921eeae6c90efa5ee72f58bb1c3aee to your computer and use it in GitHub Desktop.
Netsuite Restlet 2.0 Hello World
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);
/**
*@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
};
}
);
@jkentjnr
Copy link
Copy Markdown
Author

jkentjnr commented Aug 3, 2018

Install Node
Run npm install request
Run node nlauth.js

@RohanHart
Copy link
Copy Markdown

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):

  1. "NLAuth lauth_account=..." should be "NLAuth nlauth_account=...
  2. "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