Jump to content

PrestaShop web service on IIS7.5. Can POST, cannot PUT.


hlalumiere

Recommended Posts

I am currently working on evaluating different shopping cart platforms, and at first glance I loved PrestaShop. One of my requirements is to be able to do remote management through some web service, mostly for synchronization with another application. Once my test store was installed and setup properly on IIS7.5 (everything works, well, almost everything), I started exploring the REST service. I have the service up and running fine, I can browse it with no issue, and I can also add resources through a POST. I started with categories. I am now able to create categories with no issue whatsoever. However for the life of me I cannot get the web service to process PUT requests properly. For example, I have this category, from URL https://vmtestsrv43/api/categories/35 :

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
	<category>
		<id>
			<![CDATA[35]]>
		</id>
		<id_parent xlink:href="https://vmtestsrv43/api/categories/2">
			<![CDATA[2]]>
		</id_parent>
		<level_depth>
			<![CDATA[2]]>
		</level_depth>
		<nb_products_recursive notFilterable="true">
			<![CDATA[-1]]>
		</nb_products_recursive>
		<active>
			<![CDATA[0]]>
		</active>
		<id_shop_default>
			<![CDATA[1]]>
		</id_shop_default>
		<is_root_category>
			<![CDATA[0]]>
		</is_root_category>
		<position>
			<![CDATA[8]]>
		</position>
		<date_add>
			<![CDATA[2015-11-05 19:13:24]]>
		</date_add>
		<date_upd>
			<![CDATA[2015-11-06 10:44:34]]>
		</date_upd>
		<name>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[Seaweed and fish]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[Seafood]]>
			</language>
		</name>
		<link_rewrite>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[9]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[9]]>
			</language>
		</link_rewrite>
		<description>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[]]>
			</language>
		</description>
		<meta_title>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[Seaweed and fish]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[Seafood]]>
			</language>
		</meta_title>
		<meta_description>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[]]>
			</language>
		</meta_description>
		<meta_keywords>
			<language id="1" xlink:href="https://vmtestsrv43/api/languages/1">
				<![CDATA[]]>
			</language>
			<language id="2" xlink:href="https://vmtestsrv43/api/languages/2">
				<![CDATA[]]>
			</language>
		</meta_keywords>
		<associations>
			<categories nodeType="category" api="categories"/>
			<products nodeType="product" api="products"/>
		</associations>
	</category>
</prestashop>

Now notice the active=0. I want to set this category to active=1. So, I take this XML, change its active value to 1, create a new PUT request, set its data length, its type to "text/xml", and fill its data:

        Dim client = New PrestaRest.Client With {.BaseUri = New Uri("http://vmtestsrv43/api"),
                                                 .ApiKey = "IKAE958PQ2BWYSUIDU84A4QNA5ZNCL5D"}

        Dim xml = client.GetResource("/categories/35")

        xml...<active>.First.Value = 1

        client.UpdateResource("/categories/35", xml)


    Public Function UpdateResource(ByVal resPath As String, ByVal resData As XDocument) As Boolean
        If resData Is Nothing Then Return False

        Dim xml = resData.ToString

        Dim request = WebRequest.Create(BaseUri.ToString & resPath)
        With request
            .Credentials = New NetworkCredential(ApiKey, "")
            .Method = "PUT"
            .ContentType = "text/xml"
            .ContentLength = xml.Length
        End With

        Using reqStream = request.GetRequestStream()
            reqStream.Write(Encoding.UTF8.GetBytes(xml), 0, xml.Length)
        End Using

        Dim response As HttpWebResponse = Nothing
        Try
            response = request.GetResponse()
        Catch ex As Exception
        End Try

        Return ((response IsNot Nothing) AndAlso (response.StatusDescription.ToUpper = "OK"))

    End Function

Now when I send the request, I get a HTTP 200 OK response. But it has done absolutely nothing. No value has changed (not even the update date), and monitoring the MySQL database, no query (AT ALL) was executed while updating.

 

How is the update supposed to work, and what exactly am I missing?

 

This is my setup:

PrestaShop 1.6.1

IIS 7.5 on Windows 7

PHP 5.3 (configured per your recommendations)

URL Rewrite 2.0 IIS extension with proper rewrite rules

MySQL 5.6

 

Thank you,

 

Hugo Lalumiere

Edited by hlalumiere (see edit history)
Link to comment
Share on other sites

I would appreciate an answer on this please. I contemplated bypassing it and just writing a WCF service to query MySQL, but your database model isn't a lot of fun to work with. It's tidy, but there are way too many tables for everything and would take a while to get the data model going, I would like to avoid it...

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