The NetSuite https.post() method is throwing an error that reads "Encountered unexpected character while parsing value: S. Path '', line 0, position 0"

I'm currently facing an issue when trying to send the JSON data request below to a 3rd party system using the "N/https" modules https.post() method.

Upon sending the request, I receive a Response Code of "200" along with the Error Message "Unexpected character encountered while parsing value: S. Path '', line 0, position 0"

Here is my code snippet:

var requestData = {
    "terminal": "345678",
    "user": "TestUser1234",
    "password": "XXXXXX",
    "Currency": "USD",
    "Total": "25",
    "GoodURL": "https://gatewayxx.test.com/sandbox/landingpage",
    "Language": "EN"
};

log.debug('Typeof - RequestData: ', typeof requestData);

var headerObj = {};
headerObj['Content-Type'] = 'application/json';
headerObj['Accept'] = 'application/json';

var response = https.post({
    url: "https://gatewayxx.test.com",
    body: requestData
});

HTTPS POST Responses Message:

{
    "type": "http.ClientResponse",
    "code": 200,
    "headers": {
        "Cache-Control": "private",
        "Server": "Microsoft-IIS/7.5",
        "Content-Length": "152",
        "Date": "Fri, 02 Oct 2020 05:44:47 GMT",
        "Content-Type": "text/html; charset=utf-8",
        "Via": "1.1 mono002"
    },
    "body": "{\"URL\":\"\",\"ConfirmationKey\":\"\",\"Error\":{\"ErrCode\":599,\"ErrMsg\":\"Unexpected character encountered while parsing value: S. Path '', line 0, position 0.\"}}"
}

After validating my request data in a JSON validator and confirming its type as "object", I am puzzled by the mismatched content-type in the response message which indicated "text/html" rather than JSON data.

If anyone could provide insight into this issue, it would be greatly appreciated.

Thank you for your assistance.

Answer №1

When setting JSON data as the Content-Type in the headers, ensure that you stringify the JavaScript Object being passed in the body:

var response = https.post({
    url: "https://gatewayxx.test.com",
    body: JSON.stringify(requestData)
});

In addition, as mentioned by bluehank, remember to include the headers with the request like this:

var response = https.post({
    url: "https://gatewayxx.test.com",
    body: JSON.stringify(requestData),
    headers: headerObj
});

Answer №2

It appears that you have created a header for your request, but then failed to use it in the actual post request. Can you explain why this is?

Although you received a 200 response code indicating that the POST request was successful, there seems to be an issue with what you are trying to retrieve. You are encountering a 599 error code, typically associated with timeouts on proxies. This suggests that the problem may not be on your end, but rather with the API you are utilizing.

Answer №3

After close examination, I have discovered a discrepancy in the NetSuite documentation concerning the header object.

When using https.request() or await https.request.promise(), it is important to note that the headers object should be formatted as follows: const headerObj = { 'Content-Type': 'application/json', 'Accept': 'application/json' };

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to replace CSS classes created using makeStyles

To clarify, my development environment is using MUI version 4.12.3. Inside file A, I have a simplified code snippet for a functional component, along with the usage of makeStyles to style a JSX element within the return statement (not displayed here). Ever ...

Dealing with nested dictionary values in columns using Python Pandas

