I am using Xero Invoice API POST request with PHP, specifically the updateOrCreateInvoices function in the Xero API to sync transactions. However, I’ve noticed that everytime I run this function, some contact details are being updated or overwritten, particularly the “additional persons” field. This field gets cleared out after the sync process.
I would appreciate any insights or clarifications on the behaviour of the updateOrCreateInvoices function. Is there a specific way to structure the request to maintain the integrity of the contact information? Any help or suggestions would be greatly appreciated.
Function Used: updateOrCreateInvoices
Problem: Contact details, specifically the “additional persons” field, are being overwritten or cleared.
Here is a snippet of code that I am using to sync invoices.
public function create_or_update_invoice($xero_tenant_id, $api_instance, $invoice_list = array()){
$arr_invoices = array();
foreach ($invoice_list as $invoice) {
//Retrieve Existing Contact Details (using the getContacts function):
$contact = $this->get_contact_by_id($xero_tenant_id, $api_instance, $xero_contact_id, $contact_name);
//Prepare Invoice Data with Existing Contact & Invoice Details:
$new_invoice = new XeroAPIXeroPHPModelsAccountingInvoice;
$new_invoice->setType(XeroAPIXeroPHPModelsAccountingInvoice::TYPE_ACCREC)
->setContact($contact)
...
...
->setStatus(XeroAPIXeroPHPModelsAccountingInvoice::STATUS_AUTHORISED);
$arr_invoices[] = $new_invoice;
}
$invoices = new XeroAPIXeroPHPModelsAccountingInvoices;
$invoices->setInvoices($arr_invoices);
try{
//Update or Create Invoice:
$result = $api_instance->updateOrCreateInvoices($xero_tenant_id, $invoices);
return $result;
}catch(Exception $e){
return $e;
}
}
After the above steps, the “additional persons” field in the contact details is cleared out or overwritten.
Sebastian Cheong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.