Dolibarr: Rest PUT not working

Created on 10 Aug 2020  Â·  8Comments  Â·  Source: Dolibarr/dolibarr

Instructions

This is a template to help you report good issues. You may use Github Markdown syntax to format your issue report.
Please:

  • replace the bracket enclosed texts with meaningful information
  • remove any unused sub-section

Bug

[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.

Environment

  • Version: [12.0.1]
  • DockerFile [https://github.com/Monogramm/docker-dolibarr/blob/master/images/12.0/php7.2-apache-amd64/Dockerfile]

Expected and actual behavior

An update to the data via RestApi

Steps to reproduce the behavior

  1. Install Dolibarr via dockerFile: https://github.com/Monogramm/docker-dolibarr/blob/master/images/12.0/php7.2-apache-amd64/Dockerfile
  2. create contact via rest api
  3. update contact via rest api

Attached files (Screenshots, screencasts, dolibarr.log, debugging informations…)

[Files]
image

Bug

All 8 comments

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:

  1. I create a user in dolibarr via the POST
  2. I query the user
    GET:
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]"
}
  1. I update the user's first name
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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdoursenaud picture rdoursenaud  Â·  4Comments

QuentinPetel picture QuentinPetel  Â·  5Comments

Sylvain089 picture Sylvain089  Â·  4Comments

gnovaro picture gnovaro  Â·  5Comments

jrgonzalezrios picture jrgonzalezrios  Â·  4Comments