Third parties - Changing "Customer Code" [code_client] via API isn't possible

Hi everyone,
I am currently trying to synchronize the customer numbers of linked third party objects to the membership number in the membership module. I would like to use the API for this, as almost a hundred entries need to be adjusted.

Unfortunately, setting a changed value for the “Customer Code” [key code_client] does not work as expected. The “Customer Code” remains unchanged despite the successful API call. For debugging purposes, I also set the third party alias with the new value for the customer number. That works.
Dolibarr Version is 20.0.1

API-Request:

curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'DOLAPIKEY: abc' -d '{ \ 
   "name_alias": "MEM2406-0002", \ 
   "code_client": "MEM2406-0002" \ 
 }' 'https://www.dolliurl.tld/api/index.php/thirdparties/10'

Response Body

{
  "module": "societe",
  "id": "10",
[...]
  "name_alias": "MEM2406-0002",
[...]
  "code_client": "CU2410-00001",   // the original value remains
[...]
  "absolute_creditnote": "0"
}

Response Code

200

Am I overlooking a configuration that needs to be set so that the value for code_client can be changed via API?

I am grateful for any advice and help.

best regards
Marcel

Hi,

at the moment it doesn’t seem possible.

This is only possible if $allowmodcodeclient parameter is set to true in the update function

And there is no way to specify this parameter with a API call

Hi @hansem,
thank you for the explanation and the reference to the specific lines of code.
It is possible to change the customer number easily via the web front end. Changed entries are validated according to system specifications, see screenshot.

Am I right in assuming that the parameter $allowmodcodeclient = 0 applies to all update calls apart from the direct change in the Third-party web frontend?
Is there a technical or organizational reason why a modification to the “client code” cannot be initiated via API call? I assume that validation is also carried out here, as in the web frontend.

I just found this issue documented on github (obviously did a bad job of searching beforehand :roll_eyes:) :
Unable to modify client_code through thirdparties rest API · Issue #30432 · Dolibarr/dolibarr · GitHub

According to eldy’s comment: “No reason to not being able to edit customer code from api, surely a bug…”

What’s wrong with setting the two parameters $allowmodcodeclient and $allowmodcodefournisseur to “1” by default in api_thirdparties.class.php? This also was suggested in “REST api thirdparties update does ignore code_compta field · Issue #18146 · Dolibarr/dolibarr · GitHub
Since the third-party object already exists as the API update-call is sent, it should not have any influence on the auto-generation of code_client or code_compta.

To verify the behavior, I adjusted the named line in api_thirdparties.class.php. The fourth parameter was set to 1.

if ($this->company->update($id, DolibarrApiAccess::$user, 1, 1, ‘’, ‘update’, 1) 0) {

After that, changing an existing “Customer Code” via API worked as expected.

Fixed, see solved issue #30432 in github

2 Likes