This is a template to help you report good issues. You may use Github Markdown syntax to format your issue report.
Please:
[Short description]
I am currently trying to use dolibarr over REST, but it seems that the PUT method does not work :confused:
I've tried this now with several properties, but either I'm doing something wrong or it's a bug.
An update to the data via RestApi
[Files]

Could you post the data you sent here so I can try reproducing?
sorry, I was only taking a screenshot of the query.
curl --location --request PUT 'localhost:8080/api/index.php/contacts/1' \
--header 'Content-Type: application/json' \
--data-raw '{
"mail":"[email protected]"
}'
I also get an answer, but in the answer the propertie is not updated. Also with a later "GET" on the same ID I get the old record back. The same applies for "lastname", "firstname" etc
Are you sending your Key token also in the header?
Is the code available? Please post your code. You should redact your token of course.
Yes I also use the header "DOLAPIKEY". Of course I can also send you the (nodeJs) code. But the update call does not work in a "CURL" command or via the "Postman" program, so it shouldn't be the code.
var request = require('request');
var options = {
'method': 'PUT',
'url': 'http://localhost:8080/api/index.php/contacts/15',
'headers': {
'DOLAPIKEY': 'mySecretKey',
'Content-Type': 'application/json'
},
body: JSON.stringify({"firstname":"Mike"})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
I also tried curl and I got the same result:
curl --location --request GET 'http://localhost:8080/api/index.php/contacts/15' \
--header 'DOLAPIKEY: mySecretKey'
result:
...
"name": null,
"lastname": "Wayne",
"firstname": "John",
"date_creation": 1597056331,
"date_validation": null,
"date_modification": 1597056482,
"entity": "1",
"socname": null,
"mail": "[email protected]"
}
curl --location --request PUT 'http://localhost:8080/api/index.php/contacts/15' \
--header 'DOLAPIKEY: mySecretKey' \
--header 'Content-Type: application/json' \
--data-raw '{"firstname":"Mike"}'
result from PUT and GET is the same:
...
"name": null,
"lastname": "Wayne",
"firstname": "John",
"date_creation": 1597056331,
"date_validation": null,
"date_modification": 1597056482,
"entity": "1",
"socname": null,
"mail": "[email protected]"
}
I hope this helps, thanks for the work!
I found the cause of your problem I think.
https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/societe/class/societe.class.php#L333
Its called email in Dolibarr internally and there is no mapping in the api class:
https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/societe/class/api_contacts.class.php#L247
Why did you think it was called mail?
The post apis are really missing proper examples and documentation I think. Please submit a pull request with a working example to add to the api class once you have figured it out.
Why did you think it was called mail?
because the api replies with the property mail. But the problem also exists with other fields like firstname.
https://github.com/Dolibarr/dolibarr/issues/14446#issuecomment-672835624
The post apis are really missing proper examples and documentation I think. Please submit a pull request with a working example to add to the api class once you have figured it out.
The problem is not the POST method that works, it is the PUT method.
POST creates the entry as I expect it to be, but when I want to change it (PUT), it doesn't get updated.
Ok. Then its s bug I think. Can you test with email?