Rest API for Employee Checkin

Hi Community,
I was trying to create a POST request for Employee Checkin but encountered the following :
frappe.exceptions.ValidationError: No Employee found for the given employee field value. ‘attendance_device_id’: ‘HR-EMP-00005’
PS: I do have employee ‘HR-EMP-00005’ in my system.
Screenshot%20from%202020-07-23%2013-30-19

Am i missing out something??

I tried posting data using Postman on to
https://stsdemo.erpnext.com/api/method/erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field

In headers:

Authorization:token access key:secret key

Status received:

417 EXPECTATION FAILED

Traceback:
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/app.py”, line 64, in application
response = frappe.api.handle()
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/api.py”, line 58, in handle
return frappe.handler.handle()
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/handler.py”, line 30, in handle
data = execute_cmd(cmd)
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/handler.py”, line 69, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/init.py”, line 1085, in call
return fn(*args, **newargs)
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/erpnext/erpnext/hr/doctype/employee_checkin/employee_checkin.py”, line 61, in add_log_based_on_employee_field
frappe.throw(_(“No Employee found for the given employee field value. ‘{}’: {}”).format(employee_fieldname,employee_field_value))
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/init.py”, line 396, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’, is_minimizable=is_minimizable)
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/init.py”, line 375, in msgprint
_raise_exception()
File “/home/frappe/benches/bench-version-13-2020-07-02/apps/frappe/frappe/init.py”, line 326, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError: No Employee found for the given employee field value. ‘attendance_device_id’: HR-EMP-00003

Hello,

Check your fields again. I think the key is not employee_field_value but employee.

Try to check the source code also. You need to pass on employee_fieldname the field you want to match with.

Regards,

Ivan

1 Like

Hey Thanks.
Yes i had missed employee_fieldname.

1 Like

I’m trying the same thing here. But I do not understand what really is employee_field_value.

Please help me if you guys understand this and help me in getting a successful response from this REST API.
Thanks


This is the attendance_device_id field which takes employee_field_value in Employee, this number should be same for the employee in your Attendance Device.

1 Like

Hello, I am a newbie to ERPNext and I want to integrate a fingerprint biometric device to the attendance system. I was reading the documentation, but I cannot open the implementation details anymore (step 4 of integrating erpnext with biometric devices). Could you help me on how I could implement this API?

I am facing same error, I am updating biometric device logs to Frappe erp software using C# service, receiving following error, please update me where can I find mapping which is shown in the table image.(posted by @iRaySpace )

Error:
{“exc_type”:“ValidationError”,“exception”:“frappe.exceptions.ValidationError: No Employee found for the given employee field value. ‘attendance_device_id’: 35”,“exc”:“["Traceback (most recent call last):\n File \"apps/frappe/frappe/app.py\", line 66, in application\n response = frappe.api.handle()\n File \"apps/frappe/frappe/api.py\", line 55, in handle\n return frappe.handler.handle()\n File \"apps/frappe/frappe/handler.py\", line 38, in handle\n data = execute_cmd(cmd)\n File \"apps/frappe/frappe/handler.py\", line 76, in execute_cmd\n return frappe.call(method, **frappe.form_dict)\n File \"apps/frappe/frappe/init.py\", line 1473, in call\n return fn(*args, **newargs)\n File \"apps/erpnext/erpnext/hr/doctype/employee_checkin/employee_checkin.py\", line 91, in add_log_based_on_employee_field\n employee_fieldname, employee_field_value\n File \"apps/frappe/frappe/init.py\", line 511, in throw\n as_list=as_list,\n File \"apps/frappe/frappe/init.py\", line 479, in msgprint\n _raise_exception()\n File \"apps/frappe/frappe/init.py\", line 434, in _raise_exception\n raise raise_exception(msg)\nfrappe.exceptions.ValidationError: No Employee found for the given employee field value. ‘attendance_device_id’: 35\n"]”,“_server_messages”:“["{\"message\": \"No Employee found for the given employee field value. ‘attendance_device_id’: 35\", \"title\": \"Message\", \"indicator\": \"red\", \"raise_exception\": 1}"]”}

