Hello, I am trying to call a RESTlet from a User E...
# suitescript
g
Hello, I am trying to call a RESTlet from a User Event script, using https.requestRestlet and method GET but it seems that the RESTlet is not receiving the parameters. I am calling the Restlet as follows:
Copy code
function callRestlet(body, script, deploy){    
    var myRestletResponse = https.requestRestlet({
      body: 'My Restlet body',
      deploymentId: deploy,
      headers: myRestletHeaders,
      scriptId: script
    });

    var myRestletHeaders = {
      myHeaderType: 'Test',
      myHeaderStuff: 'This is my header',
      myHeaderId: 7
    };
  var myUrlParameters = {
      myFirstParameter: 'firstparam',
      mySecondParameter: 'secondparam'
    }
  var myRestletResponse = https.requestRestlet({
      body: 'My Restlet body',
      deploymentId: deploy,
      headers: myRestletHeaders,
      method: 'GET',
      scriptId: script,
      urlparams: myUrlParameters
  });
}
This is the doGet function on the Restlet:
Copy code
function doGet(context) {
    log.debug('doGet', '*** START ***');
    log.debug('doGet', 'context = ' + JSON.stringify(context));
    let response = '';

    try {
      return JSON.stringify(context);
    } catch (e) {
      return createErrorResponse({
        error: e.message,
        message: e
      });
    }
  }
And this how the logs look like: Any idea why I'm not getting anything in the context?
b
lots of things are weird in your code
dont send a body in a GET request, they arent supposed to have any
same thing for the custom headers, you dont have access to them
you do however want to specify the Content–Type Header
the content type controls what your restlet must return
g
You're right, I fixed my user event and even with those changes the context log is empty.
Copy code
function callRestlet(body, script, deploy){
  var myUrlParameters = {
      myFirstParameter: 'firstparam',
      mySecondParameter: 'secondparam'
    }
  var myRestletResponse = https.requestRestlet({
      deploymentId: deploy,
      method: 'GET',
      scriptId: script,
      urlparams: myUrlParameters
  });
  }
b
i suggested 3 changes
you have implemented 2
z
@battk you should be more polite when communicate with a lady 🙂 @battk [11:34 PM] lots of things are weird in your code Unfortunately for all of us, this is OFFICIAL NETSUITE SAMPLE CODE! NOT TESTED AND WRONG https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_159139340774.html as you can see, ORACLE provide sample for GET request with BODY, but still it is not reason for empty context?? @gabyrdzlobaton you are the victim of first copy-paste Murphy law. DON’T EVER COPY PASTE CODE! … There is an error in uppercase 🙂 … one lower ‘p’ wants to be upper ‘P’ urlparams => urlParams and everything will be ok
👍 1
❤️ 1
g
Thank you so much for your hel
Thank you so much for your help @Zoran R-DATAGRAM, It was too useful, I was about to go crazy because it didn't work 🤭 I did not know the error with the letter 'p' haha
👍 1
384 Views