Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.07k stars 2.67k forks source link

POST thirdparties documentation is not accurate #29343

Open utarasama opened 2 months ago

utarasama commented 2 months ago

Bug

I tried to create a thirdparty throught the POST request /thirdparties. The swagger suggested me to fill the request body with this type of data :

{
  "request_data": [
    "string"
  ]
}

Since I want to provide multiple informations, I used to do it like this with other APIs :

{
  "name" : "Cool company",
  "some_data" : {
    "money" : 10000,
    "address" : "Everywhere around the world"
  }
}

I get a 400 error "missing name field" error when I try to respect the swagger recommendations. However, when I tried like I used to do, the request worked successfully. I was able to create a thirdparty.

So, what I request from this issue is to edit the swagger documentation to tell the user something like "hey! Use this data formalism". Moreover, I checked the api_thirdparties.class.php file and can't understand what is the purpose of the $request_data variable, since I can just forget it to make my request work.

Furthermore, I didn't check but I think this problem might also be in the documentation of other requests.

Dolibarr Version

19.0.1

Environment PHP

8.2.7

Environment Database

PostgreSQL 16.2

Steps to reproduce the behavior and expected behavior

Just try to put your thirdparty data into the request_data JSON string array, and nothing elsewhere. You will get the error.

To not get it, forget the request_data key and just use the formalism from the GET /thirdparties request. You must specify at least the thirdparty's name to make it work.

Attached files

No response

JonBendtsen commented 2 months ago

@utarasama Inside Dolibarr, follow this trail Home, Admin tools, About Dolibarr - and you can find all the version information.

utarasama commented 2 months ago

@JonBendtsen Thanks!! I edited my initial message with the missing informations.

JonBendtsen commented 2 months ago

I sort of see what you mean with regards to request_data.

When I developed my system for dance class registrations and I also create thirdparties what I did was use the regular Dolibarr GUI to make some thirdparties, and then I used GET thirdparties to get some json which I then modified a little and sent back to Dolibarr with a POST until I understood the correlation between the input json and the results I got inside Dolibarr GUI was precisely as I expected.

image