通过 Zoho Books API 通过电子邮件发送发票
Send invoice by email through Zoho Books API
我的代码如下...
电子邮件功能
public function zoho_email($array){
$data = json_decode($array,true);
$url = '/invoices/'.$data['invoice']['invoice_id'].'/email';
$recivers[] = array($data['invoice']['contact_persons_details'][0]['email']);
$data = array(
'to_mail_ids' => $recivers,
'subject' => 'Invoice from MSL (Invoice#: '.$data['invoice']['invoice_number'].')',
'body' => 'Dear Customer,<br><br><br><br>Thanks for your business,
'send_from_org_email_id' => true
);
$result = $this->zoho_create($url, $data);
}
用于创建发票、联系人和发送电子邮件的 curl 函数
public function zoho_create($url,$array){
$json = json_encode($array);
$data = array('authtoken' => ZOHOAUTHTOKEN,'JSONString' => $json,'organization_id' => ZOHOORGNISATIONID);
$curl = curl_init($this->apiUrl.$url);
if($url=='contacts/'){
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
));
}
else{
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded") );
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
我想通过 API 通过电子邮件向客户发送发票,但我的代码中出现此错误。
{"code":5,"message":"Invalid URL Passed"}
请帮帮我....
提前致谢...
您是否尝试过使用完整 url:“https://books.zoho.com/api/v3/invoices/:invoiceno/email”
您的代码运行正常。尝试打印 url ($url
) 并确认一次是否符合要求的格式 (/invoices/invoice_id/email
)。例如,如果您的 invoice_id 是 1234,那么 $url
应该是 '/invoices/1234/email
'。还要确保 $this->apiUrl
是 https://books.zoho.com/api/v3
如果出现问题,您仍然可以使用下面提到的帮助文档:
我的代码如下...
电子邮件功能
public function zoho_email($array){
$data = json_decode($array,true);
$url = '/invoices/'.$data['invoice']['invoice_id'].'/email';
$recivers[] = array($data['invoice']['contact_persons_details'][0]['email']);
$data = array(
'to_mail_ids' => $recivers,
'subject' => 'Invoice from MSL (Invoice#: '.$data['invoice']['invoice_number'].')',
'body' => 'Dear Customer,<br><br><br><br>Thanks for your business,
'send_from_org_email_id' => true
);
$result = $this->zoho_create($url, $data);
}
用于创建发票、联系人和发送电子邮件的 curl 函数
public function zoho_create($url,$array){
$json = json_encode($array);
$data = array('authtoken' => ZOHOAUTHTOKEN,'JSONString' => $json,'organization_id' => ZOHOORGNISATIONID);
$curl = curl_init($this->apiUrl.$url);
if($url=='contacts/'){
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
));
}
else{
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded") );
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
我想通过 API 通过电子邮件向客户发送发票,但我的代码中出现此错误。
{"code":5,"message":"Invalid URL Passed"}
请帮帮我....
提前致谢...
您是否尝试过使用完整 url:“https://books.zoho.com/api/v3/invoices/:invoiceno/email”
您的代码运行正常。尝试打印 url ($url
) 并确认一次是否符合要求的格式 (/invoices/invoice_id/email
)。例如,如果您的 invoice_id 是 1234,那么 $url
应该是 '/invoices/1234/email
'。还要确保 $this->apiUrl
是 https://books.zoho.com/api/v3
如果出现问题,您仍然可以使用下面提到的帮助文档: