Skip to main content

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!

Hi ​@EivindJ 

When you run the call in something like Postman, do you see this text/plain header in the result and does it give the same error if you force the application/json content type?

Also, when you force a content type in a rsd file it is done like so.

<api:set attr="ContentType" value="application/json" /

The difference is that you normally would add a - so it is content-type, but that will not work for RSD files.


Hi!

Yes, I can see the header Content-Type: text/plain in the response in Postman.
 

In Postman:
If I set the header Content-Type: application/json, the response is still text/plain.
If I set the header Accept: application/json the response is application/json but now wrapped in a string.


In TX:
I have tried to set Content-Type like this as a Custom Header in “Edit CData Data Source” (both with and without the ‘-’) but I still get the error: “Invalid JSON markup. Expected json, but instead found stext/plain; charset=utf-8].”

 

 


Hi ​@EivindJ 

Try to add the following in the Other field of the CData REST setup.

IgnoreContentType=true

I have had similar questions before and this was a solution in one of these.


This works! Thank you!


Reply