Hello,
I'm working with a REST API where the response is a valid JSON but has a Content-Type: text/plain
. The response looks like this:
[{"OrderId":"46D2A6BD-8B34-4F55-B816-B90017CDBA28","OrderNumber":131,"DeviceId":"POS41232","VendorId":1,"VendorName":"Test Facility","StoreId":114}]
However, the log shows the following:
2025-01-10T15:33:16.340+01:00 2 1|Q-Id] dHTTP|Res: 0] HTTP/1.1 200 OK, 1615 Bytes Transferred
2025-01-10T15:33:16.340+01:00 2 1|Q-Id] HTTP|Res: 0] Request completed in 676 ms.
2025-01-10T15:33:16.344+01:00 3 31|Q-Id] META|Schema: JSONValidation] https://pos.no/getsales is not a valid JSON resource.
2025-01-10T15:33:16.345+01:00 3 11|Q-Id] +META|Schema: JSONValidation] Invalid JSON markup. Expected json, but instead found ptext/plain; charset=utf-8].
To attempt to fix this, I set Accept: application/json
in the request headers, but this results in a response wrapped in a string, like this:
" {\"OrderId\":\"46D2A6BD-8B34-4F55-B816-B90017CDBA28\",\"OrderNumber\":131,\"DeviceId\":\"POS41232\",\"VendorId\":1,\"VendorName\":\"Test Facility\",\"StoreId\":114}]"
And the log now shows:
2025-01-10T15:39:24.450+01:00 2 01|Q-Id] :HTTP|Res: 0] HTTP/1.1 200 OK, 8456 Bytes Transferred
2025-01-10T15:39:24.451+01:00 2 e1|Q-Id] -HTTP|Res: 0] Request completed in 672 ms.
2025-01-10T15:39:24.456+01:00 3 1|Q-Id] bMETA|Schema: JSONValidation] https://pos.no/getsales is not a valid JSON resource.
2025-01-10T15:39:24.457+01:00 3 v1|Q-Id] eMETA|Schema: JSONValidation] Length cannot be less than zero.
Question
It seems like the API is either returning JSON with the wrong content type (text/plain
) or wrapping the JSON in a string when I request application/json
.
What is the best way to handle this?
Any insights would be greatly appreciated.
Thanks!