Prestashop: web service product update failing with "Property Product->price is not valid"

Created on 23 May 2019  路  3Comments  路  Source: PrestaShop/PrestaShop

I'm trying to update a product using the web service, this is my request:

```
xmlns:xlink="http://www.w3.org/1999/xlink">






and this is the response:
```<?xml version="1.0" encoding="UTF-8"?>
<prestashop
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <errors>
    <error>
      <code>
        <![CDATA[85]]>
      </code>
      <message>
        <![CDATA[Validation error: "Property Product->price is not valid"]]>
      </message>
    </error>
  </errors>
</prestashop>

This is on a standard installation with standard sample data on version 1.7.5.2.

1.7.5.2 No change required Products WS

Most helpful comment

I am not consuming the web service from a PHP client so I can't provide feedback on your test.
I found the problem on my end: spaces and newlines. This is working:

<prestashop
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <product>
    <id><![CDATA[1]]></id>
    <price><![CDATA[25.00]]></price>
  </product>
</prestashop>

Are you planning a proper rest/json/openapi or maybe graphql API in your roadmap?

All 3 comments

Hi @esistgut,

I used this script

<?php

$url = 'http://shop';

$ws = new PrestaShopWebservice(
                           $url,
                            'Key',
                            false);

$id =  54; //ID product Here

$timestamp_debut = microtime(true);
$xml = $ws->get(array('resource' => 'products', 'id' => $id));

//Unset readonly fields or buggy fields
unset($xml->product->position_in_category);
unset($xml->product->manufacturer_name);
unset($xml->product->associations->product_features); 
unset($xml->product->quantity);
unset($xml->product->associations->categories);
unset($xml->product->type);

$product = $xml->children()->children();
$product->price = 1.121;

$opt['putXml'] = $xml->asXML();                  
$opt['id'] = $id;
$opt['resource'] = 'products';

$xml = $ws->edit($opt);
echo "DONE";

And it is OK.

Thanks to check & feedback

I am not consuming the web service from a PHP client so I can't provide feedback on your test.
I found the problem on my end: spaces and newlines. This is working:

<prestashop
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <product>
    <id><![CDATA[1]]></id>
    <price><![CDATA[25.00]]></price>
  </product>
</prestashop>

Are you planning a proper rest/json/openapi or maybe graphql API in your roadmap?

@esistgut, thanks for your feedback.

No, it is not planned yet.
The API only supports XML on input but supports JSON output if you choose:

http://[email protected]/api?output_format=JSON

Since it is fixed, I close the issue.
Feel free to open a new one when needed.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fabuloops picture Fabuloops  路  3Comments

centoasa picture centoasa  路  3Comments

matks picture matks  路  3Comments

vincent-dp picture vincent-dp  路  3Comments

sandra2n picture sandra2n  路  3Comments