Jump to content

Web Services problem z dodaniem nowego adresu klienta


avatarusswtor

Recommended Posts

witam
Chce zrobić sobie importera zamówień z Allegro do Presta.
Mam jednak problem z tym API
Korzystam z presty w wersji 1.6.0.14 i pliku PSWebServiceLibrary (ten plik wspiera preste do wersji 1.6.0.11, ale zmieniłem na sztywno żeby działał z wersją 1.6.0.14, nie wiem czy to nie powód błędu).
Ale do rzeczy używam tego kodu aby dodać nowy adres:
 


//////////////////////////////////////////////////////////////////////

                        //2: Tworzenie ADDRESS

                        /////////////////////////////////////////////////////////////////////

                        try

                        {

                            // Getting the empty XML document to send back completed

                            unset($xml);

                            unset($resources);

                            unset($webService);

                            unset($infos);

                            $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

                            $xml = $webService->get( array( 'url' => 'http://raj-dla-ogrodu.pl/api/addresses?schema=blank' ) );

                            $resources = $xml->children()->children();



                            // Information about the customer to create



                            $infos = array(

                                'id_customer' => 50,

                                'id_country' => '14',

                                'id_state' => '0',

                                'alias' => 'z Allegro',

                                'id_manufacturer' => '0',

                                'id_supplier' => '0',

                                'id_warehouse' => '0',

                                'deleted' => '0',

                                'lastname' => 'Tajny',

                                'firstname' => 'Klient',

                                'address1' => 'Allegro',

                                'address2' => '666',

                                'postcode' => '66-666',

                                'city' => 'Hell',

                                'phone_mobile' => '123456789',

                                'phone' => '123456789',



                                );



                            // Completing the XML document

                            foreach ($resources as $nodeKey => $node)

                            {

                                $resources->$nodeKey = $infos[$nodeKey];

                            }



                            // Send !

                            $opt = array('resource' => 'customers');



                             $opt['postXml'] = $xml->asXML();



                             $xml = $webService->add($opt);

                             $result = $xml->children()->children();

                            $id_adresu = $result->{'id'};

                             echo '[br /]Adres został utworzony![br /]';

                             echo '[br /]ID adresu:'.$id_adresu;

                             echo '[br /]ID klienta: '.$id_klienta;

                        }

                        catch (PrestaShopWebserviceException $ex)

                        {

                            // Here we are dealing with errors

                            $trace = $ex->getTrace();

                            if ($trace[0]['args'][0] == 404) echo 'Bad ID';

                            else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';

                            else echo '[br /]Other error[br /]'.$ex->getMessage();

                        }

Po uruchomieniu wywala błąd:

HTTP REQUEST HEADER

GET /api/addresses?schema=blank HTTP/1.1
Authorization: Basic QVhWQ1QyUUxORVA0WTgyVkVMNzJLNE0yNlE0WjlRNVE6
Host: raj-dla-ogrodu.pl
Accept: */*

HTTP RESPONSE HEADER

HTTP/1.1 200 OK
Access-Time: 1428168595
X-Powered-By: PrestaShop Webservice
PSWS-Version: 1.6.0.14
Content-Type: text/xml;charset=utf-8
Execution-Time: 0.006
Content-Sha1: 5e1fba3585eb5216941c5f157ed1c17732e510aa
Content-Length: 659
Date: Sat, 04 Apr 2015 17:29:55 GMT
Server: LiteSpeed
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Vary: User-Agent

RETURN HTTP BODY

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<address>
	<id></id>
	<id_customer></id_customer>
	<id_manufacturer></id_manufacturer>
	<id_supplier></id_supplier>
	<id_warehouse></id_warehouse>
	<id_country></id_country>
	<id_state></id_state>
	<alias></alias>
	<company></company>
	<lastname></lastname>
	<firstname></firstname>
	<vat_number></vat_number>
	<address1></address1>
	<address2></address2>
	<postcode></postcode>
	<city></city>
	<other></other>
	<phone></phone>
	<phone_mobile></phone_mobile>
	<dni></dni>
	<deleted></deleted>
	<date_add></date_add>
	<date_upd></date_upd>
</address>
</prestashop>

HTTP REQUEST HEADER

POST //api/customers HTTP/1.1
Authorization: Basic QVhWQ1QyUUxORVA0WTgyVkVMNzJLNE0yNlE0WjlRNVE6
Host: raj-dla-ogrodu.pl
Accept: */*
Content-Length: 742
Content-Type: application/x-www-form-urlencoded

HTTP RESPONSE HEADER

HTTP/1.1 400 Bad Request
Access-Time: 1428168595
X-Powered-By: PrestaShop Webservice
PSWS-Version: 1.6.0.14
Content-Type: text/xml;charset=utf-8
Execution-Time: 0.002
Content-Length: 241
Date: Sat, 04 Apr 2015 17:29:55 GMT
Server: LiteSpeed
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Vary: User-Agent

XML SENT

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<address>
	<id></id>
	<id_customer>55</id_customer>
	<id_manufacturer>0</id_manufacturer>
	<id_supplier>0</id_supplier>
	<id_warehouse>0</id_warehouse>
	<id_country>14</id_country>
	<id_state>0</id_state>
	<alias>Klient Allegro</alias>
	<company></company>
	<lastname>test</lastname>
	<firstname>test</firstname>
	<vat_number></vat_number>
	<address1>test</address1>
	<address2>444</address2>
	<postcode>55-555</postcode>
	<city>wadowice</city>
	<other></other>
	<phone>55555555</phone>
	<phone_mobile>5555555</phone_mobile>
	<dni></dni>
	<deleted>0</deleted>
	<date_add></date_add>
	<date_upd></date_upd>
</address>
</prestashop>

RETURN HTTP BODY

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>


Other error
This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request. 

Macie pomysł co jest nie tak?

Edited by avatarusswtor (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...