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.52k stars 2.81k forks source link

REST API create thirdparty as customer fail with error ErrorCustomerCodeRequired #10100

Closed MatthieuTexier closed 4 years ago

MatthieuTexier commented 6 years ago

When creating a thirdparty setting customer to "1", server returns an error ErrorCustomerCodeRequired but customer codes are created by the server.

sample command to reproduce: curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'DOLAPIKEY: XXXXXXXXXXX' -d '{ "client": "1", "name": "TEST" }' 'http://XXXXXXX/dolibarr/api/index.php/thirdparties'

atm-florian commented 6 years ago

IF you setup dolibarr (configuration->thirdparties) with a required customer code, it mean you should give it to the API when you set to customer status

eldy commented 6 years ago

You can also set the value to 'auto' when calling API.

MatthieuTexier commented 6 years ago

IF you setup dolibarr (configuration->thirdparties) with a required customer code, it mean you should give it to the API when you set to customer status

The setup is Monkey mode, codes are generated by Dolibarr, I don't want to create one by myself.

MatthieuTexier commented 6 years ago

You can also set the value o 'auto' when calling API.

Thank you Laurent, it works for me too when setting "client" to "1" and "code_client" to "auto"

MatthieuTexier commented 5 years ago

worked on 7.0.3 but not on 8.0.3

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'DOLAPIKEY: XXXXXXXXXXXXXX' -d '{ "client": "1", "client_code": "auto", "name": "customer" }' 'http://mon_serveur/dolibarr/api/index.php/thirdparties'

fails with error { "error": { "0": null, "1": "ErrorCustomerCodeRequired", "code": 500, "message": "Internal Server Error: Error creating thirdparty" } }

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 1 year with no activity. If this is a bug, please comment to confirm it is still present on latest stable version. if this is a feature request, please comment to notify the request is still relevant and not yet covered by latest stable version. Without comment, this issue will be closed automatically by stale bot in 15 days.

hichxm commented 2 years ago

In the source code, you need to set '-1' for automatic assignment of client code_client. The same for code_fournisseur

https://github.com/Dolibarr/dolibarr/blob/1b5eb2de22ccee5377549a219d0448f1e3026117/htdocs/societe/class/societe.class.php#L862-L869

The curl request will be like this :

curl -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'DOLAPIKEY: XXXXXXXXXXXXXX' \
-d '{
    "client": "1",
    "client_code": "-1",
    "name": "customer"
}' 'http://mon_serveur/dolibarr/api/index.php/thirdparties'
GenZai commented 3 months ago

I'm on version 13.0.5

For me the key is code_client and not client_code