Hi All,
I've read a few submissions on this, but none of the solutions provided seem to be working.
I'm making my API call, and getting a response, and in my console, I take the response and use JSON.parse(response.getBody()) to return a nice neat object.
Unfortunately when I load this into a scheduled script, I keep getting the "SyntaxError: Unexpected token: " at the JSON.parse line.
I've tried using JSON.parse(JSON.stringify(response.getBody())), and this actually allows the script to run, but the return value isn't an object anymore. Still just a long messy string.
Any ideas?
var response = nlapiRequestURL(URL+truckLoadId, null, headers); if(response.body.substr(0,10) != "Could not "){ var responseBody = response.body; nlapiLogExecution('debug','Details',response.body); var dataObj = JSON.parse(JSON.stringify(response.getBody())); nlapiLogExecution('debug','Details','dataObj = '+dataObj); var deliveryStatus = dataObj.DeliveryStatusDescription; if(dataObj.LasPositionEvent != null){ var lastPosition = dataObj.LastPositionEvent.City + " " + dataObj.LastPositionEvent.state; nlapiLogExecution('debug','Details','dataObj.LastPositionEvent.City = '+dataObj.LastPositionEvent.City); var latitude = dataObj.LastPositionEvent.Latitude; nlapiLogExecution('debug','Details','dataPbj;LastPositionEvent = '+ dataObj.LastPositionEvent); var longitude = dataObj.LastPositionEvent.Longitude; } //var ETA = dataObj.Stops[1].EstimatedDeliveryDate; //var date = ETA.substr(0,10); //var day = date.substr(); var tenFourLicense = dataObj.TenFourLicensePlate; nlapiLogExecution('debug','Details','tenFourLicense = '+ tenFourLicense)Note: When I use the stringify I can tell that its spitting out an object and not a string in the execution log, as well as that tenFourLicense just keeps coming back undefined because it can't recognize an object.