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

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 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)