【问题标题】:Integration with ZOHO invoice与 ZOHO 发票集成
【发布时间】:2014-01-31 06:04:33
【问题描述】:

我正在探索 Zoho-invoice api 并尝试与我的应用程序集成。但我被卡住了,无法找出原因。

请帮忙:

这就是我调用 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 support@zohoinvoice.com for assistance."

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 使用 $info = curl_getinfo($ch);然后 echo '
    ';print_r($info);echo '
    ';并查看状态和错误!!!

标签: php curl invoice zoho


【解决方案1】:

我没有看到您在代码中发布 json 数据。将这些与您的代码一起添加:

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

【讨论】:

    【解决方案2】:

    我创建了一个示例 PHP 类,它使用 Zoho Invoice API v3 在 Zoho Invoice 中创建发票。 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;
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-28
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      相关资源
      最近更新 更多