Krunal Patel
Krunal Patel

Reputation: 55

Call Restlet from User Event Script Error INVALID_LOGIN_ATTEMPT

I am trying to access Restlet from User Event script but i am receiving error: body":"error code: INVALID_LOGIN_ATTEMPT\nerror message: Invalid login attempt. Do i need to pass credentials too? what should i pass client id, client secret? is there another way?

I also tried url.resolveScript but no luck.

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope Public
*/
define(["N/https", "N/log", "N/record", "N/url" ],

function(https, log, record, url) {


    function beforeLoad(context) {
        // log.debug('beforeLoad Triggered');
        // context.newRecord;
        // context.type;
        // context.form;
        return;
    }
    
    function afterSubmit(context) {
      log.debug('Before code');
      var record = context.newRecord;
  var requestBody = {
"recordId": record.id,
"recordType": record.type,
 };

   var output = url.resolveScript({
scriptId: '1157',
deploymentId: '1',
 });   
var output1 = 'https://12345-sb5.restlets.api.netsuite.com';
log.debug('After code', output );   
 var response = https.post({
url: output1 + output,
body: requestBody,
 });

 if (response.code === 200) {
// success!
 } else {
 // handle error
 }
      log.debug('After code', response );
        return;
    }
    
    function beforeSubmit(context) {
        // log.debug('beforeSubmit Triggered');
        // context.newRecord;
        // context.oldRecord;
        // context.type;
        return;
    }

    return {
            beforeLoad : beforeLoad,
            afterSubmit : afterSubmit,
            beforeSubmit : beforeSubmit
        }



    })

Upvotes: 0

Views: 941

Answers (2)

Steffen Andersland
Steffen Andersland

Reputation: 609

try https.requestRestlet

var response = https.requestRestlet({
    body: JSON.stringify({
        "recordId": record.id,
        "recordType": record.type,
    }),
    deploymentId: '1',
    method: 'POST',
    scriptId: 1157,
});

Upvotes: 1

Nukedd
Nukedd

Reputation: 28

Why do you need your UE Script to submit and trigger your RESTlet every record submit?

Below could work for ClientScript, just not sure if saveRecord (only when the Submit/Save is clicked) entry point will trigger this.

var requestBody = JSON.stringify({
      recordId: record.id,
      recordType: record.type
});

var output = url.resolveScript({
      scriptId: '1157',
      deploymentId: '1'
});

var response = https.post({

      url: output,
      body: requestBody

});

Previously you could manipulate the cookies and pass it. However, it's no longer the case and Server Scripts cannot call Server Scripts unless you pass Authentication which is a pain if you have no library. Oauth1 + SHA256 is complicated to figure out without libraries.

You could probably approach this on another angle depending on your use case. At this moment, it isn't clear why you want AfterSubmit to call RESTlet. If you do this, if you have routine Scheduled Scripts that touches that record and saves the record, it will keep triggering your AfterSubmit unless you place an if statement.

Upvotes: 0

Related Questions