<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HTTP request returns html instead of json in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/777315#M95862</link>
    <description>&lt;P&gt;"Accept: application/json" is just a hint to the web service as to the type of response you want returned.&lt;/P&gt;
&lt;P&gt;Web services are completely free to ignore it.&lt;/P&gt;
&lt;P&gt;Is this an external web service or one developed "in house" if "in house", then you'll want to talk to the developer about returning json data when requested by a client.&lt;/P&gt;
&lt;P&gt;If external, can you post the api doc?&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jul 2024 21:59:57 GMT</pubDate>
    <dc:creator>bryan_boone</dc:creator>
    <dc:date>2024-07-29T21:59:57Z</dc:date>
    <item>
      <title>HTTP request returns html instead of json</title>
      <link>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773315#M95428</link>
      <description>&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;I tried to request JSON from an API using the following script:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;request_neu = New HTTP Request(
	URL( "https://redacted.com/api/path?fileType=Json" ),
	Method( "GET" ),
	//headers( {"Accept: text/plain", "Accept: text/html", "Accept: */*"} ),
	//headers( {"Accept: */*"} ),
	//I tried everything here
	Headers( {"Accept: application/json"} ),
	Username( "api.user" ),
	Password( "redacted" ),
	Timeout( 900000 )
);

response = request_neu &amp;lt;&amp;lt; send;
show(request_neu &amp;lt;&amp;lt; get mime type);
show(request_neu &amp;lt;&amp;lt; get status);
show(request_neu &amp;lt;&amp;lt; get status message);
show(substr(response,1,999));
JSON to data table(response);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I added the debugging statements after the JSON to data table function resulted in an error and the output is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;request_neu &amp;lt;&amp;lt; get mime type = "text/html; charset=utf-8";
request_neu &amp;lt;&amp;lt; get status = 200;
request_neu &amp;lt;&amp;lt; get status message = "HTTP/1.1 200 OK";
Substr(response, 1, 999) = "
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html class=\!"no-js smooth-scrolling-html\!" lang=\!"en-GB\!" dir=\!"ltr\!"&amp;gt;
&amp;lt;head&amp;gt;
etc&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;so essentially instead of JSON I receive html.&lt;/P&gt;&lt;P&gt;The interesting thing is that it works with Postman, Python, even Excel.&lt;/P&gt;&lt;P&gt;The really interesting thing is that some months ago when I created this script it also was working.&lt;/P&gt;&lt;P&gt;Do you have some idea what is going on here?&lt;/P&gt;&lt;P&gt;thx&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 12:29:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773315#M95428</guid>
      <dc:creator>dk</dc:creator>
      <dc:date>2024-07-16T12:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP request returns html instead of json</title>
      <link>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773325#M95429</link>
      <description>&lt;P&gt;Have you tried to see what the HTML contains? You could for example save it as .html page using Save Text File()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't quickly see anything wrong in your syntax, below is slightly modified example from scripting index&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

request = New HTTP Request(
	url("http://httpbin.org/get"),
	Method("GET"),
	Headers({"Accept: application/json"}),
	Username("ross"),
	Password("Abc123"), 

);
data = request &amp;lt;&amp;lt; Send;
Show(request &amp;lt;&amp;lt; get response headers, request &amp;lt;&amp;lt; get last url);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 13:06:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773325#M95429</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-16T13:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP request returns html instead of json</title>
      <link>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773326#M95430</link>
      <description>&lt;P&gt;When I looked at the html, it looks similar to the platform's web page except that the relative links are broken.&lt;/P&gt;&lt;P&gt;I am afraid that I will need to discuss with the people responsible for the platform since the mistake seems to originate from there.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 13:32:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/773326#M95430</guid>
      <dc:creator>dk</dc:creator>
      <dc:date>2024-07-16T13:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: HTTP request returns html instead of json</title>
      <link>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/777315#M95862</link>
      <description>&lt;P&gt;"Accept: application/json" is just a hint to the web service as to the type of response you want returned.&lt;/P&gt;
&lt;P&gt;Web services are completely free to ignore it.&lt;/P&gt;
&lt;P&gt;Is this an external web service or one developed "in house" if "in house", then you'll want to talk to the developer about returning json data when requested by a client.&lt;/P&gt;
&lt;P&gt;If external, can you post the api doc?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 21:59:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/HTTP-request-returns-html-instead-of-json/m-p/777315#M95862</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2024-07-29T21:59:57Z</dc:date>
    </item>
  </channel>
</rss>

