Creating a bill returns code 1000 "Internal Error" with API v3
This is a testing array I'm sending to the API
- $data = array(
- "vendor_id" => ZOHO_VENDOR_ID ,
- "bill_number" => "1234" ,
- "date" => "2019-04-01" ,
- "line_items" => array( array(
- "quantity" => "1" ,
- "name" => "Testing Bill Name" ,
- "rate" => "1000" ,
- "account_id" => ZOHO_ACCOUNT_ID ,
- "tax_name" => "Zero VAT Rate [0%]" ,
- "tax_percentage" => 0
- ) ) ,
- "notes" => "notes123"
- );
- $curlData = "JSONString=" . urlencode( json_encode( $data ) ) . "";
- /* JSON GENERATED
- 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
- */
- $ch = curl_init();
- curl_setopt( $ch , CURLOPT_URL ,"https://books.zoho.eu/api/v3/bills?organization_id=" . ZOHO_ORGANIZATION_ID );
- curl_setopt( $ch , CURLOPT_POST , true );
- curl_setopt( $ch , CURLOPT_HTTPHEADER , array(
- 'Authorization: Zoho-authtoken ' . $access_token,
- 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'
- ));
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $curlData );
- curl_setopt( $ch , CURLOPT_RETURNTRANSFER , true );
- $server_output = curl_exec( $ch );
- $info = curl_getinfo( $ch );
- curl_close ( $ch );
- var_dump( $server_output );
But the response from the API is
'{"code":1000,"message":"Internal Error"}' (length=40)
I tried different edits with the $curlData variable:
1. urlencode + json_encode ( without JSON_PRETTY_PRINT )
- $curlData = array( "JSONString" => urlencode( json_encode( $data ) ) );
- // JSON GENERATED
- %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
- // returns
'{"code":4,"message":"Invalid value passed for JSONString"}' (length=58)
2. urlencode + json_encode ( with JSON_PRETTY_PRINT )
- $curlData = array( "JSONString" => urlencode( json_encode( $data , JSON_PRETTY_PRINT ) ) );
- // JSON GENERATED
- %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
- // returns
- '{"code":4,"message":"Invalid value passed for JSONString"}' (length=58)
3. json_encode ( without JSON_PRETTY_PRINT )
- $curlData = array( "JSONString" => json_encode( $data ) );
- // JSON GENERATED
- {"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"}
- // returns
'{"code":4,"message":"Invalid value passed for JSONString"}'
4. json_encode ( with JSON_PRETTY_PRINT )
- $curlData = array( "JSONString" => json_encode( $data , JSON_PRETTY_PRINT ) );
- // JSON GENERATED
{
"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"
}
// returns
'{"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.