Jump to content

test PUT request


Matt_

Recommended Posts

I am unable to successfully make a PUT request using Prestashop's webservice.  GET, POST and DELETE work fine.

Here is the output from debug on my modified CRUD (like the Prestashop examples https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=2ahUKEwi_lc6Z6aHeAhVM64MKHSnTCaQQFjADegQIAhAB&url=http%3A%2F%2Fdoc.prestashop.com%2Fdownload%2Fattachments%2F327702%2F2-Update.php&usg=AOvVaw0GUs_SLEnNe8nxGvoQzIB-)

HTTP REQUEST HEADER
GET /api/customers/23 HTTP/1.1
Authorization: Basic VVVYWExHM1pTRExGSTg2SkMyVVNCOTE5VUhFUVU3QVA6
Host: example.com
Accept: */*

HTTP RESPONSE HEADER
HTTP/1.1 200 OK
Date: Thu, 25 Oct 2018 14:32:15 GMT
Content-Type: text/xml;charset=utf-8
Content-Length: 1876
Connection: keep-alive
Keep-Alive: timeout=30
Server: Apache
Access-Time: 1540477935
X-Powered-By: PrestaShop Webservice
PSWS-Version: 1.7.3.1
Execution-Time: 0.021
Content-Sha1: cbeb8d1c1ba601f49651a99d8753d60ed49e1761
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer>
	<id><![CDATA[23]]></id>
	<id_default_group xlink:href="http://example.com/api/groups/1"><![CDATA[1]]></id_default_group>
	<id_lang xlink:href="http://example.com/api/languages/1"><![CDATA[1]]></id_lang>
	<newsletter_date_add><![CDATA[0000-00-00 00:00:00]]></newsletter_date_add>
	<ip_registration_newsletter></ip_registration_newsletter>
	<last_passwd_gen><![CDATA[2018-10-05 06:15:45]]></last_passwd_gen>
	<secure_key><![CDATA[fa9345d70e28bffb4182397ea63f5176]]></secure_key>
	<deleted><![CDATA[0]]></deleted>
	<passwd><![CDATA[$2y$10$J7aqIAyfMdQjZqSYAJwElOJIasNKCmSnPmzJGRjpPxHw2k49UJfJe]]></passwd>
	<lastname><![CDATA[dd]]></lastname>
	<firstname><![CDATA[aa]]></firstname>
	<email><![CDATA[[email protected]]]></email>
	<id_gender><![CDATA[1]]></id_gender>
	<birthday><![CDATA[0000-00-00]]></birthday>
	<newsletter><![CDATA[0]]></newsletter>
	<optin><![CDATA[0]]></optin>
	<website></website>
	<company></company>
	<siret></siret>
	<ape></ape>
	<outstanding_allow_amount><![CDATA[0.000000]]></outstanding_allow_amount>
	<show_public_prices><![CDATA[1]]></show_public_prices>
	<id_risk><![CDATA[0]]></id_risk>
	<max_payment_days><![CDATA[0]]></max_payment_days>
	<active><![CDATA[1]]></active>
	<note></note>
	<is_guest><![CDATA[0]]></is_guest>
	<id_shop><![CDATA[1]]></id_shop>
	<id_shop_group><![CDATA[1]]></id_shop_group>
	<date_add><![CDATA[2018-10-05 12:15:45]]></date_add>
	<date_upd><![CDATA[2018-10-05 12:15:45]]></date_upd>
	<reset_password_token></reset_password_token>
	<reset_password_validity><![CDATA[0000-00-00 00:00:00]]></reset_password_validity>
<associations>
<groups nodeType="group" api="groups">
	<group xlink:href="http://example.com/api/groups/1">
	<id><![CDATA[1]]></id>
	</group>
</groups>
</associations>
</customer>
</prestashop>
HTTP REQUEST HEADER
PUT /api/customers/23 HTTP/1.1
Authorization: Basic VVVYWExHM1pTRExGSTg2SkMyVVNCOTE5VUhFUVU3QVA6
Host: example.com
Accept: */*
Content-Length: 1400
Content-Type: application/x-www-form-urlencoded

HTTP RESPONSE HEADER
HTTP/1.1 500 Internal Server Error
Date: Thu, 25 Oct 2018 14:32:15 GMT
Content-Type: text/xml;charset=utf-8
Content-Length: 282
Connection: keep-alive
Keep-Alive: timeout=30
Server: Apache
Access-Time: 1540477935
X-Powered-By: PrestaShop Webservice
PSWS-Version: 1.7.3.1
Execution-Time: 0.017
XML SENT
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer>
	<id>23</id>
	<id_default_group xlink:href="http://example.com/api/groups/1">1</id_default_group>
	<id_lang xlink:href="http://example.com/api/languages/1">1</id_lang>
	<newsletter_date_add>0000-00-00 00:00:00</newsletter_date_add>
	<ip_registration_newsletter></ip_registration_newsletter>
	<last_passwd_gen>2018-10-05 06:15:45</last_passwd_gen>
	<secure_key>fa9345d70e28bffb4182397ea63f5176</secure_key>
	<deleted>0</deleted>
	<passwd>kB670xK3sO</passwd>
	<lastname>Manager</lastname>
	<firstname>Yuma</firstname>
	<email>[email protected]</email>
	<id_gender>1</id_gender>
	<birthday>0000-00-00</birthday>
	<newsletter>0</newsletter>
	<optin>0</optin>
	<website></website>
	<company>qwerty</company>
	<siret></siret>
	<ape></ape>
	<outstanding_allow_amount>0.000000</outstanding_allow_amount>
	<show_public_prices>1</show_public_prices>
	<id_risk>0</id_risk>
	<max_payment_days>0</max_payment_days>
	<active>1</active>
	<note></note>
	<is_guest>0</is_guest>
	<id_shop>1</id_shop>
	<id_shop_group>1</id_shop_group>
	<date_add>2018-10-05 12:15:45</date_add>
	<date_upd>2018-10-05 12:15:45</date_upd>
	<reset_password_token></reset_password_token>
	<reset_password_validity>0000-00-00 00:00:00</reset_password_validity>
<associations></associations>
</customer>
</prestashop>
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[127]]></code>
<message><![CDATA[XML error : String could not be parsed as XML
XML length : 0
Original XML : ]]></message>
</error>
</errors>
</prestashop>

Other error
This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.

 

Summary: It sends a GET request, for the supplied customer, and displays it in a form. When the UPDATE button is clicked, it issues a PUT request of the entered data.

Can somebody test this on their installation to determine whether I'm doing it correctly. (You'll need to create an API webservice key [with all permissions] and a test customer [that can deleted later].   Then update that customer with some random data.  Please share the debug output - remember to remove the Host or Authorization.)

(Attached:  CRUD Tutorial - Update example)

2-Update.php

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...