eBay API returns JSON as Text

Nov 20, 2013 at 9:05 PM
I'm looking for some perspective. I'm entirely new to API programming. I've found that calling eBay's GeteBayTime method is returning JSON with a header of Text, not application/json. Is this a eBay bug, just average API weirdness, acceptable in some way, or what? Could it be an error on my part? I'm using C++ Rest SDK for client API access.

The solution, for those who face the same issue, is to change the response header:
        response.headers().set_content_type(L"application/json");
The actual request uses:

http://open.api.sandbox.ebay.com/shopping?callname=GeteBayTime&responseencoding=JSON&appid=<my appid>&siteid=0&version=713
Nov 20, 2013 at 10:55 PM
Hi BSalita,

What is the exact Content-Type header string value? You mention 'Text' so I'm assuming it is literally "text". Our extract_json() API checks to make sure it is one of the following values:
application/json
text/json
text/x-json
text/javascript
text/x-javascript
application/javascript
application/x-javascript
I think what you did by changing the Content-Type header to the standard application/json is good idea. There are just a couple things to keep in mind. First you need to be sure the data you are getting back is indeed json, if not obviously we will fail when trying to parse it. Second you need to be careful to not lose any charset information. For example if the Content-Type was "text; utf-16" and you replace it to be "application/json" when we go to parse the data we will assume it is utf-8, as this is the default for application/json if not specified. This means if you take this approach you should make sure to carry the charset portion forward. If you don't want to do this another option would be to get the data as a string and directly construct the json::value object yourself using http_response::extract_string().

As to whether or not this is an Ebay bug, I'm not quite sure. In my opinion yes it would be better if they returned the content type with the standard MIME type application/json.

Let's know if you hit any other issues.
Steve
Nov 20, 2013 at 11:18 PM
Great reply. Thanks. I hadn't considered the issue of switching charsets.

The exact mime type was text/plain;charset=utf-8