dsfdsf46465 2013-05-14 17:58
浏览 85
已采纳

prestashop通过url webservice api创建和更新资源

I (unfortunately) have to write a client application as front end to a prestashop powered web site. I'd need to perform all CRUD operations on resources via url webservice and I'm stuck on create and update. I was very surprise to find out how few examples are available on the web since prestashop is supposed to be a widely used cms. However, till now I came to:

GET http://www.myshop.com/api/myresource/id

to get xml for resource with given id or

GET http://www.myshop.com/api/myresource/?display=full&filter[field]=[value]

to filter results. I'm writing this just because I had to struggle with google to achieve this information, this filters stuff might help somebody in the future.

DELETE http://www.myshop.com/api/myresource/id

to delete a resource (I suppose filters work here too, but didn't try so far)

now, does somebody know how create and update resources? I tried

POST/PUT http://www.myshop.com/api/myresource/

giving couples of field - value in http request parameters with no luck, I'm getting internal server error. No, I have no direct access to the server so I don't know what error is thrown and I hope it can be solved without bother website maintainers, I'd like to save my ammunitions.

The only useful resource I found on the web is this one, I also looked among other question on SO and suggested links in those question was of no help.

  • 写回答

3条回答 默认 最新

  • doubi4435 2013-05-16 07:20
    关注

    If you edit your config/config.inc.php and add the following you will be able to see the errors in the Response (error) (1by1 which is very frustrating when you are trying to work out why create fails). Remember to comment out the line when you are done.

    /*DEBUGGING ON*/
    ini_set('display_errors', 'on'); 
    

    You also need to make sure that you prepend the data in your POST/PUT operation with xml=<prestashop>......</prestashop> (I am using C# for my Client so this may not be required with PHP)

    if you are using the ?schema=synopsis to get your blank one, make sure you go through any elements in the XML that are in there as placeholders and remove them.. Your (products) for example will be broken but kind of work if you don't.

    I also added to my code that in the initial pass of the XML it completely walks the tree, looking for anything with the attribute not_filterable and removes those nodes (once again not much documentation available to know if this is the right thing to do).

    EDIT: 1 other thing of note in and of the Language based elements, make sure you are using CDATA for the elements.

    I have just succeeded with Generating my Products via performing this so I hope it's of help. I am yet to perform an Update of an existing.

    UPDATE: I have since updated to 1.5.4.1 of Prestashop and started updating resource Products in my case

    Update Resource

    URI: http://site/api/products/1

    Use Method = "PUT"

    content type = "text/xml"

    Make sure that you remove any elements that have 'not_filterable' attribute set. (I don't understand why, but it doesn't work if you don't)

    Delete Resource

    URI: http://site/api/products/1

    Use Method = "DELETE"

    content type = "application/x-www-form-urlencoded"

    I found that you don't need any body so you can set ContentLength to 0 it seems. and probaly don't really need content type to be set either, but it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?