Hi,

We get the following error in EPRNext 14. Is the erpnext.hr not exist in v14? if so any idea about the right path to push the data?

Error message:
{“exc_type”:“ValidationError”,“exception”:“frappe.exceptions.ValidationError: Failed to get method for command erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field with No module named ‘erpnext.hr’”,“exc”:“["Traceback (most recent call last):\n File \"apps/frappe/frappe/handler.py\", line 74, in execute_cmd\n method = get_attr(cmd)\n File \"apps/frappe/frappe/handler.py\", line 260, in get_attr\n method = frappe.get_attr(cmd)\n File \"apps/frappe/frappe/init.py\", line 1612, in get_attr\n return getattr(get_module(modulename), methodname)\n File \"apps/frappe/frappe/init.py\", line 1342, in get_module\n return importlib.import_module(modulename)\n File \"/usr/lib/python3.10/importlib/init.py\", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n File \"\", line 1050, in _gcd_import\n File \"\", line 1027, in _find_and_load\n File \"\", line 992, in _find_and_load_unlocked\n File \"\", line 241, in _call_with_frames_removed\n File \"\", line 1050, in _gcd_import\n File \"\", line 1027, in _find_and_load\n File \"\", line 992, in _find_and_load_unlocked\n File \"\", line 241, in _call_with_frames_removed\n File \"\", line 1050, in _gcd_import\n File \"\", line 1027, in _find_and_load\n File \"\", line 992, in _find_and_load_unlocked\n File \"\", line 241, in _call_with_frames_removed\n File \"\", line 1050, in _gcd_import\n File \"\", line 1027, in _find_and_load\n File \"\", line 1004, in find_and_load_unlocked\nModuleNotFoundError: No module named ‘erpnext.hr’\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"apps/frappe/frappe/app.py\", line 95, in application\n response = frappe.api.handle()\n File \"apps/frappe/frappe/api.py\", line 54, in handle\n return frappe.handler.handle()\n File \"apps/frappe/frappe/handler.py\", line 47, in handle\n data = execute_cmd(cmd)\n File \"apps/frappe/frappe/handler.py\", line 76, in execute_cmd\n frappe.throw((\"Failed to get method for command {0} with {1}\").format(cmd, e))\n File \"apps/frappe/frappe/init.py\", line 534, in throw\n msgprint(\n File \"apps/frappe/frappe/init.py\", line 502, in msgprint\n _raise_exception()\n File \"apps/frappe/frappe/init.py\", line 451, in _raise_exception\n raise raise_exception(msg)\nfrappe.exceptions.ValidationError: Failed to get method for command erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field with No module named ‘erpnext.hr’\n"]”,“_server_messages”:“["{\"message\": \"Failed to get method for command erpnext.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field with No module named ‘erpnext.hr’\", \"title\": \"Message\", \"indicator\": \"red\", \"raise_exception\": 1}"]”} [HTTP CODE: 417],

Hey I’m having issue with Attendance doctype, Im unable to use the POST method on to it I’m trying to add this using API call, the Employee checkin you are working on is also linked to this doctype,
is there anything wrong in trying to add the details into the attendance doctype given below,
Am i missing out something, I’m getting 417 error

data = {
        "naming_series": "HR-ATT-.YYYY.-",
        "employee": "HR-EMP-00005",
        "attendance_date": "2023-10-13",
        "status": "Present",
        "company": "Prerana",
        "working_hours": 0,
        "shift": 3,
        "late_entry": 0,
        "early_exit": 0,
    }

Thank you in advance

SOLVED

Here is a solution, the url you are using is probably wrong. Use this one instead url:http://{yourdomain}/api/resource/Attendance

use a POST method with the following fields depicted in the screenshot.

image

Test it with Postman.