I need to return the json format of data for client request. I used prestashop 1.6 and enabled the web services and created the authkey. I am using below code
<?php
define('DEBUG', true); // Debug mode
define('PS_SHOP_PATH', 'http://www.example.com'); // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', 'myauthkey'); // Auth key (Get it in your Back Office)
require_once('PSWebServiceLibrary.php');
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Here we set the option array for the Webservice : we want customers resources
$opt['resource'] = 'categories';
$opt['output_format'] = 'JSON';
$opt['ps_method'] = 'GET';
// Call
$output = $webService->get($opt);
echo $output;
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error';
}
?>
But it returns like
HTTP RESPONSE HEADER
HTTP/1.1 200 OK
Date: Thu, 21 May 2015 10:37:18 GMT
Server: Apache/2.4.10 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
Access-Time: 1432204638
X-Powered-By: PrestaShop Webservice
PSWS-Version: 1.6.0.14
Execution-Time: 0.012
Content-Sha1: 39de35d56851e6fb74644c38ffcb34215d63822f
Vary: Accept-Encoding
Cache-Control: max-age=3600
Expires: Thu, 21 May 2015 11:37:18 GMT
Transfer-Encoding: chunked
Content-Type: text/xml;charset=utf-8
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<categories>
<category id="1" xlink:href="http://www.example.com/api/categories/1"/>
<category id="2" xlink:href="http://www.example.com/api/categories/2"/>
<category id="57" xlink:href="http://www.example.com/api/categories/57"/>
<category id="58" xlink:href="http://www.example.com/api/categories/58"/>
</categories>
</prestashop>
object(SimpleXMLElement)#2 (1) { ["categories"]=> object(SimpleXMLElement)#3 (1) { ["category"]=> array(17) { [0]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(1) { ["id"]=> string(1) "1" } } [1]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(1) { ["id"]=> string(1) "2" } } [2]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "57" } } [3]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "58" } } [4]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "59" } } [5]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "60" } } [6]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "61" } } [7]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "62" } } [8]=> object(SimpleXMLElement)#12 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "63" } } [9]=> object(SimpleXMLElement)#13 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "64" } } [10]=> object(SimpleXMLElement)#14 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "65" } } [11]=> object(SimpleXMLElement)#15 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "66" } } [12]=> object(SimpleXMLElement)#16 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "67" } } [13]=> object(SimpleXMLElement)#17 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "68" } } [14]=> object(SimpleXMLElement)#18 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "69" } } [15]=> object(SimpleXMLElement)#19 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "70" } } [16]=> object(SimpleXMLElement)#20 (1) { ["@attributes"]=> array(1) { ["id"]=> string(2) "71" } } } } }
how to return only json output without HTTP RESPONSE HEADER and RETURN HTTP BODY.