How insert row by REST API by ajax?


I am trying to insert new record to custom doctype by REST API, I call this by ajax function in custom button.

This is my code :

   frappe.ui.form.on("mohd", "call",
    function(frm) {
     // to do javascript hear:
     headerParams = {'X-Frappe-CSRF-Token':frappe.csrf_token};
        type: 'post',
        crossDomain: true,
        url: '/api/resource/mohd',

    data:{'price': "'111'"},
    success: function(data){
    error:function(jqXHR, textStatus, errorThrown){

and i get this error:

{β€œexc”:β€œ["Traceback (most recent call last):\n
File \"/home/mohd/frappe-bench/apps/frappe/frappe/\", line 60, in application\n
response = frappe.api.handle()\n
File \"/home/mohd/frappe-bench/apps/frappe/frappe/\", line 111, in handle\n
data = json.loads(\n File \"/usr/lib/python2.7/json/\", line 338, in loads\n
return _default_decoder.decode(s)\n
File \"/usr/lib/python2.7/json/\", line 366, in decode\n
obj, end = self.raw_decode(s, idx=_w(s, 0).end())\nTypeError: expected string or buffer\n"]”}

Any help?

you need to send your_data in data key

data: { data: {price: 111} }
1 Like

Thanks a lot.