来自SuiteLet Client的NetSuite RestLet调用

时间:2017-07-17 11:41:40

标签: netsuite

我正在尝试从另一个SuiteScript调用RestLet webservice / URL。据我所知,我需要使用http / https模块这样做。但我无法找到一些例子或步骤来做到这一点。

计划在SS2.0-

中使用此代码
var response = http.post({
url: 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=601&deploy=1',
body: myDataObj, // json object
headers: headerObj // json obj
});

以下代码适用于我。

            var nameValue = "arin";
            var myDataObj = {
                "name" : nameValue
            };
            var myRequest = {};
            myRequest.headers = {};
            myRequest.headers["Authorization"] = 'NLAuth nlauth_account=TSTDRV158xxxx,nlauth_email=XXXX,nlauth_signature=XXXX,nlauth_role=3';
            myRequest.headers["Content-Type"] = 'application/json';
            myRequest.headers["Accept"] = '*/*';
            myRequest.url = 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=601&deploy=1'; // RESTlet
                                                                                                                // URL
            myRequest.method = "POST";
            myRequest.body = JSON.stringify(myDataObj);
            // myRequest.body = myDataObj;
            var myResponse = https.post(myRequest);

阅读JSON返回的响应数据......

        log.debug("Resonse", myResponse.body);
        log.debug("Resonse", myResponse.code);          
        var data = myResponse.body;             
        var retObj = JSON.parse(data);              
        log.debug("Resonse Ret city - ", retObj.city);

1 个答案:

答案 0 :(得分:2)

以下是如何操作的基本示例:

var myRequest = {};
myRequest.headers = {};
myRequest.headers["Authorization"] = 'NLAuth nlauth_account=TSTDRVXXXXX, nlauth_email=xxx@xxx.com, nlauth_signature=XXXXXXX, nlauth_role=3';
myRequest.headers["contentType"] = 'application/json';
myRequest.url = 'https://XXXXXXXXX'; //RESTlet URL
myRequest.body = myDataObj;
var myResponse = https.post(myRequest);

小心地在客户端脚本上公开它。您不想公开您的凭据。