PHP code example of matejch / webareal-api-handler

1. Go to this page and download the library: Download matejch/webareal-api-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matejch / webareal-api-handler example snippets


/** create handler, constructor ur webareal admin interface */
$handler = new \matejch\webarealApiHandler\WebarealHandler($username,$password,$apiToken);

/** New handler instance can be also created with json file, that contains username, password, apiKey and url(optional) */

$handler = \matejch\webarealApiHandler\WebarealHandler::createFromFile('path_to_the_json_file');

/** login before other requests */
$handler->login();

/** this is function for testing successful login, returns message whether access was granted */
$handler->test();

/** 
 * You can check info about how many request you have remaining, 
 * what's your limit and whether you are blocked 
 */
$handler->apiInfo()

/** API subdomain */
/** If you don't use subdomain set in class use this method*/
$handler->setBaseUrl($apiSubDomainUrl);

/** Only one api endpoint exists, and that is for getting list of customers */
$customers = new \matejch\webarealApiHandler\WCustomers($username,$password,$apiToken);
$customers->login();

$customers->asArray = true; // optional

/** also query string for searching specific customers can be set*/
$customers->searchBy(['limit' => 20,
                      'offset' => 0,
                      'sortBy' => 'id',
                      'sortDirection' => 'desc',
                      'findBy' => 'id',
                      'searchedString' => 'search string here']);

/** data can be returned as json string or array of customers */
$customers->get();
 

/**For mass update use */ 

function setFieldsAsString(array_of_products)



$products = new \matejch\webarealApiHandler\WProduct($username,$password,$apiToken);
$products->login();

$products->asArray = true; // optional

/** get list of products */
/** filter can be set with $products->searchBy(array of searchable options) */
$products->get();

/** 
 * id of product necessary for update, delete, view can be obtained with get() method, 
 * or through csv from your admin interface
 */

/** create new product */
$products->setFields(['name' => 'Name', ....]);
$products->create();

/** update existing product, you must know id beforehand */
$products->setFields(['secondName' => 'Second', ....]);
$products->update($id);

/** delete existing product, you must know id beforehand */
$products->delete($id);

/** detail info about one product, you must know id beforehand */
$products->view($id);

/** update and create multiple products at once */

$products->setFields(['name' => 'product', ....]);

$products->createMultiple();

/** to update multiple product id is 

$orders = new \matejch\webarealApiHandler\WOrder($username,$password,$apiToken);
$orders->login();

$orders->get();

$orders->states();

$orders->view($id);

$products->setFields(['firstname' => 'Jane', 'lastname' => 'Doe',...]);
$orders->update($id);

$orders->delete($id)

$property = new \matejch\webarealApiHandler\WProductProperty($username,$password,$apiToken);
$property->login();

$property->get();

$property->view($id);

$property->setFields(['name' => 'Color']);
$property->create($id);

/** before calling update, setFields must set fields you want to update on property */
$property->setFields(['name' => 'Color']);
$property->update($id);

/** delete property */
$property->delete($id);

/** create and update multiple */
$property->setFields(['name' => 'Color']);
$property->createMultiple();

/** id for every property must be set when updating */
$property->updateMultiple();

/** Product variants are products connected to other product */
$variants = new \matejch\webarealApiHandler\WProductVariants($username,$password,$apiToken);
$variants->login();

/** get list of variants, can be search by using searchBy method */
$variants->get();

$variants->view($id);

/** before calling create, setFields must set fields you want to update on property */
$variants->setFields(['idProduct' => 9,'name' => 'Jacket']);
$variants->create($id);

/** before calling update, setFields must set fields you want to update on property */
$variants->setFields(['idProduct' => 9,'name' => 'Jacket']);
$variants->update($id);

/** delete property */
$variants->delete($id);

/** create and update multiple */
$variants->setFields(['name' => 'Color']);
$variants->createMultiple();

/** id for every variant must be set when updating */
$variants->updateMultiple();

php composer.phar