PHP code example of pobo-builder / pobo-php-sdk

1. Go to this page and download the library: Download pobo-builder/pobo-php-sdk 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/ */

    

pobo-builder / pobo-php-sdk example snippets


    try {
        $user = new \Pobo\UserClient(
            'email',
            'password'
        );
    } catch (\Pobo\Exceptions\AuthenticationException $e) {
        echo 'Authentication failed: ' . $e->getMessage();
    }
    
    $client = new \Pobo\PoboClient($user);

    /**
     * @var \Pobo\Libs\Models\CategoryModel[] $categories
     * @throws \Pobo\Exceptions\ApiClientException
    */
    $categories = $client->categories()->list();
    
    foreach ($categories as $category) {
        echo $category->getName();
    }

    /**
     * @var \Pobo\Libs\Models\CategoryModel $category
     * @throws \Pobo\Exceptions\ApiClientException
    */
    $category = $client->categories()->getById(300869);
    
    echo $category->getName();

    /**
     * @var \Pobo\Libs\Models\CategoryModel $category
     * @throws \Pobo\Exceptions\ApiClientException
    */
    
    $category = $client->categories()->getByGuid('1d7dc679-f76e-11ed-82e5-ce12b750376e');
    
    echo $category->getName();

    /**
     * @var \Pobo\Libs\Models\CategoryModel $category
     * @throws \Pobo\Exceptions\ApiClientException
    */
    
    $category = $client->categories()->getByName('Category Name');
    
    echo $category->getName();

    /**
     * @var \Pobo\Libs\Models\CategoryModel $category
     * @throws \Pobo\Exceptions\ApiClientException
    */
    
    $category = $client->categories()->add(
        'New Category',
        'https://pobo.myshoptet.com/new-category/',
        '885a0720-1dde-11ee-9ccb-c23895735dfd',
    );
    
    echo $newCategory->getId();

    /**
     * @var \Pobo\Libs\Models\ProductModel[] $products
     * @throws \Pobo\Exceptions\ApiClientException
    */
    $products = $client->products()->list();
    
    foreach ($products as $product) {
        echo $product->getName();
    }

    $categoryIds = [
        1,
        2,
        3
    ];
    
    ### OR ###
    $categoryIds = [
        $client->categories()->getById(300869)->getId(),
        $client->categories()->getByGuid('1d7dc679-f76e-11ed-82e5-ce12b750376e')->getId(),
        $client->categories()->getByName('iPhone')->getId(),
        $client->categories()->add('Nová kategorie', 'https://pobo.myshoptet.com/nova-kategorie/', '885a0720-1dde-11ee-9ccb-c23895735dfd')->getId(),
    ];
    
    
    $bulkImport = $client->products()->bulkImport(
        [
            [
                'guid' => '302b8ad6-07d5-11ec-b98c-0cc47a6c9370',
                'name' => 'Test Product from API',
                'short_description' => 'This is a test product created via API.',
                'description' => '<p>HTML description of the product.</p>',
                'is_visible' => true,
                'categories' => $categoryIds,
                'images' => [
                    [
                        'src' => 'https://picsum.photos/200/300',
                    ],
                    [
                        'src' => 'https://picsum.photos/200/300',
                        'main_image' => true,
                    ],
                ]
            ]
        ]
    );
    
    print_r($bulkImport);

    Array
    (
        [result] => Array
        (
            [success] => 1
            [skipped] => 0
            [errors] => Array()
        )
    )