Skip to content

pobo-builder/pobo-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pobo SDK for PHP

Pobo SDK is a PHP library designed to integrate with the Pobo system. It provides functionality for bulk uploading products, retrieving all products, and fetching categories.

Installation

composer require pobo-builder/pobo-php-sdk

Authentication

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

Fetch All Categories

Retrieve a list of all categories from the system:

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

Get Category by ID

Retrieve a specific category by its ID.

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

Get Category by GUID

Retrieve a specific category by its GUID.

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

Get Category by Name

Retrieve a specific category by its name.

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

Add a New Category

Add a new category to the system. This function returns the created CategoryModel.

    /**
     * @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();

Fetch Products

Retrieve a list of all products from the system:

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

Bulk Upload Products

Bulk upload multiple products to the system:

    $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);

Example Response

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