Error when inserting Timesheet using the API

When we try to insert a Timesheet record using the rest-api we get a mandatory field error.
Below is the exact error.

{{"_server_messages":"["{\“message\”: \“Error: Data missing in table: Time Sheets\”}"]",“exc”:"[“Traceback (most recent call last):\n File \”/home/benjamien/frappe-bench/apps/frappe/frappe/app.py\", line 60, in application\n response = frappe.api.handle()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/api.py\", line 127, in handle\n \“data\”: frappe.get_doc(data).insert().as_dict()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 230, in insert\n self._validate()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 460, in _validate\n self._validate_mandatory()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 740, in _validate_mandatory\n name=self.name))\nfrappe.exceptions.MandatoryError: [Timesheet, TS-2020-00001]: time_logs\n"]"}}

The json data looks to be correct and contains the time_logs. See below.
What could be the problem ? Is this a bug ?

{{“data”:{“title”:“HR-EMP-00002”,“time_logs”:[{“project”:"GVE ",“activity_type”:“Uitvoering”,“task”:“TASK-2019-00002”,“from_time”:“2020-02-01 12:59”}],“employee”:“HR-EMP-00002”,“start_date”:“2020-02-01”}}}

Anyone ? I’m really stuck.

You should be able to create Timesheet if these fields are present. These are the mandatory fields except project and task.

{"company": "XYZ", "employee": "HR-EMP-00002", "time_logs": [{ "activity_type": "Research", "from_time": "2020-01-03 15:33:00", "company": "XYZ", "project": "ABC Project", "task": "TASK-2019-00001" }] }

This is my json string

{{“data”:{“company”:“BETOWARE BV”,“title”:“HR-EMP-00002”,“employee”:“HR-EMP-00002”,“start_date”:“2020-03-01”,“time_logs”:[{“project”:“GVE”,“activity_type”:“Uitvoering”,“task”:“TASK-2019-00002”,“from_time”:“2020-03-01 11:35”,“company”:“BETOWARE BV” }]}}}

I think this includes all mandatory fields.
But I keep getting the same response.

{{“exc”:"[“Traceback (most recent call last):\n File \”/home/benjamien/frappe-bench/apps/frappe/frappe/app.py\", line 60, in application\n response = frappe.api.handle()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/api.py\", line 127, in handle\n \“data\”: frappe.get_doc(data).insert().as_dict()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 230, in insert\n self._validate()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 460, in _validate\n self._validate_mandatory()\n File \"/home/benjamien/frappe-bench/apps/frappe/frappe/model/document.py\", line 740, in _validate_mandatory\n name=self.name))\nfrappe.exceptions.MandatoryError: [Timesheet, TS-2020-00002]: time_logs\n"]","_server_messages":"["{\“message\”: \“Error: Data missing in table: Time Sheets\”}"]"}}

Can anyone tell me why this isn’t working ?

Is this a bug or am I doing something wrong ?

I cannot get this to work, so I created a whitelist method that does the same thing.
That works well.

Hello,

I’m getting the same issue, can you please explain how did you resolved it?

Thank you.

I’m getting this error:

\"/opt/bench/erpnext/apps/erpnext/erpnext/projects/doctype/timesheet/timesheet.py\", line 130, in validate_dates\n if data.from_time and data.to_time and time_diff_in_hours(data.to_time, data.from_time) < 0:\nAttributeError: ‘str’ object has no attribute ‘from_time’\n"]"}

this is the time_logs code:

[{"owner": "Administrator","activity_type": "Communications","from_time": "2022-03-25 23:50:10","hours": 1}]