As someone who has never done HTTPS outbound reque...
# suitescript
s
As someone who has never done HTTPS outbound requests from NetSuite. Anyone have any suggestions? I want to do something super simple where I make a POST call to Postman - ECHO and log the response. Any suggestions?
b
https module is not that bad
Copy code
var response = <http://https.post|https.post>({
      url: "<https://httpbin.org/post>",
      body: {key:'value'}
});
log.debug("body", response.body);
j
yup, I've made plenty of requests with the https module, works good
s
Trying to do the below item, but maybe I’m screwing up something in the script debugger. Don’t get any sort of response back.
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 *@NModuleScope Public
 */
require(['N/https','N/log'], function (https,log){

function doPost(){

var response = <http://https.post|https.post>({
url : "<https://postman-echo.com/post>", 
body : {foo : 'bar'}
});

log.debug("body", response.body);

}

});
b
nothing calls doPost
e
^ yeah
No need to even make the
doPost()
function, just start with the
<http://https.post|https.post>()
call
log.debug()
won't go anywhere without a script deployment
s
console.log then?
e
yep
b
he said hes using the script debugger
e
oh sorry missed that
b
Copy code
require(["N/https", "N/log"], function(https, log) {
  var response = <http://https.post|https.post>({
    url: "<https://postman-echo.com/post>",
    body: { foo: "bar" }
  });

  log.debug("body", response.body);
});
s
Thanks guys. I think I’m getting something back.
Copy code
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "foo": "bar"
  },
  "headers": {
    "x-forwarded-proto": "https",
    "host": "<http://postman-echo.com|postman-echo.com>",
    "content-length": "7",
    "accept": "text/*",
    "accept-encoding": "gzip, deflate",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "user-agent": "NetSuite/2018.2 (SuiteScript)",
    "x-forwarded-port": "443"
  },
  "json": {
    "foo": "bar"
  },
  "url": "<https://postman-echo.com/post>"
}
e
nice! Good job, @shubs
s
much love to @erictgrubaugh and @battk
Next step in the learning is going to be authentication, so I might have to come back to the well for some guidance. 😄