HTTP/400 error while useing REST API

I have a js file take attribute from a form and send it to doctype api post to create a new doctype
here is the api ,
http://localhost:8000/api/resource/pcontatcus
i used postman to test it and it’s working with no problem .

the js file

$(function(){
$(“#add47”).click(function(e){
e.preventDefault();
var name = $(“#pname”).val();
var age = $(“#age”).val();
var note = $(“#note”).val();

    var post = {"data":JSON.stringify({"pname":name,"age":age,"note":note})};

    $.post("http://localhost:8000/api/resource/pcontatcus",post,function(data){
        alert("G00D");
    });

});

});

when i click on add i get this error

POST /api/resource/pcontatcus HTTP/1.1" 400 -

could you help me solve this problem ?

@mostafa

@ahmadRagheb What is your browser and please tell me the results when you change your browser!

1 Like

in Google Chrome i had this error
00:48:56 web.1 | 127.0.0.1 - - [17/Dec/2016 00:48:56] “POST /api/resource/pcontatcus HTTP/1.1” 400 -

and when i tried Firefox i got this one :slight_smile:

00:52:12 web.1 | Traceback (most recent call last):
00:52:12 web.1 | File “/home/ahmad/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
00:52:12 web.1 | response = frappe.api.handle()
00:52:12 web.1 | File “/home/ahmad/frappe-bench/apps/frappe/frappe/api.py”, line 120, in handle
00:52:12 web.1 | “data”: frappe.get_doc(data).insert().as_dict()
00:52:12 web.1 | File “/home/ahmad/frappe-bench/apps/frappe/frappe/model/document.py”, line 178, in insert
00:52:12 web.1 | self.check_permission(“create”)
00:52:12 web.1 | File “/home/ahmad/frappe-bench/apps/frappe/frappe/model/document.py”, line 145, in check_permission
00:52:12 web.1 | self.raise_no_permission_to(permlabel or permtype)
00:52:12 web.1 | File “/home/ahmad/frappe-bench/apps/frappe/frappe/model/document.py”, line 160, in raise_no_permission_to
00:52:12 web.1 | raise frappe.PermissionError(msg)
00:52:12 web.1 | PermissionError: No permission to create pcontatcus
00:52:12 web.1 |
00:52:12 web.1 | 127.0.0.1 - - [17/Dec/2016 00:52:12] “POST /api/resource/pcontatcus HTTP/1.1” 403 -

I change my doctype Premission FROM ALL TO Guest … And it’s working … Thank you @mostafa for your help

1 Like