2014-01-31 52 views
0

我正在探索Zoho-invoice API並嘗試與我的應用程序集成。但我卡住了,無法找出是什麼原因。與ZOHO發票集成

請幫助:

我這是怎麼調用API:

$fields = array(
        'contact_name' => urlencode([name]), 
        'billing_address' => array('address' => urlencode([address]), 'city' => urlencode([city]), 'state' => urlencode([state]), 'zip' => urlencode([pincode]), 'country' => urlencode([country])), 
        'contact_person_id' => urlencode([id]), 
        'email' => urlencode([email]) 
      ); 
$jsonData = json_encode($fields); 

//Initialize connection 
$ch = curl_init("https://invoice.zoho.com/api/v3/contacts?authtoken=[authtoken]&organization_id=[id]&JSONString={$jsonData}"); 
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response) 
curl_setopt($ch, CURLOPT_POST, TRUE);//Regular post 

//Execute cUrl session 
$response = curl_exec($ch); 
curl_close($ch); 

我發送正確的身份驗證令牌和組織關鍵。

但我得到這個錯誤響應:

"code":1048,"message":"Sorry, there was an internal error. Please contact [email protected] for assistance." 

任何幫助將不勝感激。謝謝

+1

使用$信息= curl_getinfo($ CH);然後回顯'

';print_r($info);echo '
';並查看狀態和錯誤! – user2727841

回答

2

我沒有看到你在你的代碼中發佈你的json數據。與你的代碼添加這些:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonData); 
1

我已經創建了使用Zoho的發票API V3在百會創造發票的發票樣本PHP類。 You can find it on GitHub

/** 
* Sends the actual request to the REST webservice 
*/ 
protected function sendRequest($url, $data, $type = 'POST') { 
$jsonData = json_encode($this->urlencode_array($data)); 

if ($type == 'POST') { 
    $ch = curl_init("https://invoice.zoho.com/api/v3/{$url}?authtoken={$this->data['authtoken']}&organization_id={$this->data['organization_id']}&JSONString={$jsonData}"); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response) 
    curl_setopt($ch, CURLOPT_POST, TRUE);//Regular post 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); 
} else { 
    $ch = curl_init("https://invoice.zoho.com/api/v3/{$url}?authtoken={$this->data['authtoken']}&organization_id={$this->data['organization_id']}&JSONString={$jsonData}"); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response) 
    curl_setopt($ch, CURLOPT_POST, FALSE);//Regular post 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
} 


$result = curl_exec($ch); 
$result = json_decode($result); 

// RM: IS not object, is not code 0? 
if (is_object($result) === false || $result->code != 0) { 
    throw new AppException('Error creating estimate/invoice - '.print_r($result, true)); 
} 

return $result; 

}