akeneo / api-php-client

PHP client of Akeneo PIM API

Home Page:https://packagist.org/packages/akeneo/api-php-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot set image for a product

heojee1 opened this issue · comments

I have an attribute named 'thumbnail' for each product. I have images in a folder 'scraper/images.'
I am not sure how I should set an image for a product. Is there a constraint on file name or the path?
When I tried setting thumbnail via the path to the image as follows:

    $client->getProductApi()->upsert($product_id, [
        'values' => [
            'thumbnail' => [
                [
                    'data' => '/scraper/images/' . $product_name . '.jpeg',
                    'locale' => null,
                    'scope' => null
                ]
            ]
        ]
    ]);

I get the following error message:

PHP Fatal error:  Uncaught Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException: Property "thumbnail" expects a valid pathname as data, "/scraper/images/at.jpeg" given. Check the expected format on the API documentation. (see https://api.akeneo.com/php-client/exception.html#unprocessable-entity-exception) in /srv/pim/client/vendor/akeneo/api-php-client/src/Client/HttpExceptionHandler.php:58
Stack trace:
#0 /srv/pim/client/vendor/akeneo/api-php-client/src/Client/HttpClient.php(62): Akeneo\Pim\ApiClient\Client\HttpExceptionHandler->transformResponseToException(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /srv/pim/client/vendor/akeneo/api-php-client/src/Client/AuthenticatedHttpClient.php(63): Akeneo\Pim\ApiClient\Client\HttpClient->sendRequest('PATCH', 'http://httpd:80...', Array, '{"values":{"thu...')
#2 /srv/pim/client/vendor/akeneo/api-php-client/src/Client/ResourceClient.php(142): Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient->sendRequest('PATCH', 'http://httpd:80...', Array, '{"values":{"thu...')
#3 /srv/pim/client/vendor/akeneo/api-php-client/src/Api/ProductApi.php(97): Akeneo\Pim\ApiClient\Client\ResourceClient->upsertResource('http://httpd:80...', Array, Array)
#4 /srv/pim/client/importProducts.php(306): Akeneo\Pim\ApiClient\Api\ProductApi->upsert('1', Array)
#5 /srv/pim/client/importProducts.php(354): createProduct(Object(PDO), Object(Akeneo\Pim\ApiClient\AkeneoPimClient), Array, 'Apple_Products')
#6 /srv/pim/client/importProducts.php(394): createProducts(Object(PDO), Object(Akeneo\Pim\ApiClient\AkeneoPimClient), 'Apple_Products')
#7 /srv/pim/client/importProducts.php(397): execute()
#8 {main}
  thrown in /srv/pim/client/vendor/akeneo/api-php-client/src/Client/HttpExceptionHandler.php on line 58