Prestashop: Bug REST API with JSON format - Get an image

Created on 11 Sep 2019  路  14Comments  路  Source: PrestaShop/PrestaShop

I'm trying to build an application that uses rest api. And when I send a request for images https://arduino-pl.com/api/images/products/221 I have an error

{"":[{"id":"221"},{"id":"711"}],"errors":[{"code":5,"message":"[PHP Notice #8] Undefined index: objectsNodeName (\/var\/www\/reznik.p.p1\/data\/www\/arduino-pl.com\/classes\/webservice\/WebserviceOutputJSON.php, line 127)"},{"code":5,"message":"[PHP Notice #8] Undefined index: objectsNodeName (\/var\/www\/reznik.p.p1\/data\/www\/arduino-pl.com\/classes\/webservice\/WebserviceOutputJSON.php, line 127)"},{"code":61,"message":"This image does not exist on disk"}]}

However it works fine, if output format is XML:

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<image id="221">
<declination id="711" xlink:href="https://arduino-pl.com/api/images/products/221/711"/>
</image>
</prestashop>

`
Additional information
PrestaShop version: 1.7.6.1
PHP version: 7.1

1.7.5.2 1.7.6.1 Bug To Do Trivial WS Webservice

All 14 comments

Hi @dsukeeper,

I did not manage to reproduce the issue with PS1.7.6.1 => It is OK
I tried with this link: shop.com/api?output_format=JSON
image
I attached a screen record
https://drive.google.com/file/d/1u10EkU53V3R8ey6cS7D049tBc6mQBvaT/view
Thanks to check & feedback

As I said it doesn't work when I try to get images links.
For exemple:
https://arduino-pl.com/api/images/products/221

I attached a screen record
https://drive.google.com/open?id=1aybslWGw9yjWt2w6GMnoN8mK0baQXpd4

@dsukeeper, I tried with PS1.7.5.2
I have this error
{"errors":[{"code":3,"message":"[PHP Warning #2] count(): Parameter must be an array or an object that implements Countable (\/var\/www\/html\/st1752\/classes\/webservice\/WebserviceOutputJSON.php, line 153)"}]}
But with PS1.7.6.0 & PS1.7.6.1 => this error message is not displayed
https://drive.google.com/file/d/1OQc6rvMcD5Rwqrygrq_cQuheAYamwjSL/view

Thanks to check & feedback.

I have different issue because I already edited classes/webservice/WebserviceOutputJSON.php in 41 line was
protected $currentAssociatedEntity;
and now:
protected $currentAssociatedEntity = array();
Try that:)
However I still have a problem :(

@dsukeeper, this issue is fixed with PS1.7.6.0 with PS1.7.6.0
https://github.com/PrestaShop/PrestaShop/pull/11902
As I said with PS1.7.6.1 => I don't have any error.

Thanks!

It's good, that it #11902 was fixed.
However, on 1.7.6.1 I have errors with JSON, when I try to get links to images. It works only when output format is XML

https://drive.google.com/open?id=1aybslWGw9yjWt2w6GMnoN8mK0baQXpd4

@dsukeeper, I tried with this link as your screen record
http://projet/shop.com/api/images/products/31?output_format=JSON
I have this message
{"":[{"id":"31"},{"id":"33"}],"errors":[{"code":61,"message":"This image does not exist on disk"}]}
But I don't have warnings as you.

Thanks!

Yes, but if you choose output format xml - it will work.

@dsukeeper, the only issue => I manage to reproduce is this error:
{"code":61,"message":"This image does not exist on disk"}]}
I have the same issue with PS1.7.5.2 & PS1.7.6.1.
I鈥檒l add this to the debug roadmap so that it鈥檚 fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

Hi @dsukeeper same error do you have a solution ?

cap
same isssue here

PS: 1.7.6.5. PHP: 7.2.31.

There are still problems with JSON and images.

  • api/images/?output_format=XML works fine, JSON returns nothing.
    Well, it doesn't matter.

  • api/images/products/?output_format=XML works fine, JSON returns nothing.
    How do I know which products have pictures? Should we try it all one by one?

  • api/images/products/X?output_format=XML works fine, JSON returns 'something':
    {
    "": [ <- "images" better than ""
    {
    "id": "X" <- Here comes the product's id. Please remove this entry.
    },
    {
    "id": "33"
    },
    {
    "id": "34"
    }
    ],
    "errors": [ <- 驴?
    {
    "code": 61,
    "message": "This image does not exist on disk"
    }
    ]
    }

PS. 1.7.6.7
/api/images/products/1?output_format=XML works fine, JSON a very messy json.

{"":[{"id":"1"},{"id":"1"},{"id":"2"}],"errors":[{"code":5,"message":"[PHP Notice #8] Undefined index: objectsNodeName (C:\\Users\\slius\\xampp\\htdocs\\prestashop_1.7.6.7\\classes\\webservice\\WebserviceOutputJSON.php, line 127)"},{"code":5,"message":"[PHP Notice #8] Undefined index: objectsNodeName (C:\\Users\\slius\\xampp\\htdocs\\prestashop_1.7.6.7\\classes\\webservice\\WebserviceOutputJSON.php, line 127)"},{"code":5,"message":"[PHP Notice #8] Undefined index: objectsNodeName (C:\\Users\\slius\\xampp\\htdocs\\prestashop_1.7.6.7\\classes\\webservice\\WebserviceOutputJSON.php, line 127)"},{"code":61,"message":"This image does not exist on disk"}]}

I can confirm this error happening on Prestashop 1.7.6.8. Request
GET: _api/images/products/31_
Headers:
_["Authorization: Basic ABCABCABC","Io-Format: JSON","Content-Type: text\/xml; charset=utf-8"]_

Error is triggered on
https://github.com/PrestaShop/PrestaShop/blob/64e72caf510dea1ab1678d1fe0c7e00d42a543ac/classes/webservice/WebserviceOutputJSON.php#L127

I believe the solution may be:

$this->content[$node_name][] = ['id' => $more_attr['id']];

As I am new to Prestashop, I cannot be sure this solution wouldnt affect anything related, so let this serve as a suggestion for more advanced prestashoper.

Currently the only solution to avoid this error is to use XML format.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PrestaShark picture PrestaShark  路  3Comments

zuk3975 picture zuk3975  路  3Comments

zuk3975 picture zuk3975  路  3Comments

vincent-dp picture vincent-dp  路  3Comments

matks picture matks  路  3Comments