Jump to content

Adding products to PrestaShop 1.6.1.1 with WebService Bad Request


Heidy

Recommended Posts

Hi,

I am trying to add products to my shop powered by PS 1.6.1.1. My code:
 



       <?php
        ini_set('display_errors',1);
            ini_set('display_startup_errors',1);
            error_reporting(-1);
            define('_PS_DEBUG_SQL', true); 
        define('DEBUG', true);
        define('PS_SHOP_PATH', 'http://www.xxx.cz');
        define('PS_WS_AUTH_KEY', 'authkey');
        require_once('./PSWebServiceLibrary.php');
        $psXML = <<<XML
        <prestashop>
        <product>
            <id/>
            <id_manufacturer>0</id_manufacturer>
            <id_supplier>24</id_supplier>
            <id_category_default>2</id_category_default>
            <new/>
            <cache_default_attribute>0</cache_default_attribute>
            <id_default_image/>
            <id_default_combination notFilterable="true"/>
            <id_tax_rules_group>1</id_tax_rules_group>
            <position_in_category/>
            <type>simple</type>
            <id_shop_default>1</id_shop_default>
            <reference/>
            <supplier_reference>reference</supplier_reference>
            <location/>
            <width/>
            <height/>
            <depth/>
            <weight>0.1</weight>
            <quantity notFilterable="true">0</quantity>
            <quantity_discount>0</quantity_discount>
            <ean13/>
            <upc/>
            <cache_is_pack>0</cache_is_pack>
            <cache_has_attachments>0</cache_has_attachments>
            <is_virtual>0</is_virtual>
            <on_sale>0</on_sale>
            <online_only>0</online_only>
            <ecotax>0.000000</ecotax>
            <minimal_quantity>1</minimal_quantity>
            <price>0.000000</price>
            <wholesale_price>0.000000</wholesale_price>
            <unity/>
            <unit_price_ratio>0.000000</unit_price_ratio>
            <additional_shipping_cost>0.00</additional_shipping_cost>
            <customizable>0</customizable>
            <text_fields>0</text_fields>
            <uploadable_files>0</uploadable_files>
            <active>1</active>
            <redirect_type>404</redirect_type>
            <id_product_redirected>0</id_product_redirected>
            <available_for_order>1</available_for_order>
            <available_date>0000-00-00</available_date>
            <condition>new</condition>
            <show_price>1</show_price>
            <indexed>1</indexed>
            <visibility>both</visibility>
            <advanced_stock_management>0</advanced_stock_management>
            <date_add/>
            <date_upd/>
            <meta_description/>
            <meta_keywords/>
            <meta_title/>
            <link_rewrite/>
            <name><language id='1'>nazev produktu</language></name>
            <description><language id='1'>dlouhy popis</language></description>
            <description_short><language id='1'>kratky popis</language></description_short>
            <available_now><language id='1'>skladem</language></available_now>
            <available_later><language id='1'>do 9 prac. dnů</language></available_later>
            
        </product>
        </prestashop>
        XML;
        try
        {
         $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
         $xml = new SimpleXMLElement($psXML);
         $opt = array( 'resource' => 'carts' );
         $opt['postXml'] = $xml->asXML();
         $xml = $webService->add( $opt );
        }
        catch (PrestaShopWebserviceException $ex) {
            // Shows a message related to the error
            echo 'Other error: <br />' . $ex->getMessage();
        }
        
        ?>
 
But I only receive "This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request."
 
Could anybody please help me with it? How could I fix it?
 
Thank you very much
Petr
Edited by Heidy (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...