0

I need to call an external API to get some data from a SuiteScript file and I'm getting an issue. The GET call needs to go with credentials (basically, it has to go with the cookies in the Request Header).

If I make the API call from the chrome console setting withCredentials = true, but when I make that API call with NetSuite N/https module -through https.get()- the cookies don't go on the request header.

So in summary, I'm looking for a way to set withCredentials = true on the http.get() call or to be able to somehow get the cookies from my SuiteScript so that I can manually set it in the header option of the call.

Thanks in advance for your time!

nachoargentina
  • 730
  • 7
  • 13
  • Your question is isn't clear. Is your browser on a Netsuite page; a NS hosted website page or an externally hosted website page? Are you trying to pass a session from an external system to a Suitelet so that the suitelet may log in as you? If you have logged in to an external site and then go back to netsuite hoping to pass that site's cookies to Netsuite you cannot do that easily. It would be simple as a developer to use the Chrome inspector to get your session id and then manually paste that into a field on a Suitelet page but that's not a user level activity. – bknights Mar 05 '18 at 21:36
  • I apologize if it was not clear enough. Let me try to elaborate a bit more. I'm working on integrating NetSuite with an external app. For this, I have a Suitelet that performs some API calls to the external app to check some information about the logged user before returning the content to be rendered. I make all these calls through the use of N/https module by using https. get(). The problem I'm facing is that one of these calls requieres a cookie that is on my browser. Since the calls are being made from a Suitelet, I don't think there's a way to send that info, is there? – nachoargentina Mar 05 '18 at 21:51

2 Answers2

2

Within the get, pass the headers option and populate your header values. I believe these are KVP.

Adam Parker
  • 136
  • 1
  • 3
  • Unfortunately, I don't think that's going to help. See, I want to send my browser cookies in the HTTP call, but for what I can see, when I use https.get(), it's not my browser making the call, is NetSuite that is doing it internally. I'm not sure how can I get my local cookies to go on that call... – nachoargentina Mar 05 '18 at 21:16
0

If your external app is expecting information about the logged in user then what you probably want to do is an XHR request (jQuery's $.getJSON would be your best bet). If you need to pass information to a server side script then you'd call your Suitelet with the returned data.

A post example would be as follows. Note the withCredentials :

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: url,
            dataType: "json",
            data: jsonData,
            xhrFields: {
                withCredentials: true
            },
            success: function(response){
                console.log(response);
            },
            error: function(response){
                console.log('error: ' + JSON.stringify(response));
            }
        });
bknights
  • 14,408
  • 2
  • 18
  • 31