cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Fetch API throwing error called "SyntaxError: Unexpected token '<', "

0 Likes
11,284

HI,

The same code is working fine in SAP WEB IDE. and I'm able to call it Fetch API with method Post Successfully.

Now I have deployed Fiori app from SAP WEB IDE to S4 Hana Cloud. Now Iam getting error for fetch API in console is

"SyntaxError: Unexpected token '<', "<html><hea"... is not valid JSON"

Network Tab Response in debugger mode is

<html><head><title>Error report</title></head><body><h1>HTTP Status 500 - An internal application error occurred.

Request: -------------------</h1></body></html>

Could you please let me know, same code working fine in SAP WEB IDE and but not working after deployed to S4 Hana cloud?

How to resolve this issue?

PFB ,

const perform3 = (x) => {

return fetch(api, {

method: 'post',

headers: {

"X-Requested-With": 'XMLHttpRequest',

"Content-Type": 'application/json',

"X-CSRF-Token": CSRFToken,

"Accept": 'application/json',

},

body: JSON.stringify(x)

})

.then((res) => res.json())

.then((data) => {

console.log("Success:", data);

MessageArray.push({

Data: data

})

.catch((error) => console.log(error))

}

Accepted Solutions (1)

Accepted Solutions (1)

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Madhava,

Are you sending the payload in XML format? Since you have defined the request header Content-Type as "application/json", it would expect the payload in json format and throw an error as soon as the XML payload begins with the opening tag "<".

Try changing the Content-Type header to "text/xml" instead if your payload is in XML format.

0 Likes

HI

FYI

The same code is working fine in SAP WEB IDE. and I'm able to call it Fetch API with method Post Successfully.

Now I have deployed Fiori app from SAP WEB IDE to S4 Hana Cloud. Now Iam getting error for fetch API in console is

"SyntaxError: Unexpected token '<', "<html><hea"... is not valid JSON"

Also, I have sent data in json format. Still iam getting same error

Any way i have used APi in promises. Its working as expected.

Answers (1)

Answers (1)

junwu
SAP Champion
SAP Champion
0 Likes

what is that api? is api from your s4 hana cloud system?

can you show us the error in part?

<html><head><title>Error report</title></head><body><h1>HTTP Status 500 - An internal application error occurred.

Request: -------------------</h1></body></html>

0 Likes

Hi,

Yes that API is to perform Goods Movement and SAP has design by default and it is standard API.

Thanks for the response.

Actually the error in cache part is - "SyntaxError: Unexpected token '<', "<html><hea"... is not valid JSON".


When i checked in console, In network tab status is "500" & Response is "<html><head><title>Error report</title></head><body><h1>HTTP Status 500 - An internal application error occurred.

Request: -------------------</h1></body></html> -> Inside the blank is request 123... and My webide server.

I haven't found any resolution to above error and not fixed. Now i removed fetch API and calling API inside Promise. Now its working fine.