Friday 4 January 2013

Calling a restlet from a suitelet


I guess you are trying to call a restlet from a suitelet and pass some json object to the restlet. Here we go

Suitelet part

//url of the restlet
var url = copy the url of the restlet here...

//creating a Json object
var jsonObj = new Object();
jsonObj.fruit1 = "apple";
jsonObj.fruit2 = "mango";
var myJson = JSON.stringify(jsonObj);

//credentials
var headers = new Array();
headers['Content-Type'] = 'application/json';
headers['Authorization'] = 'NLAuth nlauth_email=your netsuite email id, nlauth_signature=password, nlauth_account=account id, nlauth_role=role';

To know your account id, just click here. For role, just write there '3' (for adminstrator account) , for the time being.

//calling restlet
var restletResponse = nlapiRequestURL(url, myJson, headers, null, "POST");

//getting response
var responseText = restletResponse.getBody();

you can use this responseText to get the response from restlet.
Now as we are done with suitelet, how to read this data in the restlet. Here is the code.

Restlet
//getting data from datain
var fruit1=datain.fruit1;
var fruit2=datain.fruit2;

Hope this was helpful.
Any suggestion to improve the blog are most welcomed.

1 comment:

  1. can we call the restlet using normal html file? please replay me...

    ReplyDelete