Jump to content

Prestashop webservice forbids inserting ID`s. How to bypass it?


bendzius

Recommended Posts

This is what i get after i try to insert new category, using web service:

RETURN HTTP BODY<?xml version="1.0" encoding="UTF-8"?><prestashop xmlns:xlink="http://www.w3.org/1999/xlink"><errors><error><code><![CDATA[91]]></code><message><![CDATA[id is forbidden when adding a new resource]]></message></error></errors></prestashop>
this is the resources im using:
unset($resources ->position);unset($resources ->date_add);unset($resources ->date_upd);//unset($resources ->id_parent); //if unset category will be root. If set it must have id existing parent category!unset($resources ->level_depth);unset($resources ->nb_products_recursive);$resources ->id = '777';$resources ->id_parent = '118';$resources ->name ->language[0][0] = 'New Category Bla Bla';$resources ->link_rewrite->language[0][0] = 'New-category';$resources ->active = 1;$resources ->id_shop_default = 1;$resources ->is_root_category = 0;

Is where a way to bypass this? I really need to insert my own ID`s :)

 

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

ID fields are based on AUTO_INCREMENT attribute

you can't add there own id because id is generated automatically while you adding new rows to the table.

 

 

The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows.
No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. 
Link to comment
Share on other sites

  • 5 months later...
You can modify the API of webservice.

You must comment this lines of file WebserviceRequest.php

 

/*elseif ($this->method == 'POST' && count($ids) > 0)

{

$this->setError(400, 'id is forbidden when adding a new resource', 91);

return false;

}*/

 

Edu Gasser.

Link to comment
Share on other sites

  • 1 year later...

Hi, Found the solution. Please download these files and just upload it in the corresponding path.

Then when inserting instead of id, put <id_product> along with other required parameters (name, price and link_rewrite) and then check the response, you would get 201 Created.

However, take a backup of your database and files for safety.

Now, you will be able to insert product id of your own in webservice. Enjoy!

Mark this is solved if solved.:D

Product.php

WebserviceRequest.php

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

  • 11 months later...

Hi, Found the solution. Please download these files and just upload it in the corresponding path.

Then when inserting instead of id, put <id_product> along with other required parameters (name, price and link_rewrite) and then check the response, you would get 201 Created.

However, take a backup of your database and files for safety.

Now, you will be able to insert product id of your own in webservice. Enjoy!

Mark this is solved if solved. :D

 

Anything less extreme? I've been trying the method @edugasser commented and it didn't work.

 

I also tried to change the auto_increment property of the id_product column, but it didn't work either.

 

Any ideas?

 

Kindest regards,

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