Jump to content

How to get the json format of data from prestashop web service


rvkvino

Recommended Posts

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'm using the PSWebServiceLibrary.php to get the data from webservice and process the result, my code like below

 

<?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;

 

// And also i have tried echo json_encode($output); It will display result with http header and response body contents

 

//If i use print_r($output->categories->children()); It will display array with xml contents and  http header and response body contents

}
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';
}
?>

 

 

 

This code return the output with  HTTP Header and HTTP response body contents. I don't need to display the extra string except my result. How to do it using this web service.

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...