API mercadolivre does not return JSON

0

When I paste the link address in the browser I see that the restfull API of the free market returns the data in JSON format, but when accessing the same link using the RestDebuger that comes with Delphi (Tools / Rest Debuger) I can only receive text / html.

I also tried to put a RestClient component in Delphi xe7 and set up the urlbase but it didnt work. Does anyone know how to do it?

See what this guy did in delphiXE6, but that example did not work for me. See the link link

object RESTClient1: TRESTClient
  Accept = 'application/json, text/plain; q=0.9;q=0.8,'
  AcceptCharset = 'UTF-8, *;q=0.8'
  AcceptEncoding = 'identity'
  BaseURL = 'https://api.mercadolibre.com/sites/MLB'
  ContentType = 'application/x-www-form-urlencoded'
  Params = <>
  HandleRedirects = True
  Left = 168
  Top = 8
end
object RESTRequest1: TRESTRequest
  Accept = 'application/json, text/plain; q=0.9;q=0.8,'
  Client = RESTClient1
  Params = <
    item
      name = 'q'
      Value = 'Smartphone'
    end
    item
      name = 'price'
      Value = '700.0-1000.0'
    end>
  Response = RESTResponse1
  SynchronizedEvents = False
  Left = 240
  Top = 8
end
object RESTResponse1: TRESTResponse
  ContentType = 'application/json'
  RootElement = 'categories'
  Left = 336
  Top = 8
end
    
asked by anonymous 12.01.2017 / 04:03

2 answers

2

This URL:

  

link

Forwards to the API documentation, not to a JSON code. However, according to this same documentation. The URL is correct.

I ran a test using the Chrome Postman extension, but specifying the content type in the request:

  

Content-Type: application / json

And in this test, the API returned valid JSON code.

I could not fix your code because you did not even provide it. However, your problem is that you are not specifying the type of content you are ordering. Most APIs do not care about this. But that league. If the component you are using does not support changing the request header, you may not be able to use it in this API.

    
12.01.2017 / 05:56
1

I just put "application / json" in RESTClient1.accept and it worked.

    
13.01.2017 / 16:05