I am working on integrating a custom PHP system with XERO and I can create invoices, etc. Now we need to attach some files to the invoice.
The PHP API examples do not have a function for this, only a function to attach a file to an account, so I used that as a basis and looked at the online documentation for the createInvoiceAttachmentByFileName() function, which is similar to the createAccountAttachmentByFileName(), except that it has an extra parameter ($include_online).
The function succeeds and returns the correct result, but it seems to ignore the $include_online parameter. It does not matter what I set it to, it is never included.
Below is my code for the function.
Has anybody done this before and can maybe tell me what I am doing wrong?
I am using v 1.4.0 of the XERO PHP API
Thanks
Andre
public function addInvoiceAttachment($invoice_xero_id, $file_path)
{
$res = "OK";
// Get the file name
$sep_pos = strrpos($file_path, '/');
$filename = substr($file_path, $sep_pos+1);
$handle = fopen($file_path, "r");
$contents = fread($handle, filesize($file_path));
fclose($handle);
$include_online = True;
try
{
$result = $this->apiInstance->createInvoiceAttachmentByFileName($this->xeroTenantId, $invoice_xero_id, $filename, $include_online, $contents);
trigger_error("addInvoiceAttachment: result = ".print_r($result, true));
}
catch (Exception $e)
{
trigger_error('Exception when calling AccountingApi->createInvoiceAttachmentByFileName: '.$e->getMessage());
$res = $e->getMessage();
}
return $res;
} // addInvoiceAttachment
// --------------------------------------------------------------------------