My dataset includes a column called "data" that contains JSON objects as values, and I am looking to separate them. source = {'_id':['SE-DATA-BB3A','SE-DATA-BB3E','SE-DATA-BB3F'], 'pi':['BB3A_CAP_BMLS ...

What is the process for reopening messages.json in Sublime Text (3)?

After reading the documentation on packagecontrol.io found at this link, I have a question regarding the file tab displayed in Sublime Text when installing new packages. This tab shows continuous installation notes for multiple package installations, whi ...

The CSS styling is not being rendered correctly on the AngularJS HTML page

Encountering a puzzling situation here. Our angular controller is successfully delivering data to the page, but we are facing an issue with rendering a table due to an unknown number of columns: <table border="1" ng-repeat="table in xc.tables"> ...

Sending blank AJAX data to a PHP function

I am facing a challenge where I need to utilize AJAX to send the ID of an element and a specific value (1,2,3) to a PHP document for validation. Despite successfully logging both values in the console, the PHP file always returns that the data is empty. ...

Removing a similar object from an array using JavaScript

Working on a d3 force graph, I aimed for smooth updates using the method shown in the Modifying a Force Layout example. However, my goal was to achieve dynamic updating behavior unlike the static example provided. After calling initializeGraphData(json); i ...

How can I trigger a JavaScript function when the ENTER key is pressed?

I'm attempting to use JavaScript to scroll down a page. The code below works perfectly when I use javascript:pageScroll() in a link or button: <SCRIPT LANGUAGE="Javascript"> function pageScroll() { window.scrollBy(0,50); // hor ...

Trouble parsing JSON in Classic ASP

After receiving a JSON Response from a remote server, everything looks good. I discovered an helpful script for parsing the JSON data and extracting the necessary values. When attempting to pass the variable into JSON.parse(), I encountered an error which ...

Extracting information from a checkbox list displayed within an HTML table

I have a table with multiple rows and two columns in each row. The first column contains text, and the second column consists of checkboxes. While I was able to retrieve the values from the first column, I am struggling to fetch the values of the selected ...

My script is not updating the data when executed (NodeJs Lambda Alexa Skill)

I have a Lambda project set up with NodeJs. The script I've created fetches values from an external website in the form of JSON data. The issue arises when I make changes to the data and rerun the script, as the updated values are not reflected until ...

The Next.js website displays a favicon in Chrome, but it does not appear in Brave browser

As I work on my debut next.js website, I am configuring the favicon in index.js like this: <Head> <title>Create Next App</title> <link rel="icon" href="/favicon.ico" /> </Head> Initially, all my source ...

What is the process for incorporating a resource into a bundle with the fhirclient library (Smart on FHIR)?

Recently, I've been utilizing the fhirclient (Smart on FHIR) python library to work with bundles and individual resources. However, I'm facing a challenge in figuring out how to add a resource to a bundle using helper methods within the "Bundle" ...

Convert JSON Array to List via Deserialization

I attempted the suggested solution, but I am still encountering issues when trying to print the list. Below is the JSON data: var result = [ { "id": 1409636 }, { "id": 1499272 }, { "id": 1409587 }, { ...

Pagination with React Material UI is a user-friendly and visually

Requirement Within the Material UI framework, I need to implement pagination functionality by clicking on the page numbers (e.g., 1, 2) to make an API call with a limit of 10 and an offset incrementing from 10 after the initial call. https://i.stack.imgur. ...

Holding onto numerous AJAX requests while disconnected, then dispatching them once the network connection is

I'm working on an application that heavily relies on AJAX requests, requiring the rapid or concurrent sending of multiple calls. The code snippet provided serves as a basic wrapper for sending AJAX POST requests within the app. However, I've enco ...

Performing an XMLHttpRequest to Submit an HTML Form

Our Current HTML Form Setup This is an example of the HTML form we are currently using. <form id="demo-form" action="post-handler.php" method="POST"> <input type="text" name="name" value=" ...

Enhance the efficiency of time tracking function

I have been using a nodejs module to track the execution time of different parts of my application. // polyfill for window.performance.now var performance = global.performance || {} var performanceNow = performance.now || performance.mozNow ...

Incorporating CASL with the latest version of Angular, version

I'm currently working on implementing CASL into my Angular application, but I'm having trouble understanding how to integrate it. // Login Component ngOnInit() { var jsonBody = {}; jsonBody['email'] = 'peter@klaven'; ...

Setting the button value to a textbox and refreshing the status information (Codeigniter)

How do I pass the value of my "ACTIVE" status attribute to my textbox? I want to update the user's status by clicking the ACTIVE button. The user's status is currently pending. While I can easily pass the userID, I'm facing an issu ...

jquery mobile popup message will fade away within a short time interval

In my main page, I have the following code: $(document).bind("pageinit", function () { $.mobile.loading('hide'); }); I am displaying a popup message using the following code: $.mobile.loading('show&apos ...