A PHP client library to interact with PrestaShop API.
composer require iq2i/prestashop-webservice
- Create a client instance:
use IQ2i\PrestashopWebservice\Http\Client;
$client = new Client([
'url' => 'https://my-prestashop.com/api/',
'key' => '6MBWZM37S6XCZXYT81GD6XD41SKZ14TP',
]);
- Create a request:
use IQ2i\PrestashopWebservice\Http\Request\GetRequest;
/** GET /api/categories/1 */
$request = new GetRequest('categories', 1);
- Execute request
$response = $client->execute($request);
- Use client's response:
$statusCode = $response->getStatusCode();
$header = $response->getHeaders();
$content = $response->getContent();
The response's content is an array, client automatically decode XML.
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Schema;
use IQ2i\PrestashopWebservice\Http\Request\SchemaRequest;
/** GET /api/categories?schema=synopsis */
$request = new SchemaRequest('categories');
$request->addQueryAttribute(new Schema(Schema::SYNOPSIS))
use IQ2i\PrestashopWebservice\Http\Request\ListRequest;
/** GET /api/categories */
$request = new ListRequest('categories');
use IQ2i\PrestashopWebservice\Http\Request\GetRequest;
/** GET /api/categories/1 */
$request = new GetRequest('categories', 1);
use IQ2i\PrestashopWebservice\Http\Request\CreateRequest;
/** POST /api/categories */
$request = new CreateRequest('categories');
$request->setBody('XML content');
use IQ2i\PrestashopWebservice\Http\Request\UpdateRequest;
/** PUT /api/categories/1 */
$request = new UpdateRequest('categories', 1);
$request->setBody('XML content');
use IQ2i\PrestashopWebservice\Http\Request\DeleteRequest;
/** DELETE /api/categories/1 */
$request = new DeleteRequest('categories', 1);
PrestaShop defines list options for webservice: https://devdocs.prestashop.com/1.7/webservice/cheat-sheet/#list-options
These options are available in this library:
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Schema;
/** GET /api/categories?schema=synopsis */
$request = new SchemaRequest('categories');
$request->addQueryAttribute(new Schema(Schema::SYNOPSIS));
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Filter;
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Sort;
/** GET /api/categories?filter[name]=%[clothes]&sort=[name_ASC] */
$request = new ListRequest('categories');
$request->addQueryAttribute(new Filter('name', 'clothes', Filter::END));
$request->addQueryAttribute(new Sort('name', Sort::ASC));
Please report issues and request features at https://github.com/iq2i/prestashop-webservice/issues.
This bundle is under the MIT license. For the whole copyright, see the LICENSE file distributed with this source code.