誰能幫助我使用官方(非 calcanai)PHP SDK 將 pdf 添加到 Xero 發票。我與 oAuth2 相關聯并且之前創建了草稿發票。然后我將發票更新為 Authorized 并嘗試向發票添加附件。在這一點上我沒有任何運氣,附件已發送但返回時為空。這些文檔一點用處都沒有,也沒有給出任何添加附件甚至最小字段的示例。所以這就是我所擁有的:... $attachments = $apiResponse->getInvoices()[0]->getAttachments(); $attachment = new XeroAPI\XeroPHP\Models\Accounting\Attachment; $attachment->setFileName( $filename ) ->setIncludeOnline( true ) ->setMimeType( 'application/pdf' ); $attachments[] = $attachment; $apiResponse->getInvoices()[0]->setAttachments( $attachments ); $apiResult = $accountingApi->updateOrCreateInvoices( $xeroTenantId, $apiAuth ); if ( !$apiResult->getInvoices()[0]->getHasAttachments() ) { $errors[] = 'Pdf file was not added to Xero.'; } $errorList = array(); $errList = $apiResult->getInvoices()[0]->getValidationErrors()[0]; if ( !is_null( $errList ) ) { $errorList = $errList; } foreach ( $errorList as $err ) { $errors[] = $err->getMessage(); } if ( count( $errors ) == 0 ) { $result['message'] = 'New Invoice Authorised: ' . $xeroInvoice->getReference(); $result['apiResult'] = $apiResult; $result['success'] = true; } else { $result['message'] = print_r( $errors ); $result['success'] = false; }...有任何想法嗎?
1 回答

慕姐8265434
TA貢獻1813條經驗 獲得超2個贊
添加附件需要兩次 API 調用。
// 創建或獲取您的發票 ID,然后創建附件
$invoices = $apiInstance->getInvoices($xeroTenantId);
$guid = $invoices->getInvoices()[0]->getInvoiceId();
// file in the same dir.
$filename = "./helo-heros.jpg";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$result = $apiInstance->createInvoiceAttachmentByFileName($xeroTenantId,$guid,"helo-heros.jpg",$contents);
- 1 回答
- 0 關注
- 155 瀏覽
添加回答
舉報
0/150
提交
取消