Issue with frappe api request

Hello,
I am using api to make a Journal entry in erpnext. but it is not working as I want. I have written following ajax call. I am able to login success fully but somehow not able to create the Journal entry.

$.ajax({
		method: "POST",
		url: "http://frappe.local:8000/api/resource/Journal Entry",
		data: {
		 "data": {"company":"XYZ Company","posting_date":"2017-01-02","fiscal_year":"2016-2017","accounts":[{"account":"Account A", "debit":"500","cost_center":"XYZ"},{"account":Account B", "credit":"500","cost_center":"XYZ"}],"remark":"Some Remarks"}
		} 
	}).success(function(data, status, xhr) {
		alert("success");
		alert(data);
	}).error(function(data, status, xhr) {
		alert("error");
	});

When I use postman tool I am successfully able to create this entry.
can any one help with this?

seems issue with JSON.

{
	"data": {
		"company": "XYZ Company",
		"posting_date": "2017-01-02",
		"fiscal_year": "2016-2017",
		"accounts": [{
			"account": "Account A",
			"debit": "500",
			"cost_center": "XYZ"
		}, {
			"account": "Account B",
			"credit ": "500 ",
			"cost_center ": "XYZ "
		}],
		"remark ": "Some Remarks "
	}
}

Ref JSON validator : http://jsonlint.com/

@saurabh6790

Thanks for reply, I have checked and following is my json but still its not working

data:{
“data”: {
“company”: “XYZ Company”,
“posting_date”: “2017-01-02”,
“fiscal_year”: “2016-2017”,
“accounts”: [{
“account”: “Account A”,
“debit”: “500”,
“cost_center”: “XYZ”
}, {
“account”: “Account B”,
"credit ": "500 ",
"cost_center ": "XYZ "
}],
"remark ": "Some Remarks "
}
}

Please share exception or error message

It shows internal server error.

I have resolved this issue like this…

$.ajax({
method: “POST”,
url: “http://frappe.local:8000/api/resource/Journal Entry”,
data: {
data:JSON.stringify({
“company”: “XYZ Company”,
“posting_date”: “2017-01-02”,
“fiscal_year”: “2016-2017”,
“accounts”: [{
“account”: “Account A”,
“debit”: “500”,
“cost_center”: “XYZ”
}, {
“account”: “Account B”,
"credit ": "500 ",
"cost_center ": "XYZ "
}],
"remark ": "Some Remarks "
})
}
}).success(function(data, status, xhr) {
alert(“success”);
alert(data);
}).error(function(data, status, xhr) {
alert(“error”);
});

1 Like