Log Insight API and JSON no content to map due to end-of-input

While you will not see the error in the title of this blog post in the Log Insight UI, you may see it when issuing API calls to Log Insight and may also see it in the Log Insight runtime.log. What is it, what does it mean, and how do you fix it? Read on to learn more!
li-logo

The error means that you have a malformed JSON request. The key bit is “JSON”. The Log Insight API is based on JSON and you must ensure that you pass the Content-Type header with application/json. If you do not, then by default the Content-Type header will be set to application/x-www-form-urlencoded and you will receive the following error:

JSON: No content to map due to end-of-input

Now, it is possible to have an unintentionally malformed API request. Let’s say you have a shell script like the following:

#!/user/bin/env bash
HEADERS='-H "Content-Type: application/json"'
curl -ki -X GET $HEADERS https://loginsight.example.com/api/v1/version

IMPORTANT: Do not run curl with the -s flag or the errors will not be reported!
If you run this code then you would receive the following output:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=AD9470252D1808D81E2E62D059F7EBC0; Path=/; Secure; HttpOnly
ACCESS-CONTROL-EXPOSE-HEADERS: X-LI-Build
VMware-LI-API-Status: Tech Preview
Warning: 299 - "Tech Preview: This API is a tech-preview. It is subject to change or removal as the product evolves." "Sun, 16 Oct 2016 11:08:58 GMT"
Date: Sun, 16 Oct 2016 11:08:58 GMT
X-LI-Build: 4202923
Content-Type: application/json;charset=utf-8
Content-Language: en-US
Content-Length: 46
Server: loginsight
curl: (6) Couldn't resolve host 'application'
{"releaseName":"GA","version":"3.6.0-4202923"}

Notice how the first line contains an error. This is because of the HEADERS variable. If you wrap the HEADERS variable in double quotations then it works as expected:

$ > curl -k -X GET "$HEADERS" https://172.16.90.156/api/v1/version
{"releaseName":"GA","version":"3.6.0-4202923"}

While the header is the most common reason to see this error, if any other part of the API request is malformed you may experience this error as well. I hope this helps!

© 2016, Steve Flanders. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top