Hello, can anyone help me figure out why this code...
# suitescript
b
Hello, can anyone help me figure out why this code is getting a 415 response code? The same JSON works when I send it through postman, but seems like the post call is sending the data as plain text. Server is my own ASP.NET core server. Any help is appreciated.
Copy code
let update = new StatusUpdate(
      employeeName,
      location,
      jobTitle,
      status,
       // Omiited for brevity
    );

    log.debug("UPDATE: ", update);

    let headerObj = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    };

    let resp = <http://http.post|http.post>({
      url: "<http://myserverurl>", // ommitted
      header: headerObj,
      body: update
    });
    
    log.debug("Sent update to studio api. Response code: ", resp.code);
e
try body: JSON.stringify(update)
b
Still doesn't work unfortunately
I've tried that as well as JSON.parse(JSON.stringify(update) just in case
Going to analyze the network with wireshark
Thank you for the help!
b
depends on what you StatusUpdate object is
b
Copy code
class StatusUpdate {
  constructor(
    employeeName,
    location,
    jobTitle,
    status,
     // Ommitted for brevity)
}
b
you might want to log the value of JSON.stringify(update)
b
here is what logging both update and JSON.stringify(update) outputs
Copy code
{
  "employeeName": "Billy Cole",
  "location": "California",
  "jobTitle": "Software Engineer",
  "status": "Printed",
  "printer": "",
  "numberPrinted": 1,
  "numberSublimated": 0,
  "numberCut": 0,
  "numberSewn": 0,
  "numberFinished": 0,
  "numberReprints": 0,
  "sku": "Display-pm1",
  "timeElapsed": 0,
  "breakTimeElasped": 0,
  "rollId": 0,
  "rollSku": "N/A",
  "sqftPrinted": 0,
  "sqftSublimated": 0,
  "sqftCut": 0,
  "sqftSewn": 0,
  "sqftFolded": 0,
  "sqftReprinted": 0,
  "sewnRequired": 1,
  "orderNumber": "SO-523414",
  "sewingTime": 0,
  "material": "",
  "shipDate": "01/01/2020"
}
both are valid JSON
b
that does look like valid json
b
the same json works in postman
b
i personally prefer using something like http bin to echo what the request is
b
I will give it a try
thank you
b
Copy code
require(["N/http"], function (http) {
  var headerObj = {
    "Content-Type": "application/json",
    Accept: "application/json",
  };
  var update = {
    employeeName: "Billy Cole",
    location: "California",
    jobTitle: "Software Engineer",
    status: "Printed",
    printer: "",
    numberPrinted: 1,
    numberSublimated: 0,
    numberCut: 0,
    numberSewn: 0,
    numberFinished: 0,
    numberReprints: 0,
    sku: "Display-pm1",
    timeElapsed: 0,
    breakTimeElasped: 0,
    rollId: 0,
    rollSku: "N/A",
    sqftPrinted: 0,
    sqftSublimated: 0,
    sqftCut: 0,
    sqftSewn: 0,
    sqftFolded: 0,
    sqftReprinted: 0,
    sewnRequired: 1,
    orderNumber: "SO-523414",
    sewingTime: 0,
    material: "",
    shipDate: "01/01/2020",
  };
  var response = <http://http.post|http.post>({
    url: "<http://httpbin.org/post>",
    header: headerObj,
    body: JSON.stringify(update),
  });

  log.debug("response", response);
});
b
Fixed it
I had header: headerObj
it was supposed to be headers: headerObj
classic mistake. thank you for your help, i appreciate it!