PHP code example of ikurcubic / wolt-api

1. Go to this page and download the library: Download ikurcubic/wolt-api 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/ */

    

ikurcubic / wolt-api example snippets


    
    use GuzzleHttp\Exception\ClientException;
    use IvanKurcubic\WoltAPI\Client;
    use IvanKurcubic\WoltAPI\Exceptions\HttpResponseException;

    $username = 'test';
    $password = 'b77b7a63cd5176154ca2802f9927ee598dc';
    $venueId = '62b041691ce47b414960c712'
    
    $api = new Client($username, $password, Client::ENV_STAGE);
    
    $data = [
        "data" => [
            ['sku'=>'1234', 'price'=>10000, 'enabled'=>true, 'vat_percentage'=>20.00],
            ['sku'=>'5678', 'price'=>20000, 'enabled'=>true, 'vat_percentage'=>20.00],
            ...
        ]   
    ];
    
    try {
        $api->updateItems($venueId, $data);
    } catch (HttpResponseException|ClientException $exception) {
        if ($exception->getResponse()->getStatusCode() == 429) {
            $retryAfter = $exception->getResponse()->getHeader('retry-after');
            if (is_array($retryAfter)) {
                $retryAfter = $retryAfter[0] ?? 0;
            }
            echo "Too many requests, need to wait $retryAfter seconds.";
            sleep($retryAfter + 2);
            $api->updateItems($venueId, $data);
        } else {
            throw $exception;
        }
    }