Search code examples
prestashopprestashop-1.7

Create a new product via Prestashop 1.7 web service


I am trying to create a new product via Prestashop 1.7 web service.

I am posting the following XML to https://www.myshop.com/api/products. (I created the XML data from the blank scheme at https://www.myshop.com/api/products?schema=blank)

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <script></script>
    <product>
        <id></id>
        <id_manufacturer>10</id_manufacturer>
        <id_supplier></id_supplier>
        <id_category_default></id_category_default>
        <new></new>
        <cache_default_attribute></cache_default_attribute>
        <id_default_image></id_default_image>
        <id_default_combination></id_default_combination>
        <id_tax_rules_group></id_tax_rules_group>
        <position_in_category></position_in_category>
        <type></type>
        <id_shop_default></id_shop_default>
        <reference></reference>
        <supplier_reference></supplier_reference>
        <location></location>
        <width></width>
        <height></height>
        <depth></depth>
        <weight></weight>
        <quantity_discount></quantity_discount>
        <ean13></ean13>
        <isbn></isbn>
        <upc></upc>
        <cache_is_pack></cache_is_pack>
        <cache_has_attachments></cache_has_attachments>
        <is_virtual></is_virtual>
        <state></state>
        <on_sale></on_sale>
        <online_only></online_only>
        <ecotax></ecotax>
        <minimal_quantity></minimal_quantity>
        <price>160,37</price>
        <wholesale_price></wholesale_price>
        <unity></unity>
        <unit_price_ratio></unit_price_ratio>
        <additional_shipping_cost></additional_shipping_cost>
        <customizable></customizable>
        <text_fields></text_fields>
        <uploadable_files></uploadable_files>
        <active></active>
        <redirect_type></redirect_type>
        <id_product_redirected></id_product_redirected>
        <available_for_order></available_for_order>
        <available_date></available_date>
        <show_condition></show_condition>
        <condition></condition>
        <show_price></show_price>
        <indexed></indexed>
        <visibility></visibility>
        <advanced_stock_management></advanced_stock_management>
        <date_add></date_add>
        <date_upd></date_upd>
        <pack_stock_type></pack_stock_type>
        <meta_description>
            <language id="1">meta_description</language>
        </meta_description>
        <meta_keywords>
            <language id="1">meta_keywords</language>
        </meta_keywords>
        <meta_title>
            <language id="1">meta_title</language>
        </meta_title>
        <link_rewrite>
            <language id="1"></language>
        </link_rewrite>
        <name>
            <language id="1">product name</language>
        </name>
        <description>
            <language id="1">product description</language>
        </description>
        <description_short>
            <language id="1">product short description</language>
        </description_short>
        <available_now>
            <language id="1"></language>
        </available_now>
        <available_later>
            <language id="1"></language>
        </available_later>
        <associations>
            <categories>
                <category>
                    <id></id>
                </category>
            </categories>
            <images>
                <image>
                    <id></id>
                </image>
            </images>
            <combinations>
                <combination>
                    <id></id>
                </combination>
            </combinations>
            <product_option_values>
                <product_option_value>
                    <id></id>
                </product_option_value>
            </product_option_values>
            <product_features>
                <product_feature>
                    <id></id>
                    <id_feature_value></id_feature_value>
                </product_feature>
            </product_features>
            <tags>
                <tag>
                    <id></id>
                </tag>
            </tags>
            <stock_availables>
                <stock_available>
                    <id></id>
                    <id_product_attribute></id_product_attribute>
                </stock_available>
            </stock_availables>
            <accessories>
                <product>
                    <id></id>
                </product>
            </accessories>
            <product_bundle>
                <product>
                    <id></id>
                    <quantity></quantity>
                </product>
            </product_bundle>
        </associations>
    </product>
</prestashop>

But I am getting the following error:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[41]]></code>
<message><![CDATA[parameter "price" required]]></message>
</error>
</errors>
</prestashop>

As you can see in the posted XML, the price field has a value. In addition, the values contained in the XML above were enough for Prestashop 1.6.

What am I doing wrong?


Solution

  • You need to remove the <script></script> from xml. I tested, it inserts in tables, but doesn't show in backoffice. To show in backoffice you need to set <state>1</state> in xml