Wonder if anyone can explain what rstrictions Xero has for adding a pdf file I creted using mPDF. I have managed to use a png file and uploaded it to an invoice but cannot get past this block.
public function attachPDF( $invoice ) {
try {
$company = Company::find( $invoice->company_id );
list( $xeroTenantId, $accountingApi, $identityApi ) = VivattiXero::getApiConnection( $company, false );
$filename = 'AUTH#' . sprintf( '%08d', $invoice->id ) . '.pdf';
//$filename = 'favicon.png';
$guid = $invoice->invoice_id;
$contents = $invoice->getPDF( \Mpdf\Output\Destination::FILE, true, $filename );
$handle = fopen( $filename, "r" );
$contents = fread( $handle, filesize( $filename ) );
fclose( $handle );
//unlink( $filename );
$result['apiResponse'] = $accountingApi->createInvoiceAttachmentByFileName( $xeroTenantId, $guid, $filename, $contents, true );
$result['message'] = 'PDF was attached to invoice #' . sprintf( '%08d', $invoice->id );
$result['success'] = true;
}catch (\XeroAPI\XeroPHP\ApiException $e) {
$error = AccountingObjectSerializer::deserialize(
$e->getResponseBody(),
'\XeroAPI\XeroPHP\Models\Accounting\Error',
[]
);
$result['message'] = "ApiException - " . $error->getElements()[0]["validation_errors"][0]["message"];
$result['success'] = false;
}
return $result;
}
}
Has anyone successfully uploaded a pdf to xero? anyone with a mpdf pdf?
thanks