Netsuite Restlet Script
Hi there,
This post will cover everything about Netsuite's Restlet script. Restlet Script is used to get data from Other System to Netsuite and also send data from Netsuite to external application securely. Restlet can perform any function what other suite script can.
Restlet can retrieve, add, or manipulate data within NetSuite, from an external source. In this sense, RESTlets can be seen as an alternative to NetSuite’s SOAP-based web services.
Restlet can customize the behavior of pages and features within NetSuite. In this sense, RESTlets can be seen an alternative to other script types, such as server-side Suitelets.
There are multiple advantage of restlet over suitelet.
Pros:
1. Restlets are more secure than suitelet in data transfer
2. Restlets have more type of methods and functionality compare to suitelet.
3. Can be used as an alternative to SOAP Based web services.
4. Login details are required to make a call.
Cons:
Restlets can not be used to show data as a form.
Restlets have 4 methods:
1. PUT
2. POST
3. GET
4. DELETE
How to create a Restlet?
Step 1: Create javascript file for restlet ex: use javascript code at end of page
Step 2: Upload it to Script page , go to Customization>Scripting > Scripts>New
Step 3: Click on "Create Script Record" button,
Step 4: On Script screen , enter name, id and description if you want .
Step 5: Save and Deploy
Enter Title and Id, select status and save.
Step 6. URL and External URL will populate on save of record.
URL can be used by internal scripts and external url can be used by external applications.
While making call to netsuit user have to define NLAUTH as Authorization header.
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/record', 'N/error'],
function(record, error) {
// Get a standard NetSuite record
function mget(context) {
return JSON.stringify(record.load({
type: context.recordtype,
id: context.id
}));
}
// Delete a standard NetSuite record
function mdelete(context) {
record.delete({
type: context.recordtype,
id: context.id
});
return String(context.id);
}
// Create a NetSuite record from request params
function mpost(context) {
var rec = record.create({
type: context.recordtype
});
rec.setValue(fldName, fieldValue);
var recordId = rec.save();
return String(recordId);
}
// Upsert a NetSuite record from request param
function mput(context) {
var rec = record.load({
type: context.recordtype,
id: context.id
});
rec.setValue(fldName,fieldValue);
rec.save();
return JSON.stringify(rec);
}
return {
get: mget,
delete: mdelete,
post: mpost,
put: mput
};
});
How to call suitelet?
If you use GET method , it should use params like below:
How to know which Content-Type you need?
****Please also read , how to make restlet call from android here
Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page
This post will cover everything about Netsuite's Restlet script. Restlet Script is used to get data from Other System to Netsuite and also send data from Netsuite to external application securely. Restlet can perform any function what other suite script can.
Restlet can retrieve, add, or manipulate data within NetSuite, from an external source. In this sense, RESTlets can be seen as an alternative to NetSuite’s SOAP-based web services.
Restlet can customize the behavior of pages and features within NetSuite. In this sense, RESTlets can be seen an alternative to other script types, such as server-side Suitelets.
There are multiple advantage of restlet over suitelet.
Pros:
1. Restlets are more secure than suitelet in data transfer
2. Restlets have more type of methods and functionality compare to suitelet.
3. Can be used as an alternative to SOAP Based web services.
4. Login details are required to make a call.
Cons:
Restlets can not be used to show data as a form.
Restlets have 4 methods:
1. PUT
2. POST
3. GET
4. DELETE
How to create a Restlet?
Step 1: Create javascript file for restlet ex: use javascript code at end of page
Step 2: Upload it to Script page , go to Customization>Scripting > Scripts>New
Upload File |
Step 3: Click on "Create Script Record" button,
Step 4: On Script screen , enter name, id and description if you want .
Step 5: Save and Deploy
Enter Title and Id, select status and save.
Script Deployment page |
Step 6. URL and External URL will populate on save of record.
URL and External URL on Deployment |
While making call to netsuit user have to define NLAUTH as Authorization header.
NLAuth nlauth_account="1212",
nlauth_email="myemail@gmail.com", nlauth_signature="mypass",
nlauth_role="-4"
How to create Netsuite's Restlet in 2.0:/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/record', 'N/error'],
function(record, error) {
// Get a standard NetSuite record
function mget(context) {
return JSON.stringify(record.load({
type: context.recordtype,
id: context.id
}));
}
// Delete a standard NetSuite record
function mdelete(context) {
record.delete({
type: context.recordtype,
id: context.id
});
return String(context.id);
}
// Create a NetSuite record from request params
function mpost(context) {
var rec = record.create({
type: context.recordtype
});
rec.setValue(fldName, fieldValue);
var recordId = rec.save();
return String(recordId);
}
// Upsert a NetSuite record from request param
function mput(context) {
var rec = record.load({
type: context.recordtype,
id: context.id
});
rec.setValue(fldName,fieldValue);
rec.save();
return JSON.stringify(rec);
}
return {
get: mget,
delete: mdelete,
post: mpost,
put: mput
};
});
How to call suitelet?
If you use GET method , it should use params like below:
GET YRLofRestlet&recordtype=salesorder&id=1122 HTTP/1.1
HOST: URL
authorization: NLAuth nlauth_account=12345,
nlauth_email=netsuiteguru@netsuiteguru.com, nlauth_signature=URPassword
content-type: application/json
How to know which Content-Type you need?
application/json :: JSON is the appropriate choice for most RESTlets that require a request body,
because it lets you map values to fields.
application/xml :: XML is supported only for the get method.
text/plain :: Because plain text does not let you map values to fields, this choice
should be used only
for RESTlets that require limited and simple input.
****Please also read , how to make restlet call from android here
Thanks
Netsuite Guru
Netsuite Guru
Follow Me on Linkedin
Our FB Page
Hi,
ReplyDeleteCan a RESTlet url is customized or the system will generate its own ?
Hi Ashok,
DeleteSystem will generate its own somewhat similar to this
https://XXYYXX.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1000&deploy=2
where XXYYXX is account is , script is is of script and deploy is deployment id