Update products via POST

Hi All,
I have some 600 products that i need to update the price every week. Is there a way to use post to update the price?

I have looked in the documentation but nothing is shown.

Thanks in advanced

Hi Shaggy,

What do you mean “via POST” ?
What kind of update do you have to perform ? What type of price (buying/selling) ? What are your starting data ? Are they in tabulated format ?
You should first have a look at the tools/imports capabilities. Then search the dolistore for modules that could provide such functionality (although I am not sure there are any). Then eventually consider using the API, but that would require development on your side.
In general, for these intensive tasks, that for sure can be somewhat automated, you would probably benefit from contracting with a Dolibarr partner.
Regards,
Marc

Hi Marc,
If your not sure what POST method is then please don’t answer. Post is a method used by the API to upload data.

I script in python so making a program is no task but the issue is there is no documentation on the use of the API that I could find.

I could wake up once a month click to open my email spend 30 -60mins fixing the data to suit dolibars import method and then let it run. As you can see very time consuming.

Using python I can import my data and upload using the API.

With this https://wiki.dolibarr.org/index.php/Module_Web_Services_API_REST_(developer), I managed to write my own APIs…

Thanks @Simicar,

I have had a look and have progressed but i get the following error

curl -X GET --header ‘Accept: text/html’ --header 'DOLAPIKEY: KEY HAS BEEN REMOVED ’ ‘http://ahfcomputing.com/accounting/api/index.php/products?sortfield=t.ref&sortorder=ASC&limit=100

Request URL

http://ahfcomputing.com/accounting/api/index.php/products?sortfield=t.ref&sortorder=ASC&limit=100

Response Body

API not found (failed to include API file)

Response Code

501

Response Headers

{
“cache-control”: “no-store, no-cache, must-revalidate”,
“connection”: “keep-alive”,
“content-type”: “text/html; charset=UTF-8”,
“date”: “Wed, 19 Feb 2020 06:29:30 GMT”,
“expires”: “Thu, 19 Nov 1981 08:52:00 GMT”,
“pragma”: “no-cache”,
“server”: “nginx”,
“transfer-encoding”: “chunked”,
“x-powered-by”: “PHP/7.3.13”
}

cheers

I t says it did not find the products api, which is strange. I guess you went through the api explorer. Does it work correctly there ?
Regards,
Marc

This output was done via the API explorer…

I’ll try via python later but I have a feeling it will be the same… I’ll try a new API key just in case

Yes, it should first work through the api explorer. By the way, the explorer should list you all available apis. If products is not found, you will have to check the htdocs/products/class/api_products.class.php. If it is not present, you’d have to check your installation…
Regards,
Marc

So that file is present and comparing to github looks the same. Any other ideas? i get the same error when using python.

Hi Shaggy, it is not clear to me whether you managed to get the api explorer working when providing your apikey. This is really first step to achieve. Afterwards, scripting should be straightforward.
Maybe you could provide some screenshots ?
To help you diagnose the problem, you may have a look at this post (https://www.dolibarr.fr/forum/t/documentation-api-rest/25139) dealing with deprecated api files creating some mess after upgrade. You may also check this one https://www.dolibarr.fr/forum/t/probleme-api/30511/5 dealing with server configuration.
Regards,
Marc

Hi,
No i didn’t manage to get it woking in the API explorer.

So i have just upgraded to 11.0.1 and now its worse. I cant even get the categories to load

Hi shaggy, it looks like your api key was not recognised (The orange Invalid message). Maybe you could regenerate one and retry. Once you get “logged in” you will access the various apis.
Regards,
Marc

So I have regenerated the key found in user and groups-> user -> modify then API key.

Then head to modules -> rest API.
The first link that contains user and password I get a 404 error when adding username and password (even created a new user).

Went to phpmyadmin to change user API key to null to then reset. After all this still same output

Thanks for your help thus far

For the first try, could you check you access logs ? Everything should go through YOURINSTANCEURL/api/index.php so I can’t see why you have 404 here. Some tuning may have to be done on your server configuration (is it nginx ? apache ?).
For the second approach (setting the APIKEY to null), I thing this not a good idea as the system uses this value to “connect” to the right user and in fact setting this value to null is removing the ability to that user to use the API functionality…
Regards,
Marc

Hi Marc,
Im using Apache. I i type in YOURINSTANCEURL/api/index.php i get a 404. I have checked and the file does exist.

Setting the API key to NULL just removes the current key. When a new one is issued the NULL is removed just like a new user. I did this to make sure 100% the API key was cleared.

Go into the setup of module API REST.
You should get the URL of explorer. Check into your conf.php file that the entry $dolibarr_main_url_root is matching your Dolibarr root url
The url of the explorer should be URLintheconffile/api/index.php/explorer

Also you should not have any specific setup in your apache virtual host (only the virtual host of your dolibarr, on the dolibarr root dir is required)