Reputation: 331
I'm searching for a tutorial or documentation where is explained the webservice use of Prestashop (v1.5.6.0). I'd like simply add or edit (update) o product. There is'not a tutorial clean or with example about use of prestashop's api. Coul you help me please ?
For example, i'd like add object a:
define('PS_SHOP_PATH', 'http://localhost/myshop'); // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', '****'); // Auth key (Get it in your Back Office)
require_once('api/PSWebServiceLibrary.php');
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products');
Now, how can i set my values for a new object ? In the example you can insert only required value. Could you help me ?
And for update ?
Please ,no linked me Prestashop documentation, i have already read it, i'm asking your help. Thanks and excuse for my bad english.
Upvotes: 0
Views: 5355
Reputation: 1026
Here is the link to the official documentation. You will find there all the information you need.
Basically, you'll need to create an XML that represents the object you'd like to PUT.
Lets say you want to create a new category.
First, you need to get the schema :
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/categories?schema=blank'));
Which is something like this :
<prestashop>
<category>
</category>
</prestashop>
Then you'll have to set the content of the xml ($resources)
$resources = $xml->children()->children();
$resources->active = true;
$resources->..........
etc.
Finally,
try
{
$opt = array('resource' => 'categories');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
catch (PrestaShopWebserviceException $e)
{
echo 'Something went wrong: '.$e->getMessage();
}
Upvotes: 3