xbenjii / Prestan

PrestaShop Node.js API Library [UNMAINTAINED]
MIT License
20 stars 7 forks source link

edit response: String could not be parsed as XML #2

Closed sproit closed 9 years ago

sproit commented 9 years ago

My minimal example is as follows:

var id = 1;
prestan.get('products', {
    id: id
}).then(function(response) {
    prestan.edit('products', {id: id}, response);
});

I guess the error is something that comes from the webshop itself? If you need any additional info, let me know.

A snippet from the edit request (I changed the name of the website):

Requesting[put] http://blablabla.bla/api/products/28216 with options {"form":{"putXml":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<prestashop xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n \n 28216\n <id_manufacturer xlink:href=\"https://blablabla.bla/api/manufacturers/47\">47\n 0\n <id_category_default xlink:href=\"https://blablabla.bla/api/categories/1004\">1004\n \n 0\n <id_default_image xlink:href=\"https://blablabla.bla/api/images/products......

More error message: Error: [StatusCodeError: 500 - <?xml version="1.0" encoding="UTF-8"?>

xbenjii commented 9 years ago

Does indeed look like a bug. Not sure if it should be encoding it. I'll see how the PHP library does it.

xbenjii commented 9 years ago

Big oversight on my part for the sent parameters. Should be fixed in 1.0.13 and a1ec8119ca6471eb28306e54bcd9403eef61a8cc.

Do note that I've switched the parameters around for edit, so now it's

prestan.edit('products', response, {id: id});
sproit commented 9 years ago

Thanks a lot, you are great! I had to delete some product properties before the web service would even accept an unmodified product, but that could be related to the rather old version we are running.

For reference:

// bullshit hack
delete response.prestashop.product.position_in_category;
delete response.prestashop.product.manufacturer_name;
delete response.prestashop.product.quantity;
xbenjii commented 9 years ago

Seems to be like that for the PHP version too, since I don't think you can edit associations from another model.