{"id":6196860,"date":"2015-06-04T07:14:51","date_gmt":"2015-06-04T07:14:51","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/url-json-api-coding\/"},"modified":"2016-08-30T14:05:34","modified_gmt":"2016-08-30T14:05:34","slug":"url-json-api-coding","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/url-json-api-coding\/","title":{"rendered":"URL Json API coding"},"content":{"rendered":"<p>Hi everyone, I&#8217;m hoping you can help me with this.  I have a custom made API (made by someone else) that I need to implement on a site.  The API uses Json and is accessible via URL&#8217;s.  The problem is I don&#8217;t know the best way to put it into action in WordPress.  It should display a clothing list and clothing details for a particular piece of clothing.  Can anyone give any advice, or make any recommendations on how to get this to work?  Thanks in advance for your help.  Here&#8217;s what I have so far:<\/p>\n<pre><code>-----Begin------\n&lt;script\tsrc=&quot;resources\/js\/jquery-1.10.2.js&quot;&gt;&lt;\/script&gt;\n&lt;input type=&quot;button&quot; onclick=&quot;ajaxtest1()&quot; value=&quot;getAllClothing&quot;&gt; &amp;nbsp; &amp;nbsp; Clothing List &amp;nbsp; &amp;nbsp;&lt;select id=&quot;clolist&quot;&gt;&lt;\/select&gt;&lt;br\/&gt;\n&lt;br\/&gt;\n&lt;input type=&quot;text&quot; id=&quot;cloid&quot;&gt;&lt;input type=&quot;button&quot; onclick=&quot;ajaxtest2()&quot; value=&quot;getClothingDetails&quot;&gt;&lt;br\/&gt;\n\n&lt;div id=&quot;test1&quot;&gt;&lt;\/div&gt;\n&lt;script&gt;\n\tvar headerdata = {};\n\theaderdata[&quot;auth&quot;] = &quot;1234567890987654321qwerty&quot;;\n\n\tfunction ajaxtest1() {\n\t\tvar data = {\n\t\t\t&quot;consumerName&quot; : &quot;microsite&quot;,\n\t\t\t&quot;serviceName&quot; : &quot;getClothingList&quot;\n\t\t};\n\t\tajaxCall(data, headerdata,ClothingList)\n\t}\n\n\tfunction ajaxtest2() {\n\t\tvar cloid=$(&quot;#cloid&quot;).val();\n\t\tvar data = {\n\t\t\t&quot;consumerName&quot; : &quot;microsite&quot;,\n\t\t\t&quot;data&quot; : &quot;{\\&quot;ClothingId\\&quot; : \\&quot;&quot;+cloid+&quot;\\&quot;}&quot;,\n\t\t\t&quot;serviceName&quot; : &quot;getClothingDetails&quot;\n\t\t};\n\t\tajaxCall(data, headerdata,ClothingDetails)\n\t}\n\n\tfunction ClothingList(data) {\n\t\tvar obj=JSON.parse(data)\n\t\tvar list=obj.ClothingList;\n\t\t$(&quot;#clolist&quot;).html(&quot;&quot;);\n\t\tif(list.length==undefined){\n\t\t\t\t$(&quot;#clolist&quot;).append(new Option(&quot;--No Clothing--&quot;, &quot;&quot;));\n\t\t}else if(list.length&gt;0){\n\t\t\t\t$(&quot;#clolist&quot;).append(new Option(&quot;--Clothing--&quot;, &quot;&quot;));\n\t\t\t$.each(list, function (i, val) {\n\t\t\t\t$(&quot;#clolist&quot;).append(new Option(val.ClothingName,val.ClothingID));\n\t\t\t});\n\t\t}\n\t}\n\n\tfunction ClothingDetails(data) {\n\t\t$(&quot;#test1&quot;).html(&quot;&quot;);\n\t\tvar obj=JSON.parse(data)\n\t\tvar clo=obj.clothing;\n\t\tconsole.log(clo);\n\t\t$(&quot;#test1&quot;).append(&quot;Name : &lt;span&gt;&quot;+clo.ClothingDisplayName+&quot;&lt;\/span&gt;&lt;br\/&gt;&quot;)\n\t\t$(&quot;#test1&quot;).append(&quot;Color : &lt;span&gt;&quot;+clo.clothingColor+&quot;&lt;\/span&gt;&lt;br\/&gt;&quot;)\n\t\t$(&quot;#test1&quot;).append(&quot;Sizes : &lt;span&gt;&quot;+clo.clothingSizes+&quot;&lt;\/span&gt;&lt;br\/&gt;&quot;)\n\t}\n\n\tfunction ajaxCall(data, headerdata,callback) {\n\t\t$.ajax({\n\t\t\ttype : &quot;POST&quot;,\n\t\t\turl : &quot;http:\/\/1.1.1.1:8111\/meh\/api\/apiService&quot;,\n\t\t\tdata : data,\n\t\t\theaders : headerdata,\n\t\t\tcrossDomain : true,\n\t\t\tsuccess : callback,\n\t\t\terror : function(data, status) {\n\t\t\t\talert(&quot;Error  &quot; + status);\n\t\t\t}\n\t\t});\n\t}\n&lt;\/script&gt;\n---------End<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-6196860","topic","type-topic","status-closed","hentry","topic-tag-api","topic-tag-custom-api","topic-tag-external-api","topic-tag-json"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6196860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6196860\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6196860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}