Uploading form - Unexpected token < in json

Hi all,

What would be the reason for the error Unexpected token < in json at position 0 when uploading a form ? converting to XML goes through without any mistakes, but when uploading it fails with this error.

Uploading the converted XML through the User Interface does work without any issues which was confusing to me.

@magp18 - Hi there!

Can you give more details? Pasting in output from where the error is (maybe cht-conf?) would be great.

With out knowing more, I’m pretty certain the code is expecting JSON but is instead getting HTML. Maybe double check the CHT instance is full up and running? It will sometimes return HTML instead of JSON when it’s partially down.

1 Like

On top of what @mrjones has said, we also find this error occurs when using incorrect login details, because the API may redirect you to the login page which is HTML so starts with a < and breaks the JSON parsing.

Hi, yes sure

This is what I am getting when uploading the file.

The html does sound like something that potentially could be happening as I am pulling the file with wget -O name.xlsx url - from a repo but I think then it shouldn’t even be converting to xml right?

hi @magp18
As far as I can tell, you’re getting the error when requesting the main form document. Can you check the connection to the server?

Hi @diana the connection to the server should be good, because if I use a different form on the server to convert + upload, it goes through

Can you please try that exact URL manually?

Yes, it works and I log in the web application

Hi all,
I had the same error yesterday as well but when trying to sync data from a tablet device.
Inspecting with chrome, I found this error:

Hi @nsaibirni
Can you check your server status? Specifically the logs would be very useful to check service health.
If you’re running CHT 4.x, then you can leverage this script to get the logs.