Creating a bill returns code 1000 "Internal Error" with API v3

Creating a bill returns code 1000 "Internal Error" with API v3

Hi all, I'm creating a script who creates a new bill in the admin panel via API v3 and PHP 7 (  https://www.zoho.eu/books/api/v3/#Bills_Create_a_bill )

This is a testing array I'm sending to the API


  1. $data = array(
  2.     "vendor_id"     => ZOHO_VENDOR_ID ,
  3.     "bill_number"   => "1234" ,
  4.     "date"          => "2019-04-01" ,
  5.     "line_items"    => array( array(
  6.         "quantity"          => "1" ,
  7.         "name"              => "Testing Bill Name" ,
  8.         "rate"              => "1000" ,
  9.         "account_id"        => ZOHO_ACCOUNT_ID ,
  10.         "tax_name"          => "Zero VAT Rate [0%]" ,
  11.         "tax_percentage"    => 0
  12.     ) ) ,
  13.     "notes" => "notes123"
  14. );
  15. $curlData = "JSONString=" . urlencode( json_encode( $data ) ) . "";
  16. /* JSON GENERATED
  17. JSONString=%7B%22vendor_id%22%3A%22<ZOHO_VENDOR_ID>%22%2C%22bill_number%22%3A%221234%22%2C%22date%22%3A%222019-04-01%22%2C%22line_items%22%3A%5B%7B%22quantity%22%3A%221%22%2C%22name%22%3A%22Testing+Bill+Name%22%2C%22rate%22%3A%221000%22%2C%22account_id%22%3A%22<ZOHO_ACCOUNT_ID>%22%2C%22tax_name%22%3A%22Zero+VAT+Rate+%5B0%25%5D%22%2C%22tax_percentage%22%3A0%7D%5D%2C%22notes%22%3A%22notes123%22%7D
  18. */
  19. $ch = curl_init();
  20. curl_setopt( $ch , CURLOPT_URL ,"https://books.zoho.eu/api/v3/bills?organization_id=" . ZOHO_ORGANIZATION_ID );
  21. curl_setopt( $ch , CURLOPT_POST , true );
  22. curl_setopt( $ch , CURLOPT_HTTPHEADER , array(
  23.     'Authorization: Zoho-authtoken ' . $access_token,
  24.     'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'
  25. ));
  26. curl_setopt( $ch , CURLOPT_POSTFIELDS , $curlData );
  27. curl_setopt( $ch , CURLOPT_RETURNTRANSFER , true );
  28. $server_output = curl_exec( $ch );
  29. $info = curl_getinfo( $ch );
  30. curl_close ( $ch );
  31. var_dump( $server_output );
But the response from the API is
  1. '{"code":1000,"message":"Internal Error"}' (length=40)
I tried different edits with the $curlData variable:

1. urlencode + json_encode ( without JSON_PRETTY_PRINT )
  1. $curlData = array( "JSONString" => urlencode( json_encode( $data ) ) );
  2. // JSON GENERATED
  3. %7B%22vendor_id%22%3A%22<ZOHO_VENDOR_ID>%22%2C%22bill_number%22%3A%221234%22%2C%22date%22%3A%222019-04-01%22%2C%22line_items%22%3A%5B%7B%22quantity%22%3A%221%22%2C%22name%22%3A%22Testing+Bill+Name%22%2C%22rate%22%3A%221000%22%2C%22account_id%22%3A%22<ZOHO_ACCOUNT_ID>%22%2C%22tax_name%22%3A%22Zero+VAT+Rate+%5B0%25%5D%22%2C%22tax_percentage%22%3A0%7D%5D%2C%22notes%22%3A%22notes123%22%7D
  4. // returns
  5. '{"code":4,"message":"Invalid value passed for JSONString"}' (length=58)

2. urlencode + json_encode ( with JSON_PRETTY_PRINT )

  1. $curlData = array( "JSONString" => urlencode( json_encode( $data , JSON_PRETTY_PRINT ) ) );
  2. // JSON GENERATED
  3. %7B%0A++++%22vendor_id%22%3A+%22<ZOHO_VENDOR_ID>%22%2C%0A++++%22bill_number%22%3A+%221234%22%2C%0A++++%22date%22%3A+%222019-04-01%22%2C%0A++++%22line_items%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22quantity%22%3A+%221%22%2C%0A++++++++++++%22name%22%3A+%22Testing+Bill+Name%22%2C%0A++++++++++++%22rate%22%3A+%221000%22%2C%0A++++++++++++%22account_id%22%3A+%22<ZOHO_ACCOUNT_ID>%22%2C%0A++++++++++++%22tax_name%22%3A+%22Zero+VAT+Rate+%5B0%25%5D%22%2C%0A++++++++++++%22tax_percentage%22%3A+0%0A++++++++%7D%0A++++%5D%2C%0A++++%22notes%22%3A+%22notes123%22%0A%7D
  4. // returns
  5. '{"code":4,"message":"Invalid value passed for JSONString"}' (length=58)
3. json_encode ( without JSON_PRETTY_PRINT )

  1. $curlData = array( "JSONString" => json_encode( $data ) );
  2. // JSON GENERATED
  3. {"vendor_id":"<ZOHO_VENDOR_ID>","bill_number":"1234","date":"2019-04-01","line_items":[{"quantity":"1","name":"Testing Bill Name","rate":"1000","account_id":"<ZOHO_ACCOUNT_ID>","tax_name":"Zero VAT Rate [0%]","tax_percentage":0}],"notes":"notes123"}
  4. // returns
  5. '{"code":4,"message":"Invalid value passed for JSONString"}'

    

4. json_encode ( with JSON_PRETTY_PRINT )

  1. $curlData = array( "JSONString" => json_encode( $data , JSON_PRETTY_PRINT ) );
  2. // JSON GENERATED
  3. {
        "vendor_id": "<ZOHO_VENDOR_ID>",
        "bill_number": "1234",
        "date": "2019-04-01",
        "line_items": [
            {
                "quantity": "1",
                "name": "Testing Bill Name",
                "rate": "1000",
                "account_id": "<ZOHO_ACCOUNT_ID>",
                "tax_name": "Zero VAT Rate [0%]",
                "tax_percentage": 0
            }
        ],
        "notes": "notes123"
    }
  4. // returns
  5. '{"code":4,"message":"Invalid value passed for JSONString"}' (length=58)
Is there any error in my request or JSON encoding? Thank you for your replies.