Problem inserting value with FrappeClient PHP

Hi All!
I’m using the PHP Library and until now I had no problem with this.
I have a lot of external services who consume the values from my erpnext.
The point is that now that I’m needing to insert values in the system I’m having problems!
I tried to insert data for one of my doctypes and I recived the follow information.
I would like to have this solution ASAP because I need it to proceed with my system.
Thank you!

object(FrappeClient)#1 (12) {
string(7259) "

Server Error
<link rel="shortcut icon"
<link rel="icon"

	<link type="text/css" rel="stylesheet" href="/assets/frappe/css/bootstrap.css">
	<link type="text/css" rel="stylesheet" href="/assets/css/frappe-web.css">
	<link type="text/css" rel="stylesheet" href="/assets/erpnext/css/website.css">
	<link type="text/css" rel="stylesheet" href="/website_theme.css"><script>
	window.frappe = {};
	frappe.ready_events = [];
	frappe.ready = function(fn) {
	window.dev_server = 0;
<li class="shopping-cart hidden">
	<div class="cart-icon">
		<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="navLogin">
			Cart <span class="badge-wrapper" id="cart-count"></span>
		<div id="cart-overlay" class="dropdown-menu shopping-cart-menu"></div>

<!-- post login tools -->
  • Login
  • 		</div>
            <div class="hero-and-content">
                <div data-html-block="hero"></div>
                <div class="container">
    	<div class="page-content without-sidebar">
    		<div class="page-content-wrapper">
    			<div class="row page-head">
    				<div class='col-sm-12'>
    				<div class="col-sm-8 col-xs-6">
    				<div class="col-sm-4 col-xs-6">
    			<div class="page_content">
    .hero-and-content { background-color: #f5f7fa; } .page-card { max-width: 640px; }
    Server Error

    Traceback (most recent call last):
      File "/home/frappe/benches/bench-2017-11-08/apps/frappe/frappe/", line 62, in application
        response = frappe.api.handle()
      File "/home/frappe/benches/bench-2017-11-08/apps/frappe/frappe/", line 114, in handle
        data = json.loads(
      File "/usr/lib64/python2.7/json/", line 338, in loads
        return _default_decoder.decode(s)
      File "/usr/lib64/python2.7/json/", line 365, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib64/python2.7/json/", line 383, in raw_decode
        raise ValueError("No JSON object could be decoded")
    ValueError: No JSON object could be decoded

    <div><a href='/' class='btn btn-primary btn-sm'>

    Status: 500

    	<div><footer class="web-footer">
    <section class="footer-links">
    	<div class="container">
    		<div class="row">
    			<div class="col-sm-6 text-left">
    			<div class="col-sm-6 text-right">
    Get Updates
    		<div class="row footer-bottom-line">
    			<div class="text-muted small col-sm-6 col-xs-12">
    			<div class="text-muted small col-sm-6 col-xs-12
    				text-right footer-powered">
    					<a href="" target="_blank" class="text-muted">
    	Powered by ERPNext</a>
    <!-- js should be loaded in body! -->
    <script type="text/javascript"
    <script type="text/javascript"
    <script type="text/javascript" src="/website_script.js"></script>
    <script type="text/javascript" src="/assets/js/erpnext-web.min.js"></script>
    <script>frappe.csrf_token = "None";</script></body>
    " ["header"]=> array(23) { ["url"]=> string(55) " Lead" ["content_type"]=> string(24) "text/html; charset=utf-8" ["http_code"]=> int(500) ["header_size"]=> int(511) ["request_size"]=> int(315) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.862987) ["namelookup_time"]=> float(2.8E-5) ["connect_time"]=> float(0.170764) ["pretransfer_time"]=> float(0.523655) ["size_upload"]=> float(0) ["size_download"]=> float(7259) ["speed_download"]=> float(8411) ["speed_upload"]=> float(0) ["download_content_length"]=> float(7259) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0.862885) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "" ["certinfo"]=> array(0) { } } ["is_auth"]=> bool(true) ["_auth_url":"FrappeClient":private]=> string(51) "" ["_api_url":"FrappeClient":private]=> string(48) "" ["_cookie_file":"FrappeClient":private]=> string(10) "cookie.txt" ["_auth":"FrappeClient":private]=> array(2) { ["usr"]=> string(23) "" ["pwd"]=> string(8) "guizo123" } ["_basic_auth":"FrappeClient":private]=> array(0) { } ["_curl_timeout":"FrappeClient":private]=> int(30) ["_limit_page_length":"FrappeClient":private]=> int(20) }

    MY PHP code is the following

     * FrappeClient-PHP Sample Script
    	header('Content-Type: application/json');
    	header("Access-Control-Allow-Origin: *");
    	$client = new FrappeClient();
    	$result = $client->insert(
    					"ML Lead"
    						"vendedor" => ""
    }catch(Exception $e){
    set_error_handler(function ($errno, $errstr, $errfile, $errline ) {
    	throw new ErrorException($errstr, 0, $errno, $errfile, $errline);

    I think you need to authenticate before inserting records

    @netchampfaris ok, could you give me a sample of how I do it?

    You should refer the documentation provided by the library you are using. I couldn’t find the github link.

    @ManasSolanki do you know what should I do here?

    To troubleshoot break down the problem - this fails

    First this basic case works for you?

    Somewhere here you need to login before you insert…

    $client = new FrappeClient();
    $result = $client->insert(
    				"ML Lead"
    					"vendedor" => ""

    Search around for clues like this:

    1 Like

    @clarkej Hi!
    I don’t know if you took a look at it, but in this part of the code, It’s saying that I’m logged in.
    I tried what you told me to do but nothing changed.
    Could someone give me a little more attemption?

    string(51) “Frappe Cloud
    string(48) “Frappe Cloud
    string(10) “cookie.txt”
    array(2) {
    string(23) “
    string(8) “guizo123”
    array(0) {

    I’m able to get and update data with the PHP library, my only problem is being to insert.
    If I’m beeing able to update, it should be a problem to insert as well.
    Waiting for this answer!
    @ManasSolanki @clarkej @netchampfaris

    “If I’m beeing able to update, it should be a problem to insert as well.”

    You need to clarify this - update what? read or write what where?

    @clarkej sorry if I made myself rude, english is my second language and sometimes it sounded rude for you, but it really wasn’t how I want to express myself . :sweat_smile:
    and I saw now that I put the last sentence in upper, it was a mistake, sorry again.
    Where can I change my access and permissions ?
    About the logs, you want to mean about this doctype : Error Log?
    Thanks again and sorry about my language.


    read access to ERPNext does not mean you have write access too.

    Test and troubleshoot what is happening with write access and permissions.

    Your logs will give you clues here.

    FYI this not how to request help “Waiting for this answer!”

    @clarkej Oh, and about this "If I’m beeing able to update, it should be a problem to insert as well."what I wanted to say was : “If I’m beeing able to update, it shouldn’t be a problem to insert as well.”

    Understood - so up to now PUT works to update ERPNext. Your question now is how to get POST to work, to create and insert a new doctype instance.

    Dig into your logs /var/log/auth.log /var/log/nginx/error.log /var/log/mysql frappe-bench/logs, to follow the trail to identify what is and is not working that prevents that transaction from completing

    edit: Get the most basic POST case to work first… Introduction

    Also, try to insert records using Postman. If that works, you must be missing something in your PHP code.

    1 Like