ikurcubic/wolt-api

PHP Client for Wolt API

v1.0.2 2022-06-24 15:13 UTC

This package is auto-updated.

Last update: 2024-04-24 19:43:56 UTC


README

GitHub Workflow Status (master) Total Downloads Latest Version License

This package provides Wolt API PHP Client for Items and Inventory update

Installation

composer require ikurcubic/wolt-api

Usage

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

Wolt API PHP Client was created by Ivan Kurcubic under the MIT